Skip to content

Instantly share code, notes, and snippets.

@Donhv
Last active June 21, 2018 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Donhv/fec5989d804cb697ea631a303db6ae69 to your computer and use it in GitHub Desktop.
Save Donhv/fec5989d804cb697ea631a303db6ae69 to your computer and use it in GitHub Desktop.
react-native button-radio
export default class ButtonRadio extends React.Component {
constructor(props) {
super(props);
this.state = {
itemSelected: 1,
multiItemSelected: [1, 2]
};
}
render() {
return (
<FlatList
data={this.props.arrData}
renderItem={this._renderItem}
extraData={this.state}
ItemSeparatorComponent={() =>
<View style={{ height: 0.2, backgroundColor: 'grey' }} />}
/>
)
}
_renderItem = ({ item }) => {
return (
<TouchableOpacity activeOpacity={1}
style={{
height: 50, justifyContent: 'center',
backgroundColor: (!this.props.isMultichoice) ? ((this.state.itemSelected === item.key) ? 'grey' : 'white')
: (this.state.multiItemSelected.includes(item.key) ? 'grey' : 'white')
}}
onPress={() => {
this.setState({ itemSelected: item.key })
}}>
<View>
<Text style={{ marginLeft: 20 }}>{item.value}</Text>
</View>
</TouchableOpacity >
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment