React Native 圖片查看組件

本文原創首發於公衆號:ReactNative開發圈,轉載需註明出處。react

新的一年,新的開始,祝你們旺旺年旺旺旺!

React Native 圖片查看組件:react-native-image-viewer,純JS組件,小巧快速的圖標查看組件。支持圖片放大縮小,支持圖片加載失敗設置替代圖片,支持將圖片保存到本地等功能。

效果圖

安裝方法

npm i react-native-image-zoom-viewer --savegit

使用示例

const images = [
  {
    url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460',
  },
  {
    url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460',
  },
  {
    url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460',
  },
];

export default class Component06 extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={{ flex: 1 }}>
        <ImageViewer
          imageUrls={images}
          failImageSource={{
            url: 'https://avatars2.githubusercontent.com/u/7970947?v=3&s=460',
            width: Dimensions.get('window').width,
            height: Dimensions.get('window').width,
          }}
        />
      </View>
    );
  }
}

主要參數說明

  • imageUrls 圖片url地址的數組
  • enableImageZoom 是否容許縮放
  • failImageSource 加載失敗時顯示的圖片
  • loadingRender 加載loading
  • renderHeader 頭部樣式
  • renderFooter 底部樣式
  • renderIndicator 頁碼指示器樣式

完整示例

完整代碼:https://github.com/forrest23/ReactNativeComponents
本次示例代碼在 Component06文件夾中。請不要吝嗇大家的Stargithub

組件地址

https://github.com/ascoders/react-native-image-viewernpm

微信不讓跳轉外鏈,能夠點擊查看原文來查看外鏈GitHub內容。react-native

舉手之勞關注個人微信公衆號:ReactNative開發圈
數組

相關文章
相關標籤/搜索