I have a strange problem with the TouchableOpacity component. I have a MainButton component that accepts 2 MainButton , item and disabled . Based on disabled prop, I want my MainButton component to use a different style. The problem is that the TouchableOpacity re reenders component does not update the style. The prop disabled icon is correctly set to re render.
What makes it strange is that if I change it to TouchableHeighlight , it will work as expected.
Does anyone know why? Is this a bug in TouchableOpacity?
import React, { Component } from 'react' import UI from '../styles/ui' import { Text, TouchableOpacity } from 'react-native' const ui = new UI() const styles = ui.styles class MainButton extends Component { constructor (props) { super(props) this.state = { disabled : props.disabled, item: props.item } } componentWillReceiveProps(props) { this.setState({disabled:props.disabled}) } render() { var normalStyles = [styles.mainButton,styles.widthEighty] var disabledStyle = [styles.mainButton,styles.widthEighty,styles.lowOpacity] var correctStyles = this.state.disabled ? disabledStyle : normalStyles console.log(this.state.disabled,'this.state.disabled ? '); return ( <TouchableOpacity disabled={this.state.disabled} style={correctStyles} accessibilityLabel={this.state.item.name} onPress={this.state.item.onPress.bind(this)}> <Text style={styles.mediumLabel}>{this.state.item.name}</Text> </TouchableOpacity> ); } } export { MainButton as default }
Zolve source share