android - 样式不会在 React Native 上重新渲染

标签 android css react-native

我在使用 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/>
        };
    }

通过这段代码,我得到了以下内容:

The Style doesn't re-redender

setState 会因为文本更改而更改值。但不是应用的样式。

你知道为什么吗?

最佳答案

我相信这可能与FB bug有关https://github.com/facebook/react-native/issues/6278 - 尝试将比例设置为 0.10.01 并尝试何时它仍然适用于您以及何时会损坏。

关于android - 样式不会在 React Native 上重新渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45534147/

相关文章:

Android 多行数字编辑文本

javascript - var ball = document.getElementById ("ball");返回空对象?

javascript - 检查一个字符串是否包含另一个字符串 React Native

android - 如何将对 "video/photo"附加的支持从 whatsapp 等应用程序添加到我的应用程序?

android - 如何在python脚本中导入android

jquery - 具有不透明度的垂直文本渐变

html - css 中的背景颜色未显示

javascript - 在 React Native 中迭代 JSON

react-native - react native 错误无法识别的运算符最小值

android - android中的动画轮效果