首页 > 解决方案 > react-native 中如何优雅的管理图片资源?

问题描述

我有很多图片要在很多屏幕上管理。每次我加载图片时

<Image source={require("../../images/001.png")} style={styles.image1}/>

但是它太乏味了,因为它要编写的内容太多并且难以管理。

我想一起管理图像。像

  export default function loadImages(){
     return {
        img1:require("../../images/001.png"),
        img2:require("../../images/002.png"),
        ...
     }
  }

然后像这样使用它。

import Images from "image.js"
<Image source={Images.img1} />

但是我担心返回的对象会太大并且占用太多的内存资源。会是吗?有人有一些优雅的解决方案吗?

标签: react-nativeassets

解决方案


推荐阅读