Typescript 在react native中创建下拉菜单

Typescript 在react native中创建下拉菜单,typescript,react-native,dropdown,Typescript,React Native,Dropdown,我想在react native和typescript中创建如下所示的下拉菜单。 请推荐一种在ios和android上实现的方法。 react native library()提供了一个选择器组件。 您还可以使用诸如native base()之类的库。然后将onPress操作附加到它,或者使用react native popupmenu库,但我在使用类型脚本时遇到问题。检查完整示例以创建下拉菜单 /** * Sample React Native App * https://github.co

我想在react native和typescript中创建如下所示的下拉菜单。 请推荐一种在ios和android上实现的方法。

react native library()提供了一个选择器组件。
您还可以使用诸如native base()之类的库。然后将onPress操作附加到它,或者使用react native popupmenu库,但我在使用类型脚本时遇到问题。

检查完整示例以创建下拉菜单

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from "react";
import { Platform, StyleSheet, Text, View, Alert, YellowBox} from "react-native";
import { Menu, MenuProvider, MenuOptions, MenuOption, MenuTrigger} from "react-native-popup-menu";

export default class HomeActivity extends Component {

  constructor(props) {
     super(props);
     YellowBox.ignoreWarnings([
      'Warning: isMounted(...) is deprecated', 'Module RCTImageLoader'
    ]);
   }

  render() {
    return (
      <MenuProvider style={{ flexDirection: "column", padding: 30 }}>
        <Menu onSelect={value => alert(`You Clicked : ${value}`)}>

          <MenuTrigger  >
          <Text style={styles.headerText}>DropDown Menu</Text>
          </MenuTrigger  >

          <MenuOptions>
            <MenuOption value={"Login"}>
              <Text style={styles.menuContent}>Login</Text>
            </MenuOption>
            <MenuOption value={"Register"}>
              <Text style={styles.menuContent}>Register</Text>
            </MenuOption>
            <MenuOption value={"Download"}>
              <Text style={styles.menuContent}>Download</Text>
            </MenuOption>
            <MenuOption value={"Logout"}>
              <Text style={styles.menuContent}>Logout</Text>
            </MenuOption>
            <MenuOption value={3} disabled={true}>
              <Text style={styles.menuContent}>Disabled Menu</Text>
            </MenuOption>
          </MenuOptions>

        </Menu>
      </MenuProvider>
    );
  }
}

const styles = StyleSheet.create({
    headerText: {
    fontSize: 20,
    margin: 10,
    fontWeight: "bold"
  },
  menuContent: {
    color: "#000",
    fontWeight: "bold",
    padding: 2,
    fontSize: 20
  }
});
/**
*示例React本机应用程序
* https://github.com/facebook/react-native
*@flow
*/
从“React”导入React,{Component};
从“react native”导入{平台、样式表、文本、视图、警报、黄盒};
从“react native popup Menu”(反应本机弹出菜单)导入{Menu,MenuProvider,MenuOptions,MenuOptions,MenuTrigger};
导出默认类HomeActivity扩展组件{
建造师(道具){
超级(道具);
YellowBox.ignoreWarnings([
“警告:isMounted(…)已弃用”,“模块RCTImageLoader”
]);
}
render(){
返回(
警报(`Your Clicked:${value}`)}>
下拉菜单
登录
登记
下载
注销
禁用菜单
);
}
}
const styles=StyleSheet.create({
标题文字:{
尺寸:20,
差额:10,
fontWeight:“粗体”
},
菜单内容:{
颜色:“000”,
fontWeight:“粗体”,
填充:2,
尺寸:20
}
});

picker(react-native)或react-native material下拉菜单我只是想知道,是否还有其他方法可以动态填充菜单选项?是的,可以使用react-state对象。谢谢我的朋友,这真的很有帮助