【发布时间】:2020-12-19 09:28:42
【问题描述】:
Animated.View 仅缩放到提供的屏幕宽度的一半。 其次,为什么我必须在样式表中给出宽度才能使它起作用,以及给它长度 1 的具体原因是什么。 如果我将样式表中的宽度增加到 2,进度条会覆盖整个屏幕宽度
import React from 'react'
import { View, Animated, StyleSheet, Dimensions, Easing } from 'react-native'
export default class ProgressBar extends React.Component {
state = {
percent: new Animated.Value(0)
}
componentDidMount() {
this.startAnimation()
}
startAnimation = () => {
this.animation = Animated.timing(this.state.percent, {
toValue: 100,
duration: this.props.timeRemaining*1000,
easing: Easing.linear,
useNativeDriver: true,
})
this.animation.start()
}
render() {
return(
<Animated.View
style={[
styles.bar,
{transform: [{
scaleX: this.state.percent.interpolate({
inputRange: [0, 100],
outputRange: [0, Dimensions.get('window').width]
})
}] }
]}
/>
// <View style={[styles.bar, {width: Dimensions.get('window').width}]}/>
)
}
}
const styles = StyleSheet.create({
bar: {
height: 30,
width: 1,
backgroundColor: 'tomato',
}
})
【问题讨论】:
标签: react-native expo react-native-android react-native-flatlist