React native RadioButton (radio button)

Source: Internet
Author: User



Just finished this multi-select button, I think there is no radio, always feel a little uncomfortable, because in the project I also did not use the radio, so I did not study the source code, so I found a bit on GitHub, find a very good, simple, not fancy.



Search for this on GitHub


React-native-flexi-radio-button


After the download, you can use it directly.


 
 
1 import React, { Component } from ‘react‘;
 2 import {
 3   StyleSheet,
 4   Text,
 5   View
 6 } from ‘react-native‘;
 7 
 8 import {RadioGroup, RadioButton} from ‘react-native-flexi-radio-button‘
 9 
10 class App extends Component{
11 
12     constructor(){
13         super()
14         this.state = {
15             text: ‘‘
16         }
17         this.onSelect = this.onSelect.bind(this)
18     }
19 
20     onSelect(index, value){
21         this.setState({
22         text: `Selected index: ${index} , value: ${value}`
23         })
24     }
25 
26     render(){
27         return(
28             <View style={styles.container}>
29                 <RadioGroup
30                     onSelect = {(index, value) => this.onSelect(index, value)}
31                 >
32                     <RadioButton value={‘item1‘} >
33                         <Text>This is item #1</Text>
34                     </RadioButton>
35 
36                     <RadioButton value={‘item2‘}>
37                         <Text>This is item #2</Text>
38                     </RadioButton>
39 
40                     <RadioButton value={‘item3‘}>
41                         <Text>This is item #3</Text>
42                     </RadioButton>
43 
44                 </RadioGroup>
45                 
46                 <Text style={styles.text}>{this.state.text}</Text>
47             </View>
48         )
49     }
50 }
51 
52 let styles = StyleSheet.create({
53     container: {
54         marginTop: 40,
55         padding: 20
56     },
57     text: {
58         padding: 10,
59         fontSize: 14,
60     },
61 })
62 
63 module.exports = App






React native RadioButton (radio button)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.