react-native TouchableOpacity 的 hitSlop 取动态宽高
react-native TouchableOpacity's hitSlop to take dynamic width and height
根据下面的代码,点击区域应该适用于父视图的整个宽度和高度,根据屏幕宽度是动态的,但它只发生在文本区域
代码:-
<View style={test1}>
<TouchableOpacity onPress={this.handleClick} hitSlop={{ //dynamic data }}>
<Text>TEXT DATA</Text>
</TouchableOpacity>
</View>
test1 {
alignItems: 'center',
justifyContent: 'center',
height: 50,
width: (Dimensions.get('window').width - 30),
borderRadius: 5,
backgroundColor: buttonLightBlue,
position: 'absolute',
top: (Dimensions.get('window').height / 3),
alignSelf: 'center',
zIndex: 1
}
通过提供自定义 width/height 值解决了问题
根据下面的代码,点击区域应该适用于父视图的整个宽度和高度,根据屏幕宽度是动态的,但它只发生在文本区域
代码:-
<View style={test1}>
<TouchableOpacity onPress={this.handleClick} hitSlop={{ //dynamic data }}>
<Text>TEXT DATA</Text>
</TouchableOpacity>
</View>
test1 {
alignItems: 'center',
justifyContent: 'center',
height: 50,
width: (Dimensions.get('window').width - 30),
borderRadius: 5,
backgroundColor: buttonLightBlue,
position: 'absolute',
top: (Dimensions.get('window').height / 3),
alignSelf: 'center',
zIndex: 1
}
通过提供自定义 width/height 值解决了问题