我正在尝试使用create-react-native-app与世博在一个单一的设置。当我从一个子文件夹app/启动应用程序并导入@expo/vector-icons时,我会发现字体家族丢失了一个错误。
"fontFamily" 'material' is not a system font and has not been loaded
through Expo.Font.loadAsync.如果我在主src/文件夹中启动应用程序,图标就会很好地加载。
我已经配置了我的rn-cli.config.js,以便该应用程序能够对其他依赖项进行编译和运行。我的项目的设置类似于一个monorepo,这样我就可以在回购中拥有多个本地应用程序。
src/
MainApp.js
package.json
app/App.js
app/app.json
app/package.json
app/rn-cli.config.js
...我试过几件事都没有用:
@expo/vector-icons中安装package.json"assetExts": ["ttf"]文件中设置app.json。我的代码(主要来自一个新的creat-react-native-app):
app/App.js
export { default } from "../MainApp";app/app.json
{
"expo": {
"sdkVersion": "22.0.0",
"react": "16.0.0-beta.5"
}
}app/package.json
{
"private": true,
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"native": "react-native-scripts start"
},
"dependencies": {
"@expo/vector-icons": "^6.2.1",
"expo": "^22.0.0",
"react-native": "^0.49.0",
"react-native-scripts": "1.7.0"
}
}app/rn-cli.config.js
const blacklist = require("metro-bundler/src/blacklist");
const path = require("path");
const roots = [process.cwd(), path.resolve(__dirname, "..")];
const config = {
getProjectRoots: () => roots,
/**
* Specify where to look for assets that are referenced using
* `image!<image_name>`. Asset directories for images referenced using
* `./<image.extension>` don't require any entry in here.
*/
getAssetRoots: () => roots,
/**
* Returns a regular expression for modules that should be ignored by the
* packager on a given platform.
*/
getBlacklistRE: () =>
blacklist([
// Ignore the local react-native so that we avoid duplicate modules
/\/app\/node_modules\/react-native\/.*/
])
};
module.exports = config;package.json
{
"name": "react-native-app",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.7.0"
},
"scripts": {
"native": "cd app && yarn native"
},
"dependencies": {
"@expo/vector-icons": "^6.2.1",
"expo": "^22.0.0",
"react": "16.0.0-beta.5",
"react-native": "^0.49.0"
}
}MainApp.js
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import MaterialIcons from "react-native-vector-icons/MaterialIcons";
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Text>Changes you make will automatically reload.</Text>
<Text>Shake your phone to open the developer menu.</Text>
<MaterialIcons name="search" color="black" size={32} />
<MaterialIcons name="location-searching" color="black" size={32} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
}
});发布于 2017-12-06 06:52:11
问题似乎是我有两个不同的世博会模块。摆脱子文件夹中的那个使它正常工作。
发布于 2017-12-04 22:09:19
我是一个很新的反应-本土的,但我有一个类似的问题,我解决了完全不安装世博图标,并使用它们正常。所以在我的package.json里
"react-native-vector-icons": "^4.4.2",我导入的字体如下:
import Icon from 'react-native-vector-icons/FontAwesome';我敢打赌这不是一个完美的解决方案,但由于世博只是一种让事情变得更简单的工具,我不觉得做一些有用的事情会有什么不好,而不是使用另一种使事情复杂化的工具;
发布于 2019-02-25 11:37:59
我的世博会版本是“博览会”:"^32.0.0“。您所需要做的就是添加您的字体系列,它支持react本机-矢量-图标组,如AntDesign、MaterialIcons、FontAwesome等。
import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome';
<FontAwesomeIcon name="circle" size={10} color="#FF6859" style={{ marginLeft: 5 }} />您还可以从https://expo.github.io/vector-icons/找到图标。
https://stackoverflow.com/questions/47642178
复制相似问题