alwx / react-native-photo-view

Pinch-to-zoom view for React Native (both iOS and Android)
MIT License
816 stars 435 forks source link

Does not work with Rotation: Axis point gets lost on rotation update #72

Closed facuescobar closed 2 years ago

facuescobar commented 7 years ago

Hi!

The axis gets lost after rotation

My app is locked on portrait, but I have an image slider component where images can go to landscape. I've added PhotoView to my project, and everything goes well if the orientation doesn't change but when I change the orientation, the photo view component gets a wrong axis.

Initial load looks good, I can zoom in/out

screenshot 2017-07-18 14 34 55

But, if the image scale is different than 1 and orientation change, the next render will look like this, on portrait or landscape.

screenshot 2017-07-18 14 28 29
   //Returns screen bounds based on orientation 
   // switch width and height values if orientation===landscape) if not, returns bounds width and height as it is
    const screenBounds = getImageBounds(
      orientation, bounds.width, bounds.height
    );

    //Returns scaled image size 
    const imageScale = scaleImage(
      screenBounds.width, screenBounds.height,
      image.width, image.height
    );

    //Degrees to rotate
    const rotation = this.animation.interpolate({
      inputRange: [0, 360],
      outputRange: ['0deg', '360deg'],
    });

    const viewStyles = {
      width: screenBounds.width,
      height: screenBounds.height,
      transform: [
        {
          rotate: rotation,
        },
      ],
    };

    const imageStyles = {
      width: imageScale.width,
      height: imageScale.height,
    };

    return (
      <Animated.View
        style={viewStyles}
      >
        <PhotoView
          source={{
            uri: this.props.image.url,
          }}
          minimumZoomScale={1}
          maximumZoomScale={3}
          androidScaleType='fitCenter'
          style={imageStyles}
        />
      </Animated.View>
    );
stevenleeg commented 6 years ago

Has anyone found a workaround for this issue? I'm also running into it and am not entirely sure how to fix it.

filipmadej commented 5 years ago

+1

vbanurag commented 4 years ago

+1