Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement radio button in React Native

I am converting React code to React Native. So I need to implement radio buttons.

like image 738
vasavi Avatar asked Aug 08 '15 05:08

vasavi


1 Answers

You can mimic a radio button really easily using just barebones RN. Here's one simple implementation which I use. Tweak size, colors etc. as you like. It looks like this (with a different tint, and some text). Add TouchableOpacity on top to turn it into a button that does something.

enter image description here

function RadioButton(props) {   return (       <View style={[{         height: 24,         width: 24,         borderRadius: 12,         borderWidth: 2,         borderColor: '#000',         alignItems: 'center',         justifyContent: 'center',       }, props.style]}>         {           props.selected ?             <View style={{               height: 12,               width: 12,               borderRadius: 6,               backgroundColor: '#000',             }}/>             : null         }       </View>   ); } 
like image 156
Lane Rettig Avatar answered Oct 02 '22 15:10

Lane Rettig