[英]touchableopacity is not working when offline
touchableopacity is not working when offline, sometimes it take really slow like take a few minute to run onPress 离线状态下,touchableopacity无法正常工作,有时会花一些时间,例如在onPress上运行几分钟
<TouchableOpacity
onPress={() => this.example()}
style={{padding: 10, justifyContent: 'center', flexDirection: 'row', backgroundColor: '#F26525', width: Dimensions.get('screen').width * 0.8, borderRadius: 3, marginTop: 15}}>
<Icon name='refresh' size={20} color='#ffffff' />
<Text style={{fontSize: 16, color: '#ffffff', fontFamily: 'Quicksand-Medium'}}> Try Again</Text>
</TouchableOpacity>
i using : react-native-cli: 2.0.1 react-native: 0.55.1 我使用:react-native-cli:2.0.1 react-native:0.55.1
i tried to change into touchablewithoutfeedback, but it still the same 我试图将其更改为touchablewithoutfeedback,但还是一样
thanks for your help , 谢谢你的帮助 ,
You will have to bind your function like this. 您将必须这样绑定您的函数。
<TouchableOpacity
onPress={this.example.bind(this)}
style={{padding: 10, justifyContent: 'center', flexDirection: 'row', backgroundColor: '#F26525', width: Dimensions.get('screen').width * 0.8, borderRadius: 3, marginTop: 15}}>
<Icon name='refresh' size={20} color='#ffffff' />
<Text style={{fontSize: 16, color: '#ffffff', fontFamily: 'Quicksand-Medium'}}> Try Again</Text>
or you can also bind your function in your constructor as well 或者您也可以将函数绑定到构造函数中
constructor(props) {
super(props)
this.example = this.example.bind(this)
}
<TouchableOpacity
onPress={this.example}
style={{padding: 10, justifyContent: 'center', flexDirection: 'row', backgroundColor: '#F26525', width: Dimensions.get('screen').width * 0.8, borderRadius: 3, marginTop: 15}}>
<Icon name='refresh' size={20} color='#ffffff' />
<Text style={{fontSize: 16, color: '#ffffff', fontFamily: 'Quicksand-Medium'}}> Try Again</Text>
or like this 或像这样
<TouchableOpacity
onPress={() => {console.log('Pressed!')}}
style={{padding: 10, justifyContent: 'center', flexDirection: 'row', backgroundColor: '#F26525', width: Dimensions.get('screen').width * 0.8, borderRadius: 3, marginTop: 15}}>
<Icon name='refresh' size={20} color='#ffffff' />
<Text style={{fontSize: 16, color: '#ffffff', fontFamily: 'Quicksand-Medium'}}> Try Again</Text>
I think you should use just one component inside the touchableOpacity so do this: 我认为您应该只在touchableOpacity内部使用一个组件,所以请执行以下操作:
<TouchableOpacity
onPress={() => this.example()}
style={{padding: 10, justifyContent: 'center', flexDirection: 'row', backgroundColor: '#F26525', width: Dimensions.get('screen').width * 0.8, borderRadius: 3, marginTop: 15}}>
<View>
<Icon name='refresh' size={20} color='#ffffff' />
<Text style={{fontSize: 16, color: '#ffffff', fontFamily: 'Quicksand-Medium'}}> Try Again</Text>
</View>
</TouchableOpacity>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.