Skip to content

Commit 13a2dae

Browse files
PR Batch Testerclaude
andcommitted
fix(mobile): run the running-thread shimmer on the native driver instead
The app-wide ANDROID_SYNCHRONOUSLY_UPDATE_UI_PROPS flag needs a store build and can drop onPress on Pressables inside transformed views, like the floating working control. Revert it, the fingerprint hash, and the LoadingStrip tweak. Instead, move only the looping "Thinking" shimmer to React Native's Animated with useNativeDriver, which updates views without shadow-tree commits. One timing covers the sweep and the pause so the native driver loops it. JS-only, so it ships with the next update. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 860ea9d commit 13a2dae

5 files changed

Lines changed: 51 additions & 75 deletions

File tree

‎apps/mobile/fingerprint.config.js‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,8 @@ if (!majorVersion) {
1313
throw new Error("fingerprint.config.js could not read the app version from app.config.ts");
1414
}
1515

16-
// Reanimated compiles its static feature flags from package.json into native
17-
// code, but Expo only hashes package.json's scripts. Without this, flipping a
18-
// flag would ship as an OTA that never reaches the binary.
19-
const reanimatedConfig = JSON.parse(
20-
fs.readFileSync(path.join(__dirname, "package.json"), "utf8"),
21-
).reanimated;
22-
2316
module.exports = {
2417
// Hash the pinned Screens fork's native source, rather than only its version.
2518
nativeModuleSourceType: "files",
26-
extraSources: [
27-
{ type: "contents", id: "appMajorVersion", contents: majorVersion },
28-
{
29-
type: "contents",
30-
id: "reanimatedStaticFeatureFlags",
31-
contents: JSON.stringify(reanimatedConfig ?? {}),
32-
},
33-
],
19+
extraSources: [{ type: "contents", id: "appMajorVersion", contents: majorVersion }],
3420
};

‎apps/mobile/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@
174174
},
175175
"reanimated": {
176176
"staticFeatureFlags": {
177-
"DISABLE_COMMIT_PAUSING_MECHANISM": true,
178-
"ANDROID_SYNCHRONOUSLY_UPDATE_UI_PROPS": true
177+
"DISABLE_COMMIT_PAUSING_MECHANISM": true
179178
}
180179
}
181180
}

‎apps/mobile/src/components/LoadingStrip.tsx‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,21 @@ function IndeterminateLoadingStrip() {
5656
};
5757
}, [travelProgress]);
5858

59-
// Keep the animated style transform-only. On Android a layout prop here would
60-
// make every frame a shadow-tree commit instead of a synchronous UI update.
6159
const indicatorStyle = useAnimatedStyle(
6260
() => ({
6361
transform: [
6462
{
6563
translateX: (containerWidth + indicatorWidth) * travelProgress.value - indicatorWidth,
6664
},
6765
],
66+
width: indicatorWidth,
6867
}),
6968
[containerWidth, indicatorWidth],
7069
);
7170

7271
return (
7372
<LoadingStripFrame onLayout={setContainerWidth}>
74-
<Animated.View
75-
className="h-full rounded-full bg-primary"
76-
style={[{ width: indicatorWidth }, indicatorStyle]}
77-
/>
73+
<Animated.View className="h-full rounded-full bg-primary" style={indicatorStyle} />
7874
</LoadingStripFrame>
7975
);
8076
}

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ import {
3333
} from "react";
3434
import {
3535
AccessibilityInfo,
36+
Animated as NativeAnimated,
3637
AppState,
3738
type ColorValue,
39+
Easing,
3840
Pressable,
3941
ScrollView,
4042
StyleSheet,
@@ -91,17 +93,12 @@ import type { FilePreviewSource } from "../../components/FilePreviewModal";
9193
import { FilePreviewGallery } from "../../components/FilePreviewGallery";
9294
import { ThreadMarkdownImage } from "./ThreadMarkdownImage";
9395
import Animated, {
94-
cancelAnimation,
95-
Easing,
9696
FadeIn,
9797
FadeOut,
9898
LinearTransition,
9999
ReduceMotion,
100100
useAnimatedStyle,
101101
useSharedValue,
102-
withDelay,
103-
withRepeat,
104-
withSequence,
105102
withTiming,
106103
} from "react-native-reanimated";
107104
import { useAssetUrl } from "../../state/assets";
@@ -267,7 +264,7 @@ export function ShimmeringWorkContent(props: {
267264
const [appIsActive, setAppIsActive] = useState(AppState.currentState === "active");
268265
const [reducedMotion, setReducedMotion] = useState(true);
269266
const screenIsFocused = useIsFocused();
270-
const progress = useSharedValue(0);
267+
const [progress] = useState(() => new NativeAnimated.Value(0));
271268
const gradientId = `work-shimmer-${useId().replaceAll(":", "")}`;
272269
const contentWidth = Math.min(
273270
availableWidth,
@@ -290,37 +287,35 @@ export function ShimmeringWorkContent(props: {
290287
return () => subscription.remove();
291288
}, []);
292289

290+
// Runs on React Native's native driver instead of Reanimated, whose
291+
// per-frame commits starve React's while commit pausing is disabled
292+
// (package.json). See docs/internals/performance-regressions.md.
293293
useEffect(() => {
294-
cancelAnimation(progress);
295-
progress.value = 0;
294+
progress.setValue(0);
296295
if (contentWidth <= 0 || reducedMotion || !appIsActive || !screenIsFocused) return;
297296

298-
progress.value = withRepeat(
299-
withSequence(
300-
withTiming(1, {
301-
duration: SHIMMER_SWEEP_MS,
302-
easing: Easing.linear,
303-
reduceMotion: ReduceMotion.Never,
304-
}),
305-
withDelay(
306-
SHIMMER_PAUSE_MS,
307-
withTiming(0, { duration: 0, reduceMotion: ReduceMotion.Never }),
308-
),
309-
),
310-
-1,
311-
false,
312-
undefined,
313-
ReduceMotion.Never,
297+
const loop = NativeAnimated.loop(
298+
NativeAnimated.timing(progress, {
299+
toValue: 1,
300+
duration: SHIMMER_SWEEP_MS + SHIMMER_PAUSE_MS,
301+
easing: Easing.linear,
302+
useNativeDriver: true,
303+
}),
314304
);
315-
return () => cancelAnimation(progress);
305+
loop.start();
306+
return () => loop.stop();
316307
}, [appIsActive, contentWidth, progress, reducedMotion, screenIsFocused]);
317308

318-
const sweepStyle = useAnimatedStyle(() => ({
319-
transform: [{ translateX: -SHIMMER_WIDTH + progress.value * (contentWidth + SHIMMER_WIDTH) }],
320-
}));
321-
const counterSweepStyle = useAnimatedStyle(() => ({
322-
transform: [{ translateX: SHIMMER_WIDTH - progress.value * (contentWidth + SHIMMER_WIDTH) }],
323-
}));
309+
// One timing covers the sweep and the pause, so the native driver can loop it.
310+
const sweepInputRange = [0, SHIMMER_SWEEP_MS / (SHIMMER_SWEEP_MS + SHIMMER_PAUSE_MS), 1];
311+
const sweepTranslateX = progress.interpolate({
312+
inputRange: sweepInputRange,
313+
outputRange: [-SHIMMER_WIDTH, contentWidth, contentWidth],
314+
});
315+
const counterSweepTranslateX = progress.interpolate({
316+
inputRange: sweepInputRange,
317+
outputRange: [SHIMMER_WIDTH, -contentWidth, -contentWidth],
318+
});
324319

325320
return (
326321
<View
@@ -341,13 +336,20 @@ export function ShimmeringWorkContent(props: {
341336
onTextLayout={(event) => setTextWidth(event.nativeEvent.lines[0]?.width ?? 0)}
342337
/>
343338
{!reducedMotion && appIsActive && screenIsFocused && contentWidth > 0 ? (
344-
<Animated.View
345-
className="absolute inset-y-0 left-0 overflow-hidden"
339+
<NativeAnimated.View
346340
pointerEvents="none"
347341
accessible={false}
348342
accessibilityElementsHidden
349343
importantForAccessibility="no-hide-descendants"
350-
style={[{ width: SHIMMER_WIDTH }, sweepStyle]}
344+
style={{
345+
position: "absolute",
346+
top: 0,
347+
bottom: 0,
348+
left: 0,
349+
overflow: "hidden",
350+
width: SHIMMER_WIDTH,
351+
transform: [{ translateX: sweepTranslateX }],
352+
}}
351353
>
352354
<MaskedView
353355
style={StyleSheet.absoluteFill}
@@ -368,7 +370,9 @@ export function ShimmeringWorkContent(props: {
368370
</Svg>
369371
}
370372
>
371-
<Animated.View style={[{ width: availableWidth }, counterSweepStyle]}>
373+
<NativeAnimated.View
374+
style={{ width: availableWidth, transform: [{ translateX: counterSweepTranslateX }] }}
375+
>
372376
<ShimmerWorkContent
373377
textClassName={props.textClassName}
374378
compact={props.compact}
@@ -381,9 +385,9 @@ export function ShimmeringWorkContent(props: {
381385
themeAppearance={props.themeAppearance}
382386
toolIcon={props.toolIcon}
383387
/>
384-
</Animated.View>
388+
</NativeAnimated.View>
385389
</MaskedView>
386-
</Animated.View>
390+
</NativeAnimated.View>
387391
) : null}
388392
</View>
389393
);

‎docs/internals/performance-regressions.md‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,9 @@ Focused coverage: `ProjectionSettlement.test.ts`, `ThreadSettlementService.test.
106106
## Mobile looping animations
107107

108108
`apps/mobile/package.json` sets Reanimated's `DISABLE_COMMIT_PAUSING_MECHANISM` so keyboard
109-
avoiding animates on iOS. Without commit pausing, an animation that commits to the shadow tree on
110-
every frame can starve React's commits: the JS thread keeps retrying the same commit, which looks
111-
like a frozen screen where back does nothing. Release builds retry forever; dev builds abort with
112-
`ShadowTree.cpp: assertion failed (attempts < 1024)`.
113-
114-
`ANDROID_SYNCHRONOUSLY_UPDATE_UI_PROPS` keeps Android out of that loop by applying the props in
115-
Reanimated's `SynchronousPropNames.h` (transform, opacity, border radii, and numeric background,
116-
border, and tint colors) directly to views. Keep looping animations (`withRepeat`, shimmers,
117-
spinners) on those props. Any other animated prop on the same view, such as `width` or text
118-
`color`, sends that view's whole update back through the shadow tree every frame, so pass static
119-
sizes as a plain style.
120-
121-
These flags are compiled into the native build. `apps/mobile/fingerprint.config.js` hashes them,
122-
because Expo's fingerprint otherwise ignores `package.json` beyond `scripts` and a flag change
123-
would ship as an OTA update that never reaches the binary.
109+
avoiding animates on iOS. Reanimated commits each animation frame to the shadow tree, and without
110+
commit pausing those commits can starve React's: the JS thread keeps retrying its commit, the
111+
screen freezes, and back does nothing. Release builds retry forever; dev builds abort with
112+
`ShadowTree.cpp: assertion failed (attempts < 1024)`. A looping animation that stays on screen
113+
while heavy content renders, such as the running-thread shimmer in `thread-work-log.tsx`, runs on
114+
React Native's `Animated` with `useNativeDriver: true`, which updates views without commits.

0 commit comments

Comments
 (0)