触摸图标时,React-Native onPress 不起作用

React-Native onPress doesn't work, when touch the icon

我正在使用 react-native-element to create a button group, that embedded an Icon from react-native-vector-icons

问题是当图标被触摸时,onPress 没有被触发

    constructor(props) {
      super(props);    
      this.state = { selectedIndex: 0 };   
      this.SetSelected = this.SetSelected.bind(this);
    }


    SetSelected(index) {
      this.setState({ selectedIndex: index });
    }

    return(
    <ButtonGroup
      selectedIndex={this.state.selectedIndex}
      onPress={this.SetSelected}
      selectedButtonStyle={{ backgroundColor: 'blue' }}
      buttons={[
        {
          element: () => (
            <Icon.Button
              name="slack"
              style={{ backgroundColor: 'white' }}
              color={'black'}
              size={30}
              title="Inbox"
            >
              <Text style={{ color: 'black', fontSize: 15, textAlignVertical: 'center', textAlign: 'center' }}                   
              >
                All
              </Text>
            </Icon.Button>
          ),
        })

试着把它变成一个函数。

onPress={() => {this.SetSelected()}}

如果不起作用请提供this.SetSelected函数。

Thanks to Kyle Roach

原因是 因为我使用的是可触摸的 Icon.Button。因此,当我尝试点击以更改 ButtonGroup 时,触摸事件将被 Icon.Button 而不是 buttonGroup 的按钮捕获。

我应该使用 Icon 而不是 Icon.Button