-
Notifications
You must be signed in to change notification settings - Fork 0
/
31_dynamic_radio_button.js
71 lines (59 loc) · 1.35 KB
/
31_dynamic_radio_button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React,{useEffect,useState} from 'react';
import { Button, Text, View,TouchableHighlight,TouchableOpacity, FlatList,SectionList,TextInput,StyleSheet } from 'react-native';
const App = () => {
const skills = [
{id:1,name:'Javascript'},
{id:2,name:'React'},
{id:3,name:'React Native'},
{id:4,name:'Node'},
]
const [selectedRadio,setSelectedRadio] = useState(1)
return (
<View style={styles.main}>
{
skills.map((item,index)=>{
<TouchableOpacity onPress={()=> setSelectedRadio(item.id)}>
<View style={styles.radioWrapper}>
<View style={styles.radio}>
{
selectedRadio===item.id? <View style={styles.radioBg}></View>:null
}
</View>
<Text style={styles.radioText}>Radio1</Text>
</View>
</TouchableOpacity>
})
}
</View>
);
}
const styles = StyleSheet.create({
main:{
flex:1,
alignItems:'center',
justifyContent:'center',
},
radioText:{
fontSize:20,
},
radio:{
height:40,
width:40,
borderColor:'black',
borderWidth:2,
borderRadius:20,
margin:10,
},
radioWrapper:{
flexDirection:'row',
alignItems:'center',
},
radioBg:{
height:28,
width:28,
backgroundColor:'black',
borderRadius:14,
margin:4,
}
})
export default App;