1

問題はかなり単純だと思いますが、わかりません。私は、反応ネイティブルータフラックスライブラリとNativeBaseライブラリをボタン用に使用しています。私はそれを押したときにボタンの背景色を変更すると、それはアクティブですリアクトネイティブ:バックグラウンドの第2のアクションを変更するには

<Button transparent onPress={Actions.MainOne } style={{ width: 50, height: 50 }} > 
     <Text>Option1</Text> 
    </Button> 

    <Button transparent onPress={Actions.MainTwo} style={{ width: 50, height: 50 }} > 
      <Text>Option2</Text> 
    </Button> 

この

は私のコードです。そして別のボタンをクリックすると、私が押されたボタンが背景を取得し、最初のボタンが通常の透明な背景に戻ります。私はボタンに2つのアクションをどのように追加することができるかわからない。誰かが助けることができれば、私はそれを感謝します。必ずしもボタンライブラリを使用する必要はありませんので、これについてのアイデアは大歓迎です!

ありがとうございました!

答えて

0

私は、フラックスルータを使用してシーンをナビゲートします。これは、押したときにボタンの背景色を変更する方法です:

constructor() { 
     super(); 
     state = { 
     color1: 'transparent', 
     color2: 'transparent', 
     } 
    } 

    setActive(button) { 
     if (button === 1) { 
     if (this.state.color1 === 'transparent') { 
      this.setState({ 
      color1: 'red', 
      color2: 'transparent' 
      }) 
     } 
     } else { 
     if (this.state.color2 === 'transparent') { 
      this.setState({ 
      color2: 'red', 
      color1: 'transparent' 
      }) 
     } 
     } 
    } 

    { . . . } 

    <Button 
     onPress={this.setActive.bind(this, 1)} 
     style={{ width: 50, height: 50, backgroundColor: this.state.color1 }} 
    > 
     <Text>Option1</Text> 
    </Button> 

    <Button 
     this.setActive.bind(this, 2) 
     style={{ width: 50, height: 50, backgroundColor: this.state.color2 }} 
    > 
     <Text>Option2</Text> 
    </Button> 
関連する問題