Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TouchableHighlight and TouchableOpacity affect layout on Android

Tags:

react-native

I noticed that replacing TouchableWithoutFeedback with TouchableHighlight or TouchableOpacity can cause differences in layout. Is this expected?

Example:

<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>

With TouchableWithoutFeedback:

TouchableWithoutFeedback

Replacing it with TouchableOpacity:

TouchableHighlight

The styles are:

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',
},
like image 622
Martin Konicek Avatar asked Oct 02 '15 17:10

Martin Konicek


1 Answers

The solution is not to introduce the wrapper view. Simply set the style directly on TouchableHighlight or TouchableOpacity:

<TouchableOpacity onPress={this.onClick} style={styles.row_container}>
  <Text style={styles.row_text}>
    {'I count the number of taps: ' + this.state.clicks}
  </Text>
</TouchableOpacity>
like image 176
Martin Konicek Avatar answered Nov 04 '22 00:11

Martin Konicek