TouchableHighlight和TouchableOpacity会影响Android上的布局

Mar*_*cek 8 react-native

我注意到,替换TouchableWithoutFeedbackTouchableHighlightTouchableOpacity可引起布局的差异.这是预期的吗?

例:

<TouchableWithoutFeedback onPress={this.onClick}>
  <View style={styles.row_container}>
    <Text style={styles.row_text}>
      {'I count the number of taps: ' + this.state.clicks}
    </Text>
  </View>
</TouchableWithoutFeedback>
Run Code Online (Sandbox Code Playgroud)

TouchableWithoutFeedback:

TouchableWithoutFeedback

替换为TouchableOpacity:

TouchableHighlight

风格是:

row_container: {
  backgroundColor: 'rgba(0, 0, 0, 0.1)',
  flex: 1,
  height: 100,
  borderColor: '#333333',
  borderWidth: 1,
  borderRadius: 5,
  padding: 5,
},
row_text: {
  flex: 1,
  fontSize: 18,
  alignSelf: 'center',
},
Run Code Online (Sandbox Code Playgroud)

Mar*_*cek 11

解决方案不是介绍包装器视图.只需直接设置样式TouchableHighlightTouchableOpacity:

<TouchableOpacity onPress={this.onClick} style={styles.row_container}>
  <Text style={styles.row_text}>
    {'I count the number of taps: ' + this.state.clicks}
  </Text>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)