openspacelabs / react-native-zoomable-view

A view component for react-native with pinch to zoom, tap to move and double tap to zoom capability.
MIT License
210 stars 58 forks source link

Zoom location incorrect if pinch zoom in corner early #89

Open wilkinsonj opened 8 months ago

wilkinsonj commented 8 months ago

Hey,

The method of setting the 'originalWidth' and 'originalHeight' runs on a setTimeout (which incidentally also runs continuously when a zoom view is loaded). The method is called grabZoomSubjectOriginalMeasurements

For the first couple of timeouts, the original width and original height are being set to 0, which has the effect of throwing out the zoom when you pinch from a corner within the first couple of seconds.

Since I am running this in full screen, I removed the timeout and changed the method to the following:

  private grabZoomSubjectOriginalMeasurements = () => {
    this.setState({
      originalWidth: Dimensions.get('window').width,
      originalHeight: Dimensions.get('window').height,
      originalPageX: 0,
      originalPageY: 0,
    });
  };

This solves the problem completely for my use case.

However, a better approach is needed. One nicer way would be to accept the originalWidth, originalHeight, x and y as parameters, and if so, don't run the timeout.

elliottkember commented 8 months ago

This looks interesting. I'm particularly interested in the setTimeout running continuously as well – that doesn't seem right. Would you be open to collaborating on a PR to fix this?