react-native-image-zoom-viewer學習

github原地址react

react-native-image-zoom-viewer實現了相似微信朋友圈瀏覽圖片的效果,點擊小圖片實現瀏覽原圖效果。git

安裝:github

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

react-native link react-native-image-zoom-viewerreact-native

代碼以下:微信

import  ImageViewer  from 'react-native-image-zoom-viewer';this

import {Modal,} from'react-native'url

{
                                this.state.imageArry.map((item, index)=> {

                                    return this._renderImage(item, index);
                                })
                            }

  

//圖片排列
    _renderImage(item, index) {
        let url = item.url;
        let source = {uri: url};
        return (
            <View style={{alignItems: 'center', marginTop: 5, marginLeft: 5}} key={'image' + index}>
                <TouchableOpacity onPress={this._openMax.bind(this, source, index)}>
                    <Image source={source}
                           style={styles.img}/>
                </TouchableOpacity>
            </View>
        );
    }

  

_openMax(source, index) {
        this.setState({
            isImageShow: true,
            imageIndex: index,
        });
    }

  

{this.state.isImageShow ?
                            <Modal visible={true} transparent={true}
                                   onRequestClose={()=> {
                                       this.setState({
                                           isImageShow: false,
                                       });
                                   }}>
                                <ImageViewer imageUrls={this.state.dataArry}
                                             onCancel={()=> {
                                                 this.setState({
                                                     isImageShow: false,
                                                 });
                                             }}
                                             index={this.state.imageIndex}
                                             saveToLocalByLongPress={false}/>
                            </Modal>
                            : null}
相關文章
相關標籤/搜索