How to enable and disable a button in React Native and to disable it to put it in a different color

-2

I would like to know how to enable and disable a button and how to enable it I change the color.

<TouchableOpacity  disabled={disabled} onPress={() =>   navigation.navigate("ReviewOrder",{quantityOrders:screenProps.quantityOrders})}>
        <View style={styles.circleOrder}>
          <Text style={styles.labelNroOrder}>{screenProps.quantityOrders}</Text>
        </View>
      </TouchableOpacity>: null
  }
    
asked by Rogger Claudio Aponte 31.05.2018 в 00:54
source

1 answer

0
  

this may work for you

    constructor(props) {
      super(props);
      this.state = {
         disabled: true
      };
   }

   funciona() {
      console.log('yey! :3');
   }

   habilitarBoton() {
      this.state.disabled === true ?
        this.setState({disabled: false})
        :this.setState({disabled: true});
   }

   render() {
      let colorDelBoton = [{backgroundColor: this.state.disabled === false ? '#face34' : 'gray'}];
      return (<View>
         <TouchableOpacity onPress={() => this.habilitarBoton()}>
            <Text>Habilitar el otro boton</Text>
         </TouchableOpacity>
         <TouchableOpacity style={colorDelBoton} onPress={() => this.state.disabled === false ?this.funciona() :null}>
            <Text>Otro boton</Text>
         </TouchableOpacity>
      </View>);
   }
    
answered by 28.06.2018 в 19:38