Skip to content

Commit

Permalink
Fix for scale
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottkember committed Feb 24, 2024
1 parent 1b3f05b commit be1c037
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 16 deletions.
22 changes: 18 additions & 4 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.

23 changes: 18 additions & 5 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.

27 changes: 22 additions & 5 deletions src/ReactNativeZoomableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import {
calcNewScaledOffsetForZoomCentering,
} from './helper';
import { applyPanBoundariesToOffset } from './helper/applyPanBoundariesToOffset';
import { viewportPositionToImagePosition } from './helper/coordinateConversion';
import {
applyContainResizeMode,
viewportPositionToImagePosition,
} from './helper/coordinateConversion';
import { StaticPin } from './components/StaticPin';
import { debounce } from 'lodash';
import {
Expand Down Expand Up @@ -903,11 +906,25 @@ class ReactNativeZoomableView extends Component<
};

moveStaticPinTo = (position: Vec2D) => {
const zoomableEvent = this._getZoomableViewEventObject();
const imageSize = {
height: this.props.contentHeight,
width: this.props.contentWidth,
};

const { scale } =
applyContainResizeMode(imageSize, {
width: zoomableEvent.originalWidth,
height: zoomableEvent.originalHeight,
}) || {};

const toValue = {
x: this.props.staticPinPosition.x - position.x * scale,
y: this.props.staticPinPosition.y - position.y * scale,
};

Animated.timing(this.panAnim, {
toValue: {
x: this.props.staticPinPosition.x - position.x / this.zoomLevel,
y: this.props.staticPinPosition.y - position.y / this.zoomLevel,
},
toValue,
useNativeDriver: true,
duration: 200,
}).start(() => {
Expand Down

0 comments on commit be1c037

Please sign in to comment.