我在使用 React-Native 时遇到问题
我的状态:Windows 10 - Hyper V、Visual Studio Emulator Android。
我的页面上有一个组件(显示在我单击的位置)。
当我单击时,坐标会在组件中发送。
< ClickAnimation x = {item.x} y = {item.y} />
该组件首先具有以下内容:
state = {
scaleAnim: 2
};
当我第二次单击时,this.state.scaleAnim 更改为 0.001
componentWillReceiveProps(nextProps) {
if (nextProps.x != this.props.x) {
this.setState({scaleAnim: 0.001})
}
}
这就是渲染:
render() {
if (this.state.scaleAnim) {
return <Animated.View
key={this.props.y * this.props.x}
style={{
zIndex: 10,
borderColor: "blue",
borderRadius: 400,
borderWidth: 1,
position: "absolute",
top: this.props.y,
left: this.props.x,
width: 60,
height: 60,
backgroundColor: "red",
transform: [
{
scaleY: this.state.scaleAnim
}, {
scaleX: this.state.scaleAnim
}
]
}}>
<Text>{this.state.scaleAnim}</Text>
</Animated.View>
} else {
return <View/>
};
}
通过这段代码,我得到了以下内容:
setState 会因为文本更改而更改值。但不是应用的样式。
你知道为什么吗?
最佳答案
我相信这可能与FB bug有关https://github.com/facebook/react-native/issues/6278 - 尝试将比例设置为 0.1
或 0.01
并尝试何时它仍然适用于您以及何时会损坏。
关于android - 样式不会在 React Native 上重新渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45534147/