简体   繁体   中英

React Native using picker to select country & flag

I would like to know how to implement React Native picker to select a country and an image of the flag. Any help would be appreciated

import React, { Component } from 'react'
import { Text, View, Image, Picker } from 'react-native'

export default class country extends Component {
    constructor(props) {
        super(props);
        this.state = { country: ""};
        this.state = {updatedCountry};
      }

  render() {
    return (
      <View>
        <Picker selectedValue = {this.state.country} onValueChange = {this.updatedCountry}>
               <Picker.Item label = "America" value = "flag" />
               <Picker.Item label = "England" value = "Flag" />
            </Picker>
            <Text style = {styles.text}>{this.state.country}</Text>
      </View>
    )
  }
}

I just came across this react-native library react-native-country-picker-modal while looking for the same.

Supports both Android and iOS

例

Uses world-countries to populate the list.

If you are very keen you can check out the internals of the implementation src/CountryPicker.js , scripts/transform-world-countries.js , src/countryFlags.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM