Skip to content

Commit 5061496

Browse files
committed
fix(mobile): update font size only after slider release
Keep drag progress on the UI thread and commit the snapped preference once when the gesture finalizes. This avoids app-wide re-renders, lag, and maximum update depth failures during heavy slider scrubbing.
1 parent 2f486ab commit 5061496

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎apps/mobile/src/features/settings/appearance/components/FontSizeSliderRow.tsx‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ export function FontSizeSliderRow(props: {
5858
}, [dragging, fraction, progress]);
5959

6060
const commit = useCallback((next: number) => {
61-
if (next === latest.current.value) {
61+
const current = latest.current;
62+
if (next === current.value) {
6263
return;
6364
}
6465
Haptics.selectionAsync().catch(() => undefined);
65-
latest.current.onChange(next);
66+
current.onChange(next);
6667
}, []);
6768

6869
const gesture = useMemo(() => {
@@ -96,17 +97,19 @@ export function FontSizeSliderRow(props: {
9697
dragging.value = true;
9798
const f = fractionAt(event.x);
9899
progress.value = f;
99-
runOnJS(commit)(valueAtFraction(f));
100100
})
101-
.onFinalize(() => {
101+
.onFinalize((_event, success) => {
102102
if (!dragging.value) {
103103
return;
104104
}
105105
dragging.value = false;
106-
progress.value = withTiming(
107-
fractionOfValue(valueAtFraction(progress.value)),
108-
SNAP_ANIMATION,
109-
);
106+
if (!success) {
107+
progress.value = withTiming(fractionOfValue(value), SNAP_ANIMATION);
108+
return;
109+
}
110+
const next = valueAtFraction(progress.value);
111+
progress.value = withTiming(fractionOfValue(next), SNAP_ANIMATION);
112+
runOnJS(commit)(next);
110113
});
111114

112115
const tap = Gesture.Tap()
@@ -118,7 +121,7 @@ export function FontSizeSliderRow(props: {
118121
});
119122

120123
return Gesture.Race(pan, tap);
121-
}, [commit, disabled, dragging, max, min, progress, step, trackWidth]);
124+
}, [commit, disabled, dragging, max, min, progress, step, trackWidth, value]);
122125

123126
const fillStyle = useAnimatedStyle(() => ({
124127
width: THUMB_SIZE / 2 + progress.value * Math.max(0, trackWidth.value - THUMB_SIZE),

0 commit comments

Comments
 (0)