Giter Site home page Giter Site logo

react-native-image-zoom's Introduction

Show Cases

All Contributors

Zoom while sliding

3.gif

Intelligent zoom

2.gif

Getting Started

Installation

npm i react-native-image-pan-zoom --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 { Image, Dimensions } from 'react-native';
import ImageZoom from 'react-native-image-pan-zoom';

export default class App extends React.Component {
    render: function() {
        return (
            <ImageZoom cropWidth={Dimensions.get('window').width}
                       cropHeight={Dimensions.get('window').height}
                       imageWidth={200}
                       imageHeight={200}>
                <Image style={{width:200, height:200}}
                       source={{uri:'http://v1.qzone.cc/avatar/201407/07/00/24/53b9782c444ca987.jpg!200x200.jpg'}}/>
            </ImageZoom>
        )
    }
}

Document

Props Type Description DefaultValue
cropWidth(required) number operating area width 100
cropHeight(required) number operating area height 100
imageWidth(required) number picture width 100
imageHeight(required) number picture height 100
onClick (eventParams: IOnClick)=>void onClick ()=>{}
onDoubleClick (eventParams: IOnClick)=>void onDoubleClick ()=>{}
panToMove boolean allow to move picture with one finger true
pinchToZoom boolean allow scale with two fingers true
clickDistance number how many finger movement can also trigger onClick 10
horizontalOuterRangeOffset (offsetX?: number)=>void horizontal beyond the distance, the parent to do picture switching, you can listen to this function. When this function is triggered, you can do the switch operation ()=>{}
onDragLeft ()=>void trigger to switch to the left of the graph, the left sliding speed exceeds the threshold when triggered ()=>{}
responderRelease (vx: number)=>void let go but do not cancel ()=>{}
maxOverflow number maximum sliding threshold 100
longPressTime number long press threshold 800
onLongPress (eventParams: IOnClick)=>void on longPress ()=> {}
doubleClickInterval number time allocated for second click to be considered as doublClick event 175
onMove ( position: IOnMove )=>void reports movement position data (helpful to build overlays) ()=> {}
centerOn { x: number, y: number, scale: number, duration: number } if given this will cause the map to pan and zoom to the desired location undefined
enableSwipeDown boolean for enabling vertical movement if user doesn't want it false
enableCenterFocus boolean for disabling focus on image center if user doesn't want it true
onSwipeDown () => void function that fires when user swipes down null
swipeDownThreshold number threshold for firing swipe down function 230
minScale number minimum zoom scale 0.6
maxScale number maximum zoom scale 10
useNativeDriver boolean Whether to animate using useNativeDriver false
onStartShouldSetPanResponder () => boolean Override onStartShouldSetPanResponder behavior () => true
onMoveShouldSetPanResponder () => boolean Override onMoveShouldSetPanResponder behavior undefined
onPanResponderTerminationRequest () => boolean Override onMoveShouldSetPanResponder behavior () => false
useHardwareTextureAndroid boolean for disabling rendering to hardware texture on Android true
Method params Description
reset Reset the position and the scale of the image
resetScale Reset the scale of the image
centerOn ICenterOn Centers the image in the position indicated. ICenterOn={ x: number, y: number, scale: number, duration: number }

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.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Darius

💻

Thomas P.

💻

Juan Di Toro

💻

Alhaytham Elhassan

💻

Alexander Pataridze

💻

Peter Xu

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

react-native-image-zoom's People

Contributors

a-r-d avatar alexandrius avatar allcontributors[bot] avatar artemkolichenkov avatar ascoders avatar badismeddouri avatar beilunyang avatar brycehanscomb avatar chinloongtan avatar dependabot[bot] avatar ditorodev avatar esa2012 avatar h3l1o5 avatar kyonru avatar marconett avatar markdaws avatar petertravelchime avatar sunkibaek avatar tomhicks avatar zhang740 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

react-native-image-zoom's Issues

Error: in this environment the sources for assign MUST be an object. This error is a performance optimization and not spec compliant.

I'm getting the following error when using ImageZoom, any idea what might be causing this?

iphone 6 - 11 4 2018-06-13 11-24-05

The code we're using is pretty straight forward:

<ImageZoom
    style={styles.imageContainer}
    cropWidth={Dimensions.get("window").width}
    cropHeight={Dimensions.get("window").height}
    imageWidth={Dimensions.get("window").width}
    imageHeight={240}
>
    <Image
        style={styles.image}
        source={imgSrc}
    />
</ImageZoom>

Image recenters after dragging

The image recenters when I'm done dragging. If I zoom in and drag then it works as expected. This happens on both android and ios.

My code:

<ImageZoom
  cropWidth={getWinWidth()}
  cropHeight={getWinHeight()}
  imageWidth={1743}
  imageHeight={980}
>
  <Image
    style={{ width: 1743, height: 980 }}
    source={require('src/assets/images/map.png')}
  />
</ImageZoom>

No scaling on swipe down?

Is it possible to not scale the image on swipedown? I feel like it looks better if the image is just dragged down a certain distance without being scaled down at the same time to e.g. close the modal.

install issue

thanks for your smart library, I find that npm warn be throwed after install it like below image show.

wechatimg107

Is it necessary to care about this warn message?

version
react-native 0.44
react 16.0.0-alpha.6

thanks for your time,

regards

Can't pan on initial load, how to see all of the image on load

I have the following code, cropWidth/cropHeight are set to the size of the screen:

  let cropWidth = 375
  let cropHeight = 667

  let imageWidth = 3401
  let imageHeight = 1603

  imageViewer = (
    <ImageZoom
      cropWidth={cropWidth}
      cropHeight={cropHeight}
      imageWidth={imageWidth}
      imageHeight={imageHeight}
    >
      <Image
        source={{ uri: image.url }}
        //resizeMode="contain"
        style={{
          width: imageWidth,
          height: imageHeight,
        }}
      />
    </ImageZoom>

When the image loads it is at some zoom level, centered on the middle of the image, but I can't see the whole image and can't pan at all, it just jumps back to the middle as I try to pan. If I zoom in a little bit then it will let me pan around.

How can I get the whole image to be visible on load? I tried setting resizeMode="contain" on the image but that didn't do anything?

Compilation issue

Hi all,

I am using RN 55 and @types/react-native version 0.55.13 and while compilation I am having this issue:

When I use this library I am having
node_modules/react-native-image-pan-zoom/src/image-zoom/image-zoom.component.tsx:17:92 - error TS2339: Property userAgent does not exist on type Navigator. 17 return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);

any thoughts?

panToMove not working

@ascoders Unfortunately, setting panToMove is doing nothing and I'm unable to pan the image.

// component
<ImageZoom
    style={styles.imageZoomer}
    imageWidth={Dimensions.get('window').width}
    imageHeight={Dimensions.get('window').height}
    panToMove={true}
    cropWidth={Dimensions.get('window').width}
    cropHeight={Dimensions.get('window').height} >
        <Image
            style={styles.image}
            source={{uri: this.props.image}}
            resizeMode='contain' />
</ImageZoom>

// styles
image: {
    flex: 1
},
ImageZoomer: {
    flex: 1
}

Built-in image size management feasible?

Wouldn't it make sense to provide the component with the capabilities to just show an image in contain mode without having to specify its size, and have it initially just match the container's size? That would probably the case in 95+ % of all cases, not?

How to get the position of zoomed portion of image.

I have tried for getting the position of zoomed portion of an image using the onMove props. I got a position object after every pan. I couldn't understand how will the position object change during each pan move. Is it possible to get the exact position of the area using this object or any other suggestion to get the position?

How to remove Image Bounce effect during pan

Hi,

I tried the component and the zoom is working perfect for me however when I try to pan the image it has a bounce back effect when the mouse is released (on the emulator). I have not yet tried this on a physical device, but I guess that the bounce effect would be similar on the device as well. Could you kindly let me know if there is a way to disable this bounce effect on pan?
I have set the panToMove prop to true.

Thanks and Regards
Satyen Velankar

Does not zoom to centre of touches

When zooming I was expecting it to zoom to the point where I am pinch zooming. But it zooms to the images 0,0. I have spent quite a bit of time trying to get this to work without success. Any ideas anyone?

Weird behavior with image

I'm working on an app and there are 3 images that, by any reason, doesn't work properly.
Those were just sample images I picked and to my surprise, they don't work properly.
I checked the image size and it's all right. There are other images that are working just fine.

The images are minified, not sure if it changes anything. The images start zoomed and if I try to zoom in or out, it gets back to the initial size (will send a video later)

error_cable_1
error_cable_2
error_miriam

The code in use:

          <ImageZoom cropWidth={width} cropHeight={height} imageWidth={original_w} imageHeight={original_h}>
            <Image style={{width: original_w, height: original_h}} source={{uri: publicMainUrl}} />
          </ImageZoom>

width and height are the device sizes. original_w and original_h are properly set based on the image sizes.

OnPress XY Coordinates

Hi,

Probably not an issue, but I was wondering, is there a way to get the image XY coordinates for an onPress event?

Best,
Elad

Can't pan without zooming.

When an image is loaded initially with a scale of 1, if you try panning it will just jump back to the middle of the photo. If you zoom in at all it will allow you to pan as expected.
centerOn={{
x: 0,
y: 0,
scale: 1.01,
duration: 100
}}
works as a workaround, but if you reset the image with a double press you will no longer be able to pan again.

Can you reset the zoom?

Can you reset the zoom on this? I have a component which loads full-resolution images, when clicked from a slideshow, if I click an image, then zoom in, then click another image, the zoom level remains, thus I have come to the question, can I reset the zoom level? So that in my example, once a new image is loaded into the view, I can reset the zoom level.

android scroll is not smoth?

I have a flat list. Inside of that flat list I have added the image zoom view. This is working perfectly in iOS. where as in android when I tried to swipe the page to view the next image the view get stuck.

I have to do lot of swipe to actually swipe the image. I feel that in android the scroll is not smooth.

Please let me know how to add the smooth scroll to view.

建议加一个缩放的回调方法

如题,建议加一个缩放的回调或者在responderRelease里把当前scale值加上,但是responderRelease需要在onPanResponderRelease的最后面调用,这样scale就是最终值了。

Build errors with TypeScript 2.4.2

When using TS 2.4.2 the project is not working anymore. This is because of this type of error:

node_modules/react-native-image-pan-zoom/image-zoom/image-zoom.component.tsx(454,19): error TS2322: Type '{ onStartShouldSetResponder?: (event: GestureResponderEvent) => boolean; onMoveShouldSetResponder...' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<ViewProperties, ComponentState>> & Reado...'.
  Type '{ onStartShouldSetResponder?: (event: GestureResponderEvent) => boolean; onMoveShouldSetResponder...' is not assignable to type 'Readonly<ViewProperties>'.
    Types of property 'style' are incompatible.
      Type 'ViewStyle[]' has no properties in common with type 'ViewStyle'

This because appending two styles in an array does not work with newer versions of typescript.

For example, this does not work:
<View style={[{ width: this.props.cropWidth, height: this.props.cropHeight}]} {...this.imagePanResponder.panHandlers}>
But this works:
<View style={Object.assign({}, styles.container, { width: this.props.cropWidth, height: this.props.cropHeight })} {...this.imagePanResponder.panHandlers}>

Tab Bar Obscures Zoomed Image

I've tried a few different things to try to 'push up' the zoomed image, but nothing is working. When you zoom in to an image, the display cannot be panned to the very bottom. If you try to scroll to the bottom, it immediately jumps back up, and the bottom of the image is hidden by the tab bar (react-navigation). Is there a way to make sure that the zoomable content is confined to above the tab bar?

How to get if My image is back on scale factor 1

As a user, If I double tap on image to scale it, by default I am getting result where image is scaled by 2. (scale : 2)
Now if i want to get this value in code, using onMove I can see scale as 2. Here's the problem is - onMove will only fire if user moves image. If i keep on doing double tap on image, scale factor will be increasing to 2 and coming back to 1. This process will keep going, but there is no way (or unfortunately I am not able find) to get scale (scaling factor) in this scenario.

Purpose - I wanted to show / hide some section based on scale factor (If scale 1 - show, otherwise hide)

PS - I know onMove gives scale but it will only trigger if user moves image, keep on double tap on image does not trigger it, scenario mentioned above)

PLEASE HELP!!!!

Scale prop?

Hello, i want to be able to reset the scale on call. How could i do this? Just like when double clicked it goes back to full scale.

放大图片之后, 滑动图片时后面的 flatList 也滑动

问题:

  1. 我做一个图片浏览器, 外层是用的 flatList, flatList 的 item是由react-native-image-zoom包着的控件, 当我放大图片之后, 我想滑动图片看细节, 但是一滑动图片, 后面的 flatList 就滑动了, 有什么办法可以阻止当前的 flatList 滑动吗, 等当前的 图片滑动到边缘之后, 后面的 flatlist再接收到滑动事件, 就像原生一样

Screen Tearing on Pan

Only tested this on iOS so far, but for our use case, we have an ImageBackground with some views overlaid on it, inside the ImageZoom. The zooming works perfectly, but panning causes very apparent screen Tearing, worse the faster the pan (slow enough, not visible/noticeable, but has to be very slow). This was on XR simulator. Can this be avoided?

[Q] Is it possible to change default index programmatically?

I have a Swiper at my screen that shows product images, user swaps and changes the index of the slider, user is seeing third image now (e.g) now clicks on image and as I'm just sending image array to ImageZoom it shows the first image by default, Am I able to pass the index I want to see the third image at ImageZoom?

TS Error when used with

Hi,

the following error occurs in tsc when is noUnusedLocals set to true in tsconfig.json

import * as React from 'react'

node_modules/react-native-image-pan-zoom/image-zoom/image-zoom.type.ts(1,13): error TS6133: 'React' is declared but never used.

I guess the import can be removed.

执行 tsc 的时候出现一个 Error

错误信息:

node_modules/react-native-image-pan-zoom/src/image-zoom/image-zoom.component.tsx:17:92 - error TS2339: Property 'userAgent' does not exist on type 'Navigator'.

image

Example with multiple images

Hello,
Do you have a code example of this component with multiple images, like in the gif you provided? I tried using an <ImageZoom> component with multiple <Image> children but I was not able to swipe to change the current image.
Also, why does the outer component need to know the width and height of the image beforehand? What if I have images of different sizes?
Could you help me with that? I just couldn't find a more suitable option for displaying multiple images, yours seems to be the best one but I'm not sure of how to use it correctly.

Prevent FlatList scrolling while image zoomed

Hi! I have a FlatList with items wrapped to ImageZoom:

<FlatList
     horizontal
     pagingEnabled={true}
     showsHorizontalScrollIndicator={false}

     data={this.props.images}
     renderItem={item => this.renderImage(item)}
/>

And the render image function is:

renderImage = ({item}) => {
    return (
      <View style={{width: SCREEN_WIDTH, height: 'auto'}}>
        <ImageZoom
          cropWidth={Dimensions.get('window').width}
          cropHeight={Dimensions.get('window').height}
          imageWidth={Dimensions.get('window').width}
          imageHeight={'100%'}
        >
          <FastImage
            resizeMode={FastImage.resizeMode.contain}
            source={{uri: item.source.uri, cache: 'force-cache'}}
          />
        </ImageZoom>
      </View>
    )
  }

But as I starting zoom an image, the FlatList trying to scroll to next (or previous) page. How to prevent the FlatList responding to gestures while Image are zooming?

Huge image cannot be reduced

Hi
Image shows up huge and cannot be zoomed out.
The image's size is 3300x1800
Screen is 1242x2208 (iphone 7plus)

      <View style={{ flex: 1 }}>
        {!loadimage && (
          <Spinner />
        )}
        {loadimage && (
          <ImageZoom
            cropWidth={Dimensions.get('window').width}
            cropHeight={Dimensions.get('window').height - 50}
            imageWidth={width}
            imageHeight={height}
          >
            <Image
              style={{ width, height }}
              source={{
                uri: urlImage,
              }}
            />
          </ImageZoom>
        )}
      </View>

What am I doing wrong?
Thanks!

ImageZoom blocks child TouchableOpacity's onPress working

Thanks for your awesome package, it is amazing and so so helpful.
I faced some problems here: when the children of ImageZoom is TouchableOpacity, then the onPress prop is not working at all. I think something blocks its working (PanResponder or something else). Please help to solve the problem. Thnaks

Regards,
David

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.