Skip to content

Commit

Permalink
Merge pull request #124 from openspacelabs/elliott/animate-move-stati…
Browse files Browse the repository at this point in the history
…c-pin-to

Skip re-renders by checking numbers
  • Loading branch information
elliottkember authored Dec 27, 2024
2 parents 6962122 + 14605fb commit af7ce8a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
15 changes: 13 additions & 2 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.

15 changes: 13 additions & 2 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.

17 changes: 16 additions & 1 deletion src/ReactNativeZoomableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ class ReactNativeZoomableView extends Component<
// to avoid messing up calculations, especially ones that are done right after
// the component transitions from hidden to visible.
if (!x && !y && !width && !height) return;

// If these values are all the same, don't re-set them in state
// this way we don't re-render
if (
this.state.originalWidth === width &&
this.state.originalHeight === height &&
this.state.originalPageX === x &&
this.state.originalPageY === y
) {
return;
}

this.setState({
originalWidth: width,
originalHeight: height,
Expand Down Expand Up @@ -1198,7 +1210,10 @@ class ReactNativeZoomableView extends Component<
style={styles.container}
{...this.gestureHandlers.panHandlers}
ref={this.zoomSubjectWrapperRef}
onLayout={this.grabZoomSubjectOriginalMeasurements}
onLayout={(event) => {
this.props.onLayout?.(event);
this.grabZoomSubjectOriginalMeasurements();
}}
>
<Animated.View
style={[
Expand Down

0 comments on commit af7ce8a

Please sign in to comment.