English 中文(简体)
在当地拯救在线形象
原标题:Save online image locally

我正在通过URL从我的服务器获得一个简介:

<Image
    source={
      profilePictureUrl !==   
        ? {uri: API_URL +  /  + profilePictureUrl}
        : PROFILE_DEFAULT
    }
    style={{width: 200, height: 200, borderRadius: 100}}
  />

在用户离线时,我如何能够在我的装置上挽救这一形象?

最佳回答

您可使用prefetch图像部件方法,下载图像和储存,供日后使用。

电话:await 图像:prefetch(API_URL+/+profilePictureUrl);,一俟用户在网上展示这种形象,如果你有照片。

问题回答

that depends on the purpose of the usage of this image do you want to cache it then you can go with FastImage

import FastImage from  react-native-fast-image 

const YourImage = () => (
    <FastImage
        style={{ width: 200, height: 200 }}
        source={{
            uri:  https://unsplash.it/400/400?image=1 ,
            priority: FastImage.priority.normal,
        }}
        resizeMode={FastImage.resizeMode.contain}
    />
) 

but if you want to use it for offline purposes then you can go with the option of using @react-native-async-storage/async-storage or any other storages that your

import AsyncStorage from  @react-native-async-storage/async-storage ;

// Save the image to async storage
await AsyncStorage.setItem( profilePicture , uri);




相关问题
HandleClick not being recognized as a prop

I m trying to get my menu to show when I click the sidebar, but I m getting an error "react-dom.development.js:86 Warning: React does not recognize the handleClick prop on a DOM " import { ...

Is there an equivalent to localStorage in React Native?

I d like to implement the equivalent to the javascript localStorage in my React Native app. But I m unsure how to set. To function how I want it to, I would like the localStorage to be stored every ...

Video Calling in Expo React Native Application

I am building a React Native Application using Expo and I want to integrate a 1:1 video calling functionality in the app. From what I have researched so far on the topic is that I can use SDKs of ...

热门标签