Skip to content

Commit

Permalink
Fix focal point picker drag handle jump
Browse files Browse the repository at this point in the history
Replace `setOffset` with `extractOffset` as it accomplishes the intended
goal directly. It also helps avoid a jump that occurs when the tooltip
is dismissing while interacting with the drag handle.
  • Loading branch information
shadow351 committed Oct 25, 2020
1 parent 26fabf6 commit a1c78d2
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/components/src/focal-point-picker/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ function FocalPointPicker( props ) {
const pan = useRef( new Animated.ValueXY() ).current;

// Set initial cursor poition
if ( containerSize ) {
pan.setValue( {
x: focalPoint.x * containerSize.width,
y: focalPoint.y * containerSize.height,
} );
}
useEffect( () => {
if ( containerSize ) {
pan.setValue( {
x: focalPoint.x * containerSize.width,
y: focalPoint.y * containerSize.height,
} );
}
}, [ focalPoint, containerSize ] );

const panResponder = useMemo(
() =>
Expand All @@ -73,8 +75,8 @@ function FocalPointPicker( props ) {
onPanResponderGrant: ( event ) => {
shouldEnableBottomSheetScroll( false );
const { locationX: x, locationY: y } = event.nativeEvent;
pan.setValue( { x, y } ); // Set cursor to tap origin
pan.setOffset( { x: pan.x._value, y: pan.y._value } );
pan.setValue( { x, y } ); // Set cursor to tap location
pan.extractOffset(); // Set offset to current value
},
// Move cursor to match delta drag
onPanResponderMove: Animated.event( [
Expand All @@ -83,7 +85,7 @@ function FocalPointPicker( props ) {
] ),
onPanResponderRelease: ( event ) => {
shouldEnableBottomSheetScroll( true );
pan.flattenOffset();
pan.flattenOffset(); // Flatten offset into value
const { locationX: x, locationY: y } = event.nativeEvent;
setPosition( {
x: x / containerSize?.width,
Expand Down

0 comments on commit a1c78d2

Please sign in to comment.