简体   繁体   English

离线时touchableopacity不起作用

[英]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.

相关问题 TouchableOpacity onPress 不适用于 Android - TouchableOpacity onPress not working on Android TouchableOpacity onLongPress 不适用于 android - TouchableOpacity onLongPress not working on android React 本机导航不适用于 TouchableOpacity - React native navigation is not working on TouchableOpacity TouchableOpacity 的问题不适用于 position:“绝对” - Problems with TouchableOpacity not working with position:“absolute” TouchableOpacity 不适用于 expo 以进行本机反应 - TouchableOpacity not working on expo for react native 反应本机 TouchableOpacity onPress 在 Android 上不起作用 - React native TouchableOpacity onPress not working on Android TouchableOpacity 在绝对定位的视图中不起作用 - TouchableOpacity not working inside an absolute positioned View 选中后,Rotated TouchableOpacity在Android上崩溃 - Rotated TouchableOpacity crashes on Android when selected 在WebView中强制关闭-脱机时不起作用 - Force close in WebView- not working when it's in offline 设备离线时 Firebase 推送通知无法正常工作 - Firebase push notification is not working properly when device is offline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM