react-native ActivityIndicator 初始值为false再也无法显示
来源:互联网 发布:淘宝网抓绒女式外套 编辑:程序博客网 时间:2024/06/05 02:46
今天碰到一个很奇葩的问题,后来在stackoverflow上面查,据说是react-native的一个bug。
原帖地址:http://stackoverflow.com/questions/38579665/reactnative-activityindicator-not-showing-when-animating-property-initiate-false
比如如下代码:
constructor(props) {
super(props);
this.state = {
animating: true,
};
}
test() {
this.setState(animationg: !this.state.animating);
}
render() {
return(
<View>
<Button onPress = {this.test.bind(this)}>
</Button>
<ActivityIndicator animating = {this.state.animating} />
</View>
);
}
在这种情况下(animating初始值为true),可通过点击button实现加载框的显示和隐藏,达到预期效果。
但如果animating的初始值为false,如下所示:
constructor(props) {
super(props);
this.state = {
animating: false,
};
}
test() {
this.setState(animationg: !this.state.animating);
}
render() {
return(
<View>
<Button onPress = {this.test.bind(this)}>
</Button>
<ActivityIndicator animating = {this.state.animating} />
</View>
);
}
则无论如何点击button,都无法将加载框显示出来。
后来在react-native官方github上看到这个问题的一个神奇的解决方法,原帖地址: https://github.com/facebook/react-native/issues/11682
只需将
<ActivityIndicator animating = {this.state.animating} /> 改为 {this.state.animating && <ActivityIndicator animating={this.state.animating} />}
即可正常运行。
完整代码如下:
constructor(props) {
super(props);
this.state = {
animating: false,
};
}
test() {
this.setState(animationg: !this.state.animating);
}
render() {
return(
<View>
<Button onPress = {this.test.bind(this)}>
</Button>
{this.state.animating && <ActivityIndicator animating={this.state.animating} />}
</View>
);
}
<Button onPress = {this.test.bind(this)}>
</Button>
- react-native ActivityIndicator 初始值为false再也无法显示
- React-Native ActivityIndicator-指示器
- react native ActivityIndicator使用详解
- React Native学习六- ActivityIndicator
- React Native中加载指示器组件ActivityIndicator使用方法
- React Native从零开始(十)ActivityIndicator的使用
- React-Native进阶_2.加载指示动画 ActivityIndicator
- react-native无法显示图片的解决办法
- react-native react-native-swiper 设置horizontal=false无效
- react native 无法reload调试
- react native调试运行的时候,无法运行,显示无法启动
- React Native ToolbarAndroid没显示
- react native图片显示问题
- react native Image全屏显示
- React-Native之无法找到 react-native-windows 问题解决方案
- React Native: 真机测试(MIUI)无法显示菜单(Reload。。。)
- React-Native 安卓出现图片资源路径正确,却无法加载显示
- thinkphp3.2将APP_DEBUG设置为false后导致验证码无法显示的解决方法
- mininet+opendaylight/floodlight+wireshark搭建SDN测试环境
- MySQL主从复制配置
- [HDU 3944] DP?组合数 Lucas定理
- java中字符串的比较
- PAT-A 1006. Sign In and Sign Out (25)
- react-native ActivityIndicator 初始值为false再也无法显示
- HTTP基础
- Linux下用cmake编译大型C/C++项目
- 卡尔曼滤波_2(图解)
- codves m进制转十进制 1475
- Protobuf笔记以及Java Javascript使用实例
- mac80211解析一
- android studio配置
- POJ3669-Meteor Shower-BFS