Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix(mobile): use worklet easing for page zoom animation

Amruth Pillai82f7fc6a391b
diff --git a/apps/mobile/src/preview/use-page-zoom.tsx b/apps/mobile/src/preview/use-page-zoom.tsx
index 5c5da52dd..add9a9962 100644
--- a/apps/mobile/src/preview/use-page-zoom.tsx
+++ b/apps/mobile/src/preview/use-page-zoom.tsx
@@ -5,7 +5,7 @@ import { Gesture, GestureDetector } from "react-native-gesture-handler";
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
import { scheduleOnRN } from "react-native-worklets";
import { snapZoom, zoomOffset } from "./zoom";
-import { useReducedMotion, useTheme } from "@/ui";
+import { useReducedMotion, useTheme, workletEaseMove } from "@/ui";
export function usePageZoom() {
const [zoom, setZoom] = useState<number | null>(null);
@@ -16,7 +16,7 @@ export function usePageZoom() {
const change = (value: number) => {
const target = snapZoom(value) ?? 1;
live.set(
- withTiming(target, { duration: reduced ? 0 : motion.d2, easing: motion.easeMove }, (finished) => {
+ withTiming(target, { duration: reduced ? 0 : motion.d2, easing: workletEaseMove }, (finished) => {
if (finished) scheduleOnRN(commit, target);
}),
);
diff --git a/apps/mobile/src/ui/index.ts b/apps/mobile/src/ui/index.ts
index 958c5d96b..0f3cbc0f6 100644
--- a/apps/mobile/src/ui/index.ts
+++ b/apps/mobile/src/ui/index.ts
@@ -50,7 +50,7 @@ export {
type ToastOptions,
} from "./overlays";
export { SortableList, type SortableItemInfo, type SortableListProps } from "./sortable";
-export { haptics, listItemMotion, listLayout, useFirstAppearance, useReducedMotion } from "./motion";
+export { haptics, listItemMotion, listLayout, useFirstAppearance, useReducedMotion, workletEaseMove } from "./motion";
export { usePullRefresh } from "./use-pull-refresh";
export { Screen, Text, type ScreenProps, type TextProps, type TextVariant } from "./text";
export { WindowSafeAreaProvider, useWindowSafeAreaInsets } from "./safe-area";
diff --git a/apps/mobile/src/ui/motion.ts b/apps/mobile/src/ui/motion.ts
index a99e580ec..1d442274d 100644
--- a/apps/mobile/src/ui/motion.ts
+++ b/apps/mobile/src/ui/motion.ts
@@ -53,7 +53,8 @@ export function useIsWide(): boolean {
// Shared list motion. Reanimated needs its own (worklet) easing, so these repeat the `motion.ease` and `motion.easeMove` curves.
const listEase = Easing.bezier(0.2, 0.8, 0.2, 1);
-const listMove = Easing.bezier(0.77, 0, 0.175, 1);
+/** `motion.easeMove` for Reanimated: React Native's `Easing` is not a worklet and crashes on the UI thread. */
+export const workletEaseMove = Easing.bezier(0.77, 0, 0.175, 1);
const listStagger = 40;
const listStaggerCap = 8;
@@ -73,7 +74,9 @@ export const listItemMotion = (index: number, first: boolean) =>
first ? { entering: listEntering(index), exiting: listExiting } : { exiting: listExiting };
/** Rows sliding into the gap a removed or moved row leaves. */
-export const listLayout = LinearTransition.duration(motion.d2).easing(listMove).reduceMotion(ReduceMotion.System);
+export const listLayout = LinearTransition.duration(motion.d2)
+ .easing(workletEaseMove)
+ .reduceMotion(ReduceMotion.System);
/**
* True until shortly after the list first shows data, so rows stagger in once when the screen opens and never again