Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/components/AvatarCropModal/AvatarCropModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {
runOnUI,
interpolate,
useAnimatedGestureHandler,
useSharedValue,
Expand Down Expand Up @@ -281,15 +282,24 @@ const AvatarCropModal = (props) => {
}, [props.imageUri, props.imageName, props.imageType, imageContainerSize]);

/**
* @param {Event} event
* @param {Number} locationX
*/
const sliderOnPress = (event) => {
const sliderOnPress = (locationX) => {
// We are using the worklet directive here and running on the UI thread to ensure the Reanimated
// shared values are updated synchronously, as they update asynchronously on the JS thread.

Comment thread
Ollyws marked this conversation as resolved.
Resolved
'worklet';

if (!isPressableEnabled.value) {
return;
}
const newScale = newScaleValue(event.nativeEvent.locationX, sliderContainerSize);
translateSlider.value = event.nativeEvent.locationX;
const newScale = newScaleValue(locationX, sliderContainerSize);
translateSlider.value = locationX;
const differential = newScale / scale.value;
scale.value = newScale;
const newX = translateX.value * differential;
const newY = translateY.value * differential;
updateImageOffset(newX, newY);
};

return (
Expand Down Expand Up @@ -328,7 +338,7 @@ const AvatarCropModal = (props) => {
<Pressable
style={[styles.mh5, styles.flex1]}
onLayout={initializeSliderContainer}
onPressIn={sliderOnPress}
onPressIn={e => runOnUI(sliderOnPress)(e.nativeEvent.locationX)}
>
<Slider sliderValue={translateSlider} onGesture={panSliderGestureEventHandler} />
</Pressable>
Expand Down