【问题标题】:React native Loading image and store in Device?反应原生加载图像并存储在设备中?
【发布时间】:2021-09-07 14:36:33
【问题描述】:

我正在为 ios 和 android 创建 react 本机应用程序 在应用程序中,有很多图像和 GIF 会增加应用程序的大小 为了解决我将图像上传到服务器并从服务器加载的问题 **但问题是我不希望每次用户打开应用程序时都加载图像,而是我需要将它们存储在本地存储中并从那里读取如果图像在本地存储中不可用,那么它将下载并存储在那里.需要在本机反应中做到这一点的最佳方法** React 原生版本 0.64

【问题讨论】:

标签: android ios image react-native native


【解决方案1】:

在调用 api 从服务器获取图像之前,如果您使用的是 AsyncStorage,请检查图像是否存储在 AsyncStorage 中

const loadLocalImages = async() => {
    try {
      const images = await AsyncStorage.getItem('@images_Key');
           if(images !== null) {
               //set your variables
            }else {
               //fetch images from api
             }
       }cache(e){
          //log error if any
       }
 } 

【讨论】:

猜你喜欢
  • 2018-09-11
  • 2021-04-19
  • 1970-01-01
  • 2021-12-08
  • 2021-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-08
相关资源
最近更新 更多