简体   繁体   English

React Native使用选择器选择国家和国旗

[英]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. 我想知道如何实现React Native选择器来选择国家和国旗的图像。 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. 我只是遇到了这个本机库本身的react-native-country-picker-modal,同时寻找相同的东西。

Supports both Android and iOS 支持Android和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 如果您非常热衷,可以查看实现src / CountryPicker.jsscripts / transform-world-countries.jssrc / countryFlags.js的内部结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 react native,如何在 react-native-country-picker-modal 中显示标志 - react native, how to show flag in react-native-country-picker-modal 安装react-native-country-picker-modal后出现内部错误 - Internal Error After Installing react-native-country-picker-modal 使用带有钩子的 React Native Picker - using react native picker with hooks 带有选择器的启用和禁用按钮反应原生 - enabled and disabled button with select picker react native 如何使用 formik inReact Native 在表单提交上重置 react-native-picker-select? - How to Reset react-native-picker-select on form submit using formik inReact Native? 使用图像选择器反应原生开放画廊 - react native open gallery using image picker 与 typescript 项目反应的国家标志 - react country flag in react with typescript project 反应原生:图像正在使用 expo-image-picker 上传,但不使用 react-native-image-picker 上传 - react native : image is uploading using expo-image-picker but not uploading using react-native-image-picker 如何从下拉选择器 React Native 中显示和选择项目 - How to show and select items from a dropdown picker React Native React Native Picker select:Android 是否有可用的回调? - React Native Picker select: are there any callbacks available for Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM