GithubHelp home page GithubHelp logo

ascoders / react-native-image-viewer Goto Github PK

View Code? Open in Web Editor NEW
2.4K 23.0 578.0 2.44 MB

🚀 tiny & fast lib for react native image viewer pan and zoom

License: MIT License

TypeScript 100.00%
react-native image-viewer react-component

react-native-image-viewer's Introduction

Show Cases

Swiper image

Zoom while sliding

Swipe down

Getting Started

Installation

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

Basic Usage

  • Install create-react-native-app first
$ npm install -g create-react-native-app
  • Initialization of a react-native project
$ create-react-native-app AwesomeProject
  • Then, edit AwesomeProject/App.js, like this:
import { Modal } from 'react-native';
import ImageViewer from 'react-native-image-zoom-viewer';

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

    // width: number
    // height: number
    // Optional, if you know the image size, you can set the optimization performance

    // You can pass props to <Image />.
    props: {
        // headers: ...
    }
}, {
    url: '',
    props: {
        // Or you can set source directory.
        source: require('../background.png')
    }
}]

export default class App extends React.Component {
    render: function() {
        return (
            <Modal visible={true} transparent={true}>
                <ImageViewer imageUrls={images}/>
            </Modal>
        )
    }
}

Props

parameter type required description default
imageUrls array yes Image Source
enableImageZoom boolean no Enable image zoom true
onShowModal function

(content?: JSX.Element) => void
no The callback for show modal () => {}
onCancel function

() => void
no The callback for cancel modal () => {}
flipThreshold number no Swipe threshold of the next page 80
maxOverflow number no The X position maximum, that current page can slide to the next page 300
index number no Init index of images 0
failImageSource string, object

{url: string}
no placeholder for fail ''
loadingRender function

() => React.ReactElement<any>
no placeholder for loading () => null
onSaveToCamera function

(index?: number => void
no The callback for save to camera () => {}
onChange function

(index?: number => void
no When the image changed () => {}
onMove ( position: IOnMove )=>void reports movement position data (helpful to build overlays) ()=> {}
saveToLocalByLongPress boolean no Enable save to camera when long press true
onClick function

(onCancel?: function) => void
no Onclick (onCancel) => {onCancel()}
onDoubleClick function

(onCancel?: function) => void
no OnDoubleClick (onCancel) => {onCancel()}
onSave function

(url: string) => void
no The picture is saved to the local method, if you write this method will not call the system default method for Android does not support saveToCameraRoll remote picture, you can call this callback in Android call native interface
renderHeader function

(currentIndex?: number) => React.ReactElement<any>
no Custom header () => null
renderFooter function

(currentIndex?: number) => React.ReactElement<any>
no Custom footer () => null
renderIndicator function

(currentIndex?: number, allSize?) => React.ReactElement<any>: number
no Custom indicator (currentIndex, allSize) => currentIndex + "/" + allSize
renderImage function

(props: any) => React.ReactElement<any>
no Custom image component (props) => <Image {...props} />
renderArrowLeft function

() => React.ReactElement<any>
no Custom left arrow () => null
renderArrowRight function

() => React.ReactElement<any>
no Custom right arrow () => null
onSwipeDown function

() => void
no Callback for swipe down () => null
footerContainerStyle object

{someStyle: someValue}
no custom style props for container that will be holding your footer that you pass bottom: 0, position: "absolute", zIndex: 9999
backgroundColor string

white
no Component background color black
enableSwipeDown boolean no Enable swipe down to close image viewer. When swipe down, will trigger onCancel. false
swipeDownThreshold number no Threshold for firing swipe down function
doubleClickInterval number no Double click interval.
pageAnimateTime number no Set the animation time for page flipping. 100
enablePreload boolean no Preload the next image false
useNativeDriver boolean no Whether to animate using useNativeDriver false
menus function

({cancel,saveToLocal}) => React.ReactElement<any>
no Custom menus, with 2 methods:cancel to hide menus and saveToLocal to save image to camera
menuContext object

{someKey: someValue}
no Custom menu context. { saveToLocal: 'save to the album', cancel: 'cancel' }

Development pattern

Step 1, run TS listener

After clone this repo, then:

npm install
npm start

Step 2, run demo

cd demo
npm install
npm start

Then, scan the QR, use your expo app.

Dependence

Depend on react-native-image-pan-zoom: https://github.com/ascoders/react-native-image-zoom

react-native-image-viewer's People

Contributors

1uokun avatar alexiri avatar alvinmatias69 avatar andrew avatar artemkolichenkov avatar ascoders avatar aterribili avatar beilunyang avatar bolandrm avatar bradsolves avatar corygibbons avatar diskonekted avatar fgreinus avatar huangming1994 avatar jakewtaylor avatar jimbomaniak avatar julianapinheiro avatar labithiotis avatar nbolender avatar ovi avatar petertravelchime avatar pppluto avatar pt7892 avatar radeno avatar sanqi avatar shayanjavadi avatar sunkibaek avatar timothystewart6 avatar tomhicks avatar yunkaiwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-image-viewer's Issues

IOS放大图片,用力滑动到下一页有BUG。

安卓没有弹性滚动,IOS有就会出现这个BUG。把图片放大。用力滑动,一直显示loading加载

调试发现image-pan-zoom组件里面的horizontalWholeOuterCounter值是0导致不调用handleHorizontalOuterRangeOffset
我现在直接把handleResponderRelease回调里面给 if (vx > 0.7) {if (vx < -0.7) {加上handleHorizontalOuterRangeOffset回调解决

Failed prop type: invalid prop 'source' supplied to 'Image' when displaying local image

Hi @ascoders, I have been using your dependency for some time. Today, I needed to use it for displaying local images. I upgraded to the latest version of your project. A problem appeared.

When I display the image, there is a warning that goes: Failed prop type: invalid prop 'source' supplied to 'Image'. Then the modal is fully black (no image is shown). However, the weird thing that happens is that when I start scrolling it to the right, and scroll back to left, the image appears. My image array object is something like that :

[{url: "file:///storage/emulated/0/DCIM/Camera/20170531_180343.jpg"}, {url: ...}]

Your help is much appreciated!

Seems the module doesn't work out of the box?

I have just followed the instruction from readme but getting the following error:


Warning: Failed prop type: Invalid prop `source` supplied to `Image`.
    in Image (created by ImageViewer)
    in ImageViewer (created by Transmit)
    in Transmit (created by myproject)
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer (created by Modal)
    in RCTView (created by View)
    in View (created by Modal)
    in RCTModalHostView (created by Modal)
    in Modal (created by myproject)
    in myproject
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer


RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL)

Is that because my react version is too new? I have tried with 0.39 and 0.41, both failing. Thanks in advance

Make it simple to build the project on a fresh clone = higher chance of contributions

I want to contribute to the project and as I'm not previously familiar with typescript, installing the correct tools and type definitions was the initial hurdle. Just being able to do an npm install and then something like npm run build would be awesome.

I figured tsc index.ts --jsx react --experimentalDecorators seems to do the trick when building, provided you have typescript installed?

I guess something like

 "devDependencies": {
    "@types/react": "^0.14.37",
    "@types/react-native": "^0.29.35"
  }

should be in package.json ?

Then I got stuck on the following:

======== Module name 'global' was not resolved. ========
image-viewer/image-viewer.component.tsx(7,29): error TS2307: Cannot find module '../../auto-bind/index'.
image-viewer/image-viewer.component.tsx(8,37): error TS2307: Cannot find module '../../transmit-transparently/index'.
image-viewer/image-viewer.component.tsx(9,23): error TS2307: Cannot find module '../../image-zoom/index'.
image-viewer/image-viewer.component.tsx(81,36): error TS2339: Property 'assign' does not exist on type 'ObjectConstructor'.

are the modules auto-bind, transmit-transparently and image-zoom something you have on your local file system ? Could these use npm packages instead ? And the ObjectConstructor error I have no idea what to do about.

Thanks!

OnLayout bug

After changing orientation my images still shows not aligned to center
screen shot 2017-04-24 at 11 24 39 am

After several swipes my images concating to one screen.
screen shot 2017-04-24 at 11 27 03 am

can't display image chose from photo gallery for Android

This functionary is work well for IOS, but Android doesn't.

The relative code as below:

        if (Platform.OS === 'ios') {
           source = {uri: response.uri.replace('file://', ''), isStatic: true};
        } else {
           source = {uri: response.uri, isStatic: true};
        }

Zooming does not load full resolution image

If I have a large resolution image, when I zoom in the image just seems to be scaled up rather than being able to zoom all the way in to the image, I end up with just seeing a blurry image.

Does this component support zooming and letting the user see the higher resolution version of the image as they zoom, vs. just scaling the image from some reduced size?

How I can localize phrases in getMenu?

I already try to pass menuContext with english labels but without any results

<ImageViewer
            menuContext={{
              saveToLocal: 'Save To Local',
              cancel: 'Cancel',
            }}
            imageUrls={post.images.map(url => ({
              url: getImage(url, DOUBLE_WINDOW_WIDTH, DOUBLE_WINDOW_WIDTH, false),
            }))}
          />

Index problem

Hey man, started using your lib but when I want to manually change the index, it generates an error on swipe to the next or previous image.
I'm doing it like this:

<ImageViewer
    imageUrls={this.props.images}
    style={styles.ImageViewer}
    index={this.state.index}
>

for ios only???

This error is caused by a @providesModule declaration with the same name across two different files.

图片加载失败,导致无法继续

如果中间有一张图片加载失败后. 会去加载默认图片.这个时候.无法继续查看下一张图片.上一张图片也无法查看.导致界面卡死.

Configurable UI

Hi,

it would be nice if the UI could be configurable. Is would suggest allowing for a few additional render methods to the component:

  • renderHeader
  • renderFooter
  • renderIndicator: (currentIndex) => {...} renders the element that is now 1/3 but allows rendering customized versions, e.g. the common method of using little round icons. Commonly, I would expect this below the swipeable view.
  • renderArrowLeft: I would expect to be able to supply components that when clicked animates to the next photo
  • renderArrowRight

Given all these elements that people may want to customize, I would suggest almost to leave the whole modal part out of it and just supply the swipeable zoom view.

Android index有问题


screenshot_20170316-181957
screenshot_20170316-181944
如图,一共三幅图,点击第三个,第一个加载不出来
但是我点击第一个,1、2、3可以加载出来,4和5加载不出来

补充:貌似图片比较大才会出现这个bug

Pass index

Hello.
Can you add pass index current image to renderHeader and renderFooter.
Thank you.

Does not work with images from API

Hi!
Is it just me or is this not working with images fetched from an API?

<Modal visible={true} transparent={true}>
     <ImageViewer imageUrls={{ uri: `URL/${item.Ficheiro}` }}/>
</Modal>

this doesn't seem to work...

EDIT: I had to map the data into an URL of objects within render. Now it works.

加载本地图片失败

我使用本地图片加载时报错(安卓,格式为file:///sdcard/xxx.jpg)

跟踪调试时发现是因为没有判断是否为本地文件,统一调用了Image.prefetch:
const prefetchImagePromise = Image.prefetch(image.url)
能否在这里加个判断呢,如果是本地文件就success(或者判断文件存在再success)

PS:因为typescript还没用过,也不知道该怎么重新编译,束手无措。。

调用ImageViewer出错

把imageUrls设为

imageUrls=[
{url: "https://bbs.byr.cn/open/attachment/Friends/1791246/851?oauth_token=43c59a14fd5eb4ce3e5565ad627d871e"},
{url: "https://bbs.byr.cn/open/attachment/Friends/1791246/91397?oauth_token=43c59a14fd5eb4ce3e5565ad627d871e"}]

报错:
cannot read property 'originSizeKb' of undefined

图片无法加载1.2.27

你好, 更新到1.2.27版本之后图片不显示了.一直显示loading
测试代码:

const images = [{
            url: 'http://scimg.jb51.net/allimg/160815/103-160Q509544OC.jpg'
        }, {
            url: 'http://img.sc115.com/uploads1/sc/jpgs/1508/apic22412_sc115.com.jpg'
        }, {
            url: 'http://v1.qzone.cc/avatar/201407/07/00/24/53b9782c444ca987.jpg!200x200.jpg'
        }];
<ImageViewer imageUrls={images} saveToLocalByLongPress={false} loadingRender={()=>{
                        return <ActivityIndicator animating={true} style={{justifyContent: 'center',alignItems: 'center',}} size={'large'} color="#3D95D6"/>
                    }} failImageSource={{uri:'https://gss0.baidu.com/9vo3dSag_xI4khGko9WTAnF6hhy/zhidao/wh%3D600%2C800/sign=4c1580d505087bf47db95fefc2e37b14/aa18972bd40735fab74df12799510fb30e2408ea.jpg'}}/>

[Feature request] Needs image caching

@ascoders ,
This plugin was good. I'm using it in my project.
The only thing I want to suggest is the image caching.

For now, it keeps reloading the image every time the modal is open. That caused a long time of black screen waiting for the image to load. It's extremely bad when loading a large image.

Can you please add image caching in the next release?
Thanks.

Local images

Hi,
Great library!
I have noticed a new update to support local image and I am trying to use it.
Tried with the 'file:' + sourcePath but didn't manage to make it work.

Tried to do this:
const images = [{
url: 'file:../images/IMG.JPG'
}]

Is it possible ?
Thanks,

Ahikam

更新到最新版本以后,确实图片显示不出,android一直闪动

1.2.24版本是可以显示出图片的,更新到1.2.25以后不行. 我更新1.2.25的原因是因为好像动态设置index以后,无法显示图片,

<ImageViewer visible={true}
saveToLocalByLongPress={false}
onClick={this.backFullScreen}
loadingRender={() => {
return (

<View style={[styles.loading, { width: deviceWidth }]}>

数据加载中...


)
} }
imageUrls={this.state.images} />

一直出现进度条,没有出现图片

invaild prop 'source' supplied to 'Image'

我传给imageUrls里的url放的是base64的图片数据,然后显示就提示Invaild prop 'source' supplied to 'Image',并且源码里的imageInfo的status总是fail,不知道在url上是不是有什么限制,还是通过什么方式可以解决

安卓网络图片存储本机问题

On Android, the tag must be a local image or video URI, such as "file:///sdcard/img.png"
看你直接把http.....传进去进去了
应该是这个问题吧?

图片变模糊了

使用imageviewer后打开图片,感觉图片变模糊了,求解?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.