我花了很多时间来解决这个问题,但找不到解决方案。皮斯 需要有关如何从反应矢量图标获取图标的帮助。在我的代码下面和 包.json 文件。我只想在导航栏中添加一个菜单图标...感谢您的帮助
import React from 'react';
import {View, Text, StyleSheet, Image, TouchableOpacity} from 'react-native';
// import {FiMenu} from 'react-icons/fi';
//import MenuIcon from '@material-ui/icons/Menu';
import Icon from 'react-native-vector-icons/';
const MenuNav = ({navigation}) => {
const showDrawer = () => {
navigation.openDrawer();
};
return (
<View style={styles.menucontainer}>
<TouchableOpacity style={styles.img} onPress={showDrawer}>
<Image source={require('../imgs/menu.png')} />
<Icon
name="check"
color="rgba(0, 0, 0, 0.38)"
size={25}
type="entypo"
/>
</TouchableOpacity>
<Text style={styles.text}>Menu</Text>
</View>
);
};
"dependencies": {
"@material-ui/core": "^4.10.2",
"@material-ui/icons": "^4.9.1",
"@react-native-community/masked-view": "^0.1.10",
"@react-navigation/drawer": "^5.8.2",
"@react-navigation/native": "^5.5.1",
"@react-navigation/stack": "^5.5.1",
"react": "16.11.0",
"react-icons": "^3.10.0",
"react-native": "0.62.2",
"react-native-gesture-handler": "^1.6.1",
"react-native-reanimated": "^1.9.0",
"react-native-safe-area-context": "^3.0.5",
"react-native-screens": "^2.8.0",
"react-native-vector-icons": "^6.6.0"
},
错误:元素类型无效:需要字符串(对于内置组件(或 类/函数(用于复合组件(,但得到:未定义。你可能忘了 从定义组件的文件中导出组件,否则您可能混淆了 违约
并命名导入。
您以错误的方式导入Icon
。
在react-native-vector-icons
中,您应该这样做:
import Icon from 'react-native-vector-icons/SimpleLineIcons'
// and replace SimpleLineIcons with the set of icons you want to use
在这里,您可以获得集合的完整列表。