ReactNative实现图集功能
需求描述:
圖片縮放、拖動、長按保存等基礎(chǔ)圖片查看的功能;
展示每張圖片文本描述;
實(shí)現(xiàn)效果,如圖:
實(shí)現(xiàn)步驟
使用第三方插件:react-native-image-zoom-viewer
插件GitHub地址:https://github.com/ascoders/react-native-image-viewer
開放參數(shù)說明:https://github.com/ascoders/react-native-image-viewer/blob/master/src/image-viewer.type.ts
實(shí)現(xiàn)思路:
1.圖集展示部分使用‘react-native-image-zoom-viewer’的ImageViewer控件完整實(shí)現(xiàn);
2.每張圖片的說明使用ScrollView嵌套Text進(jìn)行展現(xiàn),ImageViewer開放自定義renderFooter方法,提供當(dāng)前圖片下標(biāo)(currentIndex),這樣就可以分別展示每張圖片對于的文字了。
react-native-image-zoom-viewer的使用具體參見GitHub地址的步驟進(jìn)行配置。
實(shí)現(xiàn)代碼:
import React, { Component } from 'react'; import {AppRegistry,StyleSheet,Text,View,Image,Modal,ScrollView, } from 'react-native'; import ImageViewer from 'react-native-image-zoom-viewer';const images = [{url: 'http://static.gangguwang.com/image/2017/8/29/16/24/59a524af10f4e8000900198c.jpg' }, {url: 'http://static.gangguwang.com/image/2017/8/29/16/7/59a520d710f4e80009001950.jpg' }]; let imgsDesc = ["主播上午有事不在公司,拍攝安排被調(diào)到了下午,小侯就提前在電腦面前到處瀏覽網(wǎng)站,找下一周視頻的拍攝主題。視頻一旦拍出來就要趕緊制作,剛制作完上傳到網(wǎng)上又要開始下一期欄目的劇本構(gòu)思,主題內(nèi)容既要是當(dāng)下熱點(diǎn)又要能維持熱度直到視頻上傳,還要考慮適合遠(yuǎn)近鏡頭的表現(xiàn)和鏡頭的切換等,所以小侯每周最頭疼的事情就是拍攝主題。","徐小明是陜西西安東嶺旗下的業(yè)務(wù)員!" ];class index extends Component {render() {return (<Modal visible={true} ><ImageViewer imageUrls={images} renderFooter={(currentIndex) => {return (<ScrollView style={{ height: 70, marginTop: -70 }}><Text style={{ color: '#fff', paddingLeft: 10, paddingRight: 10 }}>{imgsDesc[currentIndex]}</Text></ScrollView>);}} /></Modal >);} }const styles = StyleSheet.create({container: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#fff',} });module.exports = index;
?
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的ReactNative实现图集功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IDEA 正式版终于支持中文版和 JDK
- 下一篇: 近100个Spring/SpringBo