-
Notifications
You must be signed in to change notification settings - Fork 62
Convert to functional component #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: thomas/strip-features
Are you sure you want to change the base?
Conversation
| this.gestureType = null; | ||
| } | ||
|
|
||
| componentDidUpdate( |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
elliottkember
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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
ReactNativeZoomableViewfrom a class to a hooks-based functional component while keeping behavior and public APIs intact.useState/useRefand lifecycle withuseLayoutEffect/useEffect; wiresPanResponderhandlers via refszoomTo,zoomBy,moveTo,moveBy,moveStaticPinTo,gestureStarted) viauseImperativeHandlelodash.defaults; usesuseLatestCallbackand a debouncedonStaticPinPositionChangecalcGestureCenterPoint/calcGestureTouchDistancenow returnundefinedinstead ofnullfor invalid statesWritten by Cursor Bugbot for commit e1eae6a. Configure here.