React native 如何以编程方式在React Native中切换开关?

React native 如何以编程方式在React Native中切换开关?,react-native,react-native-ios,React Native,React Native Ios,我把我们几个人放在一个视图中。当我打开一个开关时,我希望所有其他开关都关闭。目前,我通过state设置booleanvalue属性。这会导致突然发生更改,因为开关只是重新渲染而不是转换 那么,如何以编程方式切换它们呢 编辑2:我刚刚发现它在Android上运行平稳,因此看起来像是一个iOS特有的问题 编辑:代码的一部分 _onSwitch = (id, switched) => { let newFilter = { status: null }; if (!swit

我把我们几个人放在一个视图中。当我打开一个开关时,我希望所有其他开关都关闭。目前,我通过state设置boolean
value
属性。这会导致突然发生更改,因为开关只是重新渲染而不是转换

那么,如何以编程方式切换它们呢

编辑2:我刚刚发现它在Android上运行平稳,因此看起来像是一个iOS特有的问题

编辑:代码的一部分

  _onSwitch = (id, switched) => {
    let newFilter = { status: null };

    if (!switched) {
      newFilter = { status: id };
    }
    this.props.changeFilter(newFilter); // calls the action creator
  };

  _renderItem = ({ item }) => {
    const switched = this.props.currentFilter === item.id; // the state mapped to a prop
    return (
      <ListItem
        switchButton
        switched={switched}
        onSwitch={() => this._onSwitch(item.id, switched)}
      />
    );
  };
\u开关=(id,已切换)=>{
让newFilter={status:null};
如果(!已切换){
newFilter={status:id};
}
this.props.changeFilter(newFilter);//调用动作创建者
};
_renderItem=({item})=>{
const switched=this.props.currentFilter==item.id;//映射到某个prop的状态
返回(
此。_onSwitch(item.id,switched)}
/>
);
};

发布你的代码……你能分享你的代码吗?这与我的代码无关。它工作正常。我只是想谈谈过渡,但我会尽量举一个最小的例子。这不是那么容易,因为所有的redux的东西等等。张贴你的代码…你能分享你的代码吗?这不是关于我的代码。它工作正常。我只是想谈谈过渡,但我会尽量举一个最小的例子。这不是那么容易,因为所有的redux的东西等等。