React Native SetState导致按钮点击失效

情景:
调用安卓原生,使用广播方式给RN发消息,向数组中插入数据,渲染RN页面,导致点击按钮事件,需要等到渲染基本结束以后才会调用.

解决方案:
RN:
1.将需要渲染的页面数据单独拉出来,作为组件,组件单独渲染不会使其他组件也一起渲染
2.更新A和B组件内容需要通过ref 实现
Android:将发消息改为异步实现,不能使用同步!!!!!

export default class Home1 extends Component {
    render() {
        console.log('渲染根');
        return (
            <View style={{backgroundColor: 'white', marginTop: 100}}>
                <ComponentA ref={(ref) => this.A = ref}/>
                <ComponentB ref={(ref) => this.B = ref}/>
            </View>
        );
    }
}
class ComponentA extends Component {
  constructor(props) {
    super(props)
    this.state = {
      length:0
    }
  }
    render() {
        console.log('渲染A');
        return (
            <Text>{this.state.lenght}</Text>
        )
    }
}
class ComponentB extends Component {
  constructor(props) {
    super(props)
    this.state = {
      dataList:[],
    }
  }
    render() {
        console.log('渲染B');
        return (
            <FlatList
        style={styles.middleView}
        extraData={this.state}
        data={this.state.dataList}
        renderItem={this._renderItem.bind(this)}
        keyExtractor={(item, index) => item}>
      </FlatList>
        )
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 180,397评论 25 708
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 14,553评论 2 59
  • 0727晨读感悟---选择 我们总说,有的选比没得选要好。因为有的选就是有退路,而没得选呢?逼死你,只有一条下山路...
    自律的黄老爷阅读 290评论 4 6
  • 有一年路过安徽,高速公路两旁,有些房屋依山傍水,灰瓦白墙翘檐,车窗外,它们速度飞快,扑面而来,又悠然而去,于是...
    夏天smile阅读 646评论 2 6
  • 趁着今天买了两件新衣服,把家里的秋冬季衣服都找了出来,给衣柜做换季。 夏天的衣服看着一件件薄薄的,收在一起,也装满...
    山间竹音阅读 234评论 0 0

友情链接更多精彩内容