我有两个从 react-native-paper 使用的径向按钮。我在 onPress 函数下同时拥有按钮本身和它们旁边的文本,但是只有当我按下文本时才会执行该函数,而不是当我按下按钮时。当我按下按钮时,它突出显示并显示它已被按下,但不执行 onPress。
<View style={[s.profile_gender_row]}>
<Text onPress={() => {this.onDataChange('gender', 'F')}}>Female</Text> // this works just fine
<RadioButton
value="F"
status={this.props.gender === 'F' ? 'checked' : 'unchecked'}
onPress={() => {this.onDataChange('gender', 'F')}} // this does not work
/>
</View>
<View style={[s.profile_gender_row]}>
<Text onPress={() => {this.onDataChange('gender', 'M')}}>Male</Text>
<RadioButton
value="M"
status={this.props.gender === 'M' ? 'checked' : 'unchecked'}
onPress={() => {this.onDataChange('gender', 'M')}}
/>
</View>
没有任何错误消息,我只是对它为什么不执行感到困惑。