Skip to content

Commit

Permalink
Fixed interaction problem
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottkember committed Feb 25, 2024
1 parent 83bc773 commit 9f63bfd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 57 deletions.
42 changes: 24 additions & 18 deletions lib/commonjs/ReactNativeZoomableView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/commonjs/ReactNativeZoomableView.js.map

Large diffs are not rendered by default.

43 changes: 25 additions & 18 deletions lib/module/ReactNativeZoomableView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/module/ReactNativeZoomableView.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/typescript/ReactNativeZoomableView.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="node" />
import { Component, RefObject } from 'react';
import { GestureResponderEvent, PanResponderGestureState, View } from 'react-native';
import { Vec2D, ReactNativeZoomableViewProps, ReactNativeZoomableViewState, ZoomableViewEvent } from './typings';
Expand Down Expand Up @@ -169,6 +170,7 @@ declare class ReactNativeZoomableView extends Component<ReactNativeZoomableViewP
* @private
*/
private _resolveAndHandleTap;
_moveTimeout: NodeJS.Timeout;
moveStaticPinTo: (position: Vec2D) => void;
private _staticPinPosition;
private _updateStaticPin;
Expand Down
30 changes: 11 additions & 19 deletions src/ReactNativeZoomableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Animated,
Easing,
GestureResponderEvent,
InteractionManager,
PanResponder,
PanResponderGestureState,
StyleSheet,
Expand Down Expand Up @@ -362,7 +361,7 @@ class ReactNativeZoomableView extends Component<
*/
private grabZoomSubjectOriginalMeasurements = () => {
// make sure we measure after animations are complete
InteractionManager.runAfterInteractions(() => {
requestAnimationFrame(() => {
// this setTimeout is here to fix a weird issue on iOS where the measurements are all `0`
// when navigating back (react-navigation stack) from another view
// while closing the keyboard at the same time
Expand All @@ -376,6 +375,7 @@ class ReactNativeZoomableView extends Component<
// we don't wanna measure when zoomSubjectWrapperRef is not yet available or has been unmounted
zoomSubjectWrapperRef.current?.measureInWindow(
(x, y, width, height) => {
console.log({ width, height });
this.setState({
originalWidth: width,
originalHeight: height,
Expand Down Expand Up @@ -902,27 +902,19 @@ class ReactNativeZoomableView extends Component<
}
};

_moveTimeout: NodeJS.Timeout;
moveStaticPinTo = (position: Vec2D) => {
const z = this._getZoomableViewEventObject();

const centreX = z.originalWidth / 2;
const centreY = z.originalHeight / 2;
const { originalWidth, originalHeight } = this.state;
const { staticPinPosition, contentWidth, contentHeight } = this.props;

const offsetX = this.props.staticPinPosition.x - centreX;
const offsetY = this.props.staticPinPosition.y - centreY;
// Offset for the static pin
const pinX = staticPinPosition.x - originalWidth / 2;
const pinY = staticPinPosition.y - originalHeight / 2;

const toValue = {
x: z.originalWidth / 2 - position.x + offsetX / z.zoomLevel,
y: z.originalHeight / 2 - position.y + offsetY / z.zoomLevel,
};
this.offsetX = contentWidth / 2 - position.x + pinX / this.zoomLevel;
this.offsetY = contentHeight / 2 - position.y + pinY / this.zoomLevel;

Animated.timing(this.panAnim, {
toValue,
useNativeDriver: true,
duration: 200,
}).start(() => {
this._updateStaticPin();
});
this.panAnim.setValue({ x: this.offsetX, y: this.offsetY });
};

private _staticPinPosition = () => {
Expand Down

0 comments on commit 9f63bfd

Please sign in to comment.