Skip to content

Conversation

@thomasttvo
Copy link
Collaborator

@thomasttvo thomasttvo commented Dec 23, 2025

This PR aims to perform this conversion while minimizing the diff as much as possible. This means we're sacrificing code styling in some areas to prioritize keeping the diff small.

The end goal of this PR is to set the stage for the ultimate conversion to reanimated. There's a high chance the changes here are not released, but only served as a transitional stepping stone.

Tested and verified pinch/pan/staticPin behaviors to work fine.


Note

Refactors ReactNativeZoomableView from a class to a hooks-based functional component while keeping behavior and public APIs intact.

  • Replaces class state/fields with useState/useRef and lifecycle with useLayoutEffect/useEffect; wires PanResponder handlers via refs
  • Exposes the same imperative API (zoomTo, zoomBy, moveTo, moveBy, moveStaticPinTo, gestureStarted) via useImperativeHandle
  • Centralizes prop defaults with lodash.defaults; uses useLatestCallback and a debounced onStaticPinPositionChange
  • Maintains pan/zoom animations and gesture logic; minor tweaks to tap/long-press handling and measurement interval
  • Helper calcGestureCenterPoint/calcGestureTouchDistance now return undefined instead of null for invalid states

Written by Cursor Bugbot for commit e1eae6a. Configure here.

this.gestureType = null;
}

componentDidUpdate(
Copy link
Collaborator Author

@thomasttvo thomasttvo Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is now split into 3 layout effects, each check for a specific set of changes

prevState: ReactNativeZoomableViewState
) {
const { zoomEnabled, initialZoom } = this.props;
if (prevProps.zoomEnabled && !zoomEnabled && initialZoom) {
Copy link
Collaborator Author

@thomasttvo thomasttvo Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of checking prevProps and prevState, we create deps arrays for the layout effects that contain only the changes we're trying to watch. For example the equivalent effect for this block has a deps array that contains only zoomEnabled. initialZoom is assigned to and referenced from a ref because it's not being watched for changes


useLayoutEffect(() => {
gestureHandlers.current = PanResponder.create({
onStartShouldSetPanResponder: _handleStartShouldSetPanResponder,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all functions are wrapped in a useLatestCallback so they don't trigger reevaluation of the effects, keeping the original behavior consistent

this.state.originalWidth === width &&
this.state.originalHeight === height &&
this.state.originalPageX === pageX &&
this.state.originalPageY === pageY
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this if block is totally redundant - my bad, react is capable of checking individual state variables for updates

Copy link
Collaborator

@elliottkember elliottkember left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasttvo thomasttvo added the enhancement New feature or request label Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants