I have a React Native component that consists of 3 buttons components, each one has a boolean property called inner. If inner={true} then the button appears pressed in, whereas if inner={false} then the button appears embossed.
Only one button can be active at any one time, I'd like to make it such that the active button will display inner={true} and the other two inactive buttons will display inner={false}.
Here is my code below:
const ChoiceContainer = props => {
const {children} = props;
return <View>{children}</View>;
};
const SendTransaction = () => (
<ChoiceContainer>
<Text>Component 1</Text>
</ChoiceContainer>
);
const Remove = () => (
<ChoiceContainer>
<Text>Component 2</Text>
</ChoiceContainer>
);
const History = () => (
<ChoiceContainer>
<Text>Component 3</Text>
</ChoiceContainer>
);
export default class MyComponent extends Component {
state = {
sceneType: 'add',
};
showSend = () => {
this.setState({sceneType: 'add'});
};
showReceive = () => {
this.setState({sceneType: 'remove'});
};
showHistory = () => {
this.setState({sceneType: 'history'});
};
renderScene = type => {
if (type === 'add') {
return <SendTransaction />;
}
if (type === 'remove') {
return <ReceiveTransaction />;
}
if (type === 'history') {
return <TransactionHistory />;
}
};
render() {
const {sceneType} = this.state;
return (
<View>
<View>
<TouchableOpacity onPress={this.showAdd}>
<Button inner={true}>Button 1</Button>
<TouchableOpacity onPress={this.showRemove}>
<Button inner={false}>Button 2</Button>
</TouchableOpacity>
<TouchableOpacity onPress={this.showHistory}>
<Button inner={false}>Button 3</Button>
</TouchableOpacity>
</View>
<View>{this.renderScene(sceneType)}</View>
</View>
);
}
}