Skip to content

Commit

Permalink
feat: Explicitly mark worklets
Browse files Browse the repository at this point in the history
  • Loading branch information
iliubinskii committed Feb 24, 2024
1 parent 7f6a508 commit 1ad7be4
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/CandlestickChart/CandlestickChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ export default memo(
.enabled(enabled)
.minDistance(consts.Gesture.pan.minDistance)
.onBegin(({ numberOfPointers, translationX }) => {
"worklet";
pan0.value = pan.value;
panNumberOfPointers.value = numberOfPointers;
panTranslationX.value = translationX;
})
.onStart(() => {
"worklet";
runOnJS(hideSnackbar)();
})
.onUpdate(({ numberOfPointers, translationX }) => {
"worklet";

if (numberOfPointers <= 1) {
if (panNumberOfPointers.value === numberOfPointers) {
// No need to restart
Expand Down Expand Up @@ -118,14 +122,18 @@ export default memo(
Gesture.Pinch()
.enabled(enabled)
.onBegin(({ numberOfPointers, scale }) => {
"worklet";
pan0.value = pan.value;
panNumberOfPointers.value = numberOfPointers;
panScale.value = scale;
})
.onStart(() => {
"worklet";
runOnJS(hideSnackbar)();
})
.onUpdate(({ numberOfPointers, scale }) => {
"worklet";

if (numberOfPointers >= 2) {
if (panNumberOfPointers.value === numberOfPointers) {
// No need to restart
Expand Down Expand Up @@ -158,6 +166,8 @@ export default memo(
})
),
Gesture.Tap().onEnd(({ x }) => {
"worklet";

const dataWidth = width - paddingStart - paddingEnd;

const barCount = pan0.value[1] - pan0.value[0];
Expand Down
3 changes: 3 additions & 0 deletions src/components/DateTimePicker/Calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,15 @@ export default memo(
Gesture.Pan()
.minDistance(consts.Gesture.pan.minDistance)
.onBegin(({ x, y }) => {
"worklet";
setRange(x, y, GestureStep.start);
})
.onUpdate(({ x, y }) => {
"worklet";
setRange(x, y, GestureStep.update);
})
.onFinalize(({ x, y }) => {
"worklet";
setRange(x, y, GestureStep.end);
}),
[setRange]
Expand Down
3 changes: 3 additions & 0 deletions src/components/DateTimePicker/Clock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,15 @@ export default memo(
Gesture.Pan()
.minDistance(consts.Gesture.pan.minDistance)
.onBegin(({ x, y }) => {
"worklet";
setRange(x, y, GestureStep.start);
})
.onUpdate(({ x, y }) => {
"worklet";
setRange(x, y, GestureStep.update);
})
.onFinalize(({ x, y }) => {
"worklet";
setRange(x, y, GestureStep.end);
}),
[setRange]
Expand Down
11 changes: 11 additions & 0 deletions src/components/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ export default memo(
Gesture.Pan()
.minDistance(consts.Gesture.pan.minDistance)
.onTouchesDown(({ allTouches }, { fail }) => {
"worklet";

if (
active.value ||
(dragToOpen &&
Expand All @@ -265,12 +267,14 @@ export default memo(
} else fail();
})
.onBegin(event => {
"worklet";
cancelAnimation(pan);
pan0.value =
pan.value -
Math.max(inboundValue(event.x, event.y) / size.value - 1, 0);
})
.onStart(() => {
"worklet";
runOnJS(hideSnackbar)();

if (active.value) {
Expand All @@ -284,12 +288,16 @@ export default memo(
busy.value = true;
})
.onUpdate(event => {
"worklet";
pan.value = gestureValue(event);
})
.onEnd(() => {
"worklet";
busy.value = false;
})
.onFinalize(event => {
"worklet";

if (active.value)
if (pan.value === 1) {
active.value = false;
Expand Down Expand Up @@ -349,11 +357,14 @@ export default memo(
}),
Gesture.Tap()
.onTouchesDown((_event, { fail }) => {
"worklet";

if (active.value) {
// Tappable
} else fail();
})
.onEnd(() => {
"worklet";
runOnJS(hideSnackbar)();
runOnJS(moveOut)();
})
Expand Down
8 changes: 8 additions & 0 deletions src/components/Swipeable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default memo(
Gesture.Pan()
.manualActivation(true)
.onTouchesDown(({ allTouches }, { fail }) => {
"worklet";

const touch = allTouches[0];

if (activated.value) {
Expand All @@ -106,6 +108,8 @@ export default memo(
else fail();
})
.onTouchesMove(({ allTouches }, { activate, fail }) => {
"worklet";

const touch = allTouches[0];

if (activated.value) {
Expand All @@ -129,18 +133,22 @@ export default memo(
} else fail();
})
.onStart(() => {
"worklet";
cancelAnimation(pan);
activated.value = true;
pan0.value = pan.value;
panOpacity.value = 0;
})
.onUpdate(event => {
"worklet";
pan.value = pan0.value + event.translationX;
})
.onEnd(event => {
"worklet";
runOnJS(onEnd)(event);
})
.onFinalize(() => {
"worklet";
activated.value = false;
}),
[activated, initialTouch, layout, onEnd, pan, pan0, panOpacity, threshold]
Expand Down
8 changes: 8 additions & 0 deletions src/components/common-components/AnimatedScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,23 @@ export default memo(
Gesture.Pan()
.minDistance(consts.Gesture.pan.minDistance)
.onTouchesDown((_event, { fail }) => {
"worklet";

if (disabled && disabled.value) fail();
})
.onBegin(() => {
"worklet";
cancelAnimation(pan);
pan0.value = pan.value;
panLastStop.value = pan.value;
})
.onStart(() => {
"worklet";
runOnJS(hideSnackbar)();
})
.onUpdate(event => {
"worklet";

const delta = getDelta(event);

const velocity = getVelocity(event);
Expand All @@ -176,6 +182,8 @@ export default memo(
runOnJS(onScroll)(value);
})
.onFinalize(event => {
"worklet";

const delta = getDelta(event);

const velocity = getVelocity(event);
Expand Down
1 change: 1 addition & 0 deletions src/contexts/snackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const SnackbarProvider = memo(
const gesture = React.useMemo(
() =>
Gesture.Tap().onEnd(() => {
"worklet";
runOnJS(hideSnackbar)();
}),
[hideSnackbar]
Expand Down

0 comments on commit 1ad7be4

Please sign in to comment.