ascoders / react-native-image-zoom

react native image pan and zoom
MIT License
639 stars 282 forks source link

Can you reset the zoom? #38

Closed fendorio closed 6 years ago

fendorio commented 6 years ago

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.

wangxpert commented 6 years ago

I am also faced with this issue. Did you find out the solution?

ascoders commented 6 years ago

Add unique key for each component?

ongmap commented 6 years ago

Need this feature support in future

ascoders commented 6 years ago

How about this?

someTimes() => {
  this.rnZoom.resetScale()
}

render() {
  return (
    <ReactNativeImageZoom ref={ ref => this.rnZoom = ref }>...</ReactNativeImageZoom>
  )
}
Kyonru commented 6 years ago

As @ascoders said, you can use reset instead of resetScale, this will reset the scale and the position. It would be a good idea to update the docs.

ascoders commented 6 years ago

Fix in #49

braianj commented 4 years ago

Hi, this is not working for me

<ImageZoom
                cropWidth={screenWidth}
                cropHeight={screenWidth}
                imageWidth={screenWidth}
                imageHeight={screenWidth}
                panToMove={false}
                ref={ ref => this.rnZoom = ref }
                key={index}
                responderRelease={ () => {
                   this.rnZoom.resetScale();
                   this.rnZoom.reset();
                }}
            >
               <Image
                   source={{uri: item}}
                   style={styles.image}
                   onError={() => {
                      this.setState({hasError: true})
                   }}
               />
            </ImageZoom>
EKOLX commented 3 years ago

@braianj try this:

import ImageZoom from "react-native-image-pan-zoom";
import ImageViewer from "react-native-image-pan-zoom/built/image-zoom/image-zoom.component";

const imageRef = useRef() as MutableRefObject<ImageViewer>;

const onSomeButtonPress = () => {
    imageRef.current.reset();
  };

<ImageZoom
    ref={imageRef}
    cropWidth={width}
    cropHeight={imageHeight}
    imageWidth={width}
    imageHeight={imageHeight}
>
  {loading && (
    <ActivityIndicator style={StyleSheet.absoluteFill} size="large" />
  )}
  <Image
    style={styles.image}
    source={{ uri: image?.url }}
    onLoad={() => setLoading(false)}
  />
</ImageZoom>