您可以 require() App.js 中的图像之前加载它们。像这样做:
async function loadResourcesAsync() {
await Promise.all([
Asset.loadAsync([
require('./assets/images/stock1.jpg'),
require('./assets/images/stock2.jpg'),
require('./assets/images/undraw1.png'),
]),
Font.loadAsync({
// This is the font that we are using for our tab bar
...Ionicons.font,
// We include SpaceMono because we use it in HomeScreen.js. Feel free to
// remove this if you are not using it in your app
'open-sans-regular': require('./assets/fonts/OpenSans-Regular.ttf'),
'open-sans-extrabold': require('./assets/fonts/OpenSans-ExtraBold.ttf'),
}),
]);
}
我在这里使用 Expo,你不需要创建这个函数,它已经在 App.js 中,只需在 require() 函数中添加你的图像。
我不知道这在没有 Expo 的情况下是否适用于 React Native。