1

문제는 간단하지만 생각할 수 없습니다. 나는 react-native-router-flux 라이브러리와 NativeBase 라이브러리를 버튼에 사용하고 있습니다. 나는 내가 그것을 누를 때마다 버튼의 배경색을 변경하려면 그것은 활성의React-Native : 백그라운드 보조 조치를 변경하는 방법

<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> 

:

내 코드입니다. 다른 버튼을 클릭하면 방금 누른 버튼이 배경을 가져오고 첫 번째 버튼이 일반 투명 배경으로 돌아갑니다. 단추에 두 가지 동작을 추가 할 수있는 방법이 확실하지 않습니다. 누구든지 도움을 줄 수 있다면 고맙겠습니다. 꼭 버튼 라이브러리를 사용할 필요는 없으므로 이에 대한 아이디어는 언제나 환영합니다!

감사합니다.

답변

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>