首页 > 解决方案 > 离线时touchableopacity不起作用

问题描述

离线时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>

我使用:react-native-cli:2.0.1 react-native:0.55.1

我试图改变成touchablewithoutfeedback,但它仍然一样

感谢您的帮助 ,

标签: androidreact-nativeexpotouchableopacityreact-native-cli

解决方案


我认为你应该在 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>

推荐阅读