gpt4 book ai didi

reactjs - 为什么在 expo build :android? (React Native) 之后,图像没有显示在 apk 上

转载 作者:行者123 更新时间:2023-12-03 13:45:35 25 4
gpt4 key购买 nike

我创建了一个应用程序(使用 React Native Expo),其中包含一些图像,例如:

<Image source={require('../assets/facebook_button.png')} />

图像位于 Assets 目录中,我可以使用 npm publish 查看它们或npm start功能。

问题出在使用 exp build:android 构建应用程序时,现在 apk 显示静态图像(但显示了我从 Internet 加载的其他一些图像)。

这是我的 app.json:

{
"expo": {
"name": "my-interesting-app",
"description": "My Interesting App",
"slug": "my-interesting-app",
"privacy": "public",
"sdkVersion": "29.0.0",
"platforms": ["ios", "android"],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*",
"assets/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.myinteresting.myinterestingapp"
},
"android": {
"package": "com.myinteresting.myinterestingapp"
},

}
}

感谢您的帮助

最佳答案

尝试在加载之前缓存图像。

import React from 'react';
import { Image, Text, View } from 'react-native';
import { Asset, AppLoading } from 'expo';

export default class App extends React.Component {
state = {
isReady: false,
};

render() {
if (!this.state.isReady) {
return (
<AppLoading
startAsync={() => this._cacheResourcesAsync()}
onFinish={() => this.setState({ isReady: true })}
onError={console.warn}
/>
);
}

return (
<View style={{ flex: 1 }}>
<Image source={require('./assets/images/expo-icon.png')} />
<Image source={require('./assets/images/slack-icon.png')} />
</View>
);
}

async _cacheResourcesAsync() {
return Asset.loadAsync([
require('./assets/images/expo-icon.png'),
require('./assets/images/slack-icon.png'),
]);
}
}

引用文献:

关于reactjs - 为什么在 expo build :android? (React Native) 之后,图像没有显示在 apk 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51686444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com