问题
I'm starting a very basic build. I'm using `create-react-native-app' and yarn for pm.
From there all I have tried to accomplish is to load in 'native-base' for some UI elements.
From the app.js file the only thing I've added is a Button Component from native-base.
<Button> <Text></Text> </Button>
And have included native-base.
After receiving some errors that it couldn't resolve module '@expo/vector-icons'
I went and installed @expo/vector-icons, and for the hell of it ran react-native link
.
Now it can find @expo/vector-icons but it can't find the fonts starting with Ionicons.ttf
.
SO. From there I downloaded all the fonts to a assets/fonts/
directory and then included this in my app.js file based off some documentation I found on the expo site.
import { Font } from 'exponent';
///
export default class App extends React.Component {
componentDidMount() {
Font.loadAsync({
'ionicons': require('./assets/fonts/Ionicons.ttf'),
});
}
///
回答1:
They way I load custom fonts is by adding them in the Info.plist file as a list of Font provided by the application:
And they also need to be in the provided resources of the Build Phases:
After that, you can use it in the fontFamily property in CSS in react native. Make sure you also clean and build the project again after adding the fonts so they are copied to the device.
来源:https://stackoverflow.com/questions/42842109/react-native-cant-resolve-module-for-fonts