image - React Native 如何延迟加载图像

标签 image reactjs react-native lazy-loading reactjs-flux

我有一个 ListView ,我想在每一行上显示图像,但我不想一次显示全部 25 个图像。我只想加载视口(viewport)中的图像。

我在 props 中获取 url

<Image source={{uri: this.props.media.image_url}} 
       style={{ width:this.props.media.width,
       height: this.props.media.height}}
/>

我怎样才能在 native react 中实现这一目标。 注意:我已经尝试过这些库,但没有一个适合我。可能是为旧版本的react编写的版本问题加上其中一些不适用于动态 Prop

react-native-lazyload

react-lazy-load

最佳答案

您可以使用react native elements .

添加到项目:npm install --save react-native-elements

用法:

import { ActivityIndicator } from 'react-native';
import { Image } from 'react-native-elements';

// Standard Image
<Image
  source={{ uri: image }}
  style={{ width: 200, height: 200 }}
/>


// Image with custom placeholder content
<Image
  source={{ uri: image }}
  style={{ width: 200, height: 200 }}
  PlaceholderContent={<ActivityIndicator />}
/>

来源:react native elements

关于image - React Native 如何延迟加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38735017/

相关文章:

css - 如何对齐 2 个 react native 元素,1 个在中心,1 个在开头

typescript - React Native with Typescript and Jest 在 0.57 更新 : Couldn't find preset "module:metro-react-native-babel-preset" relative to directory 后被破坏

java - 如何获取图像中每个像素的强度。我想计算图像中更高强度的像素

javascript - 当鼠标在信息框内时防止 map 拖动(但也允许文本突出显示)

javascript - React Native Card Carousel View ?

testing - 如何在 React ES6 类中测试箭头函数

css - 如何在 react 组件上添加多个类名

image - Rust - 图像 crate : issue saving image buffer

html - 批处理脚本 : image manipulating by adding logo and footer

java - 使用 OpenCV - Java 在收据上查找边缘并校正角度