-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[cherry-pick][4.2] Fix commits during the Android draw pass #9123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bartlomiejbloniarz
merged 2 commits into
4.2-stable
from
@bartlomiejbloniarz/android-draw-cherry-pick-4.2
Mar 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
181 changes: 181 additions & 0 deletions
181
apps/common-app/src/apps/reanimated/examples/AndroidDrawPassExample.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| import { useNavigation } from '@react-navigation/native'; | ||
| import type { NativeStackNavigationProp } from '@react-navigation/native-stack'; | ||
| import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
| import React, { useCallback } from 'react'; | ||
| import { Button, StyleSheet, Text, View } from 'react-native'; | ||
| import Animated, { | ||
| interpolate, | ||
| useAnimatedScrollHandler, | ||
| useAnimatedStyle, | ||
| useSharedValue, | ||
| } from 'react-native-reanimated'; | ||
|
|
||
| type AndroidDrawPassParamList = { | ||
| Description: undefined; | ||
| ScrollList: undefined; | ||
| }; | ||
|
|
||
| const Stack = createNativeStackNavigator<AndroidDrawPassParamList>(); | ||
| const LIST_ITEM_COUNT = 80; | ||
|
|
||
| export default function AndroidDrawPassExample() { | ||
| return ( | ||
| <View style={descriptionStyles.container}> | ||
| <Stack.Navigator> | ||
| <Stack.Screen name="Description" component={DescriptionScreen} /> | ||
| <Stack.Screen name="ScrollList" component={ScrollListScreen} /> | ||
| </Stack.Navigator> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function DescriptionScreen() { | ||
| const navigation = | ||
| useNavigation<NativeStackNavigationProp<AndroidDrawPassParamList>>(); | ||
|
|
||
| return ( | ||
| <View style={descriptionStyles.centered}> | ||
| <Text style={descriptionStyles.title}>Android Draw Pass Fix</Text> | ||
| <Text style={descriptionStyles.description}> | ||
| This example reproduces a bug that was fixed on Android where committing | ||
| updates during a draw pass caused a crash. | ||
| </Text> | ||
| <Text style={descriptionStyles.description}> | ||
| Previously, if you navigated to the scroll list and went back{' '} | ||
| <Text style={descriptionStyles.bold}>while actively scrolling</Text>, | ||
| the app would crash. This happened because Reanimated was attempting to | ||
| commit UI updates while Android was in the middle of a draw pass, and | ||
| sometimes React would have some hierarchy mutations queued up that would | ||
| get bundled with these updates, triggering the crash. | ||
| </Text> | ||
| <Text style={descriptionStyles.description}> | ||
| The fix detects when a draw pass is in progress and pushes only | ||
| non-layout updates through the synchronous update path, while layout | ||
| updates are deferred to the next frame. This ensures that we never | ||
| attempt to mutate the view hierarchy during a draw pass. | ||
| </Text> | ||
| <Button | ||
| title="Go to scroll list" | ||
| onPress={() => navigation.navigate('ScrollList')} | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function ListItem({ index }: { index: number }) { | ||
| return ( | ||
| <View style={listStyles.listItem}> | ||
| <Text>Item {index + 1}</Text> | ||
| <Text style={listStyles.listItemSubtext}> | ||
| Scroll fast and press Back — this used to crash on Android | ||
| </Text> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| function ScrollListScreen() { | ||
| const scrollY = useSharedValue(0); | ||
|
|
||
| const scrollHandler = useAnimatedScrollHandler({ | ||
| onScroll: (event) => { | ||
| scrollY.value = event.contentOffset.y; | ||
| }, | ||
| }); | ||
|
|
||
| const floatingBadgeStyle = useAnimatedStyle(() => { | ||
| const scale = interpolate(scrollY.value, [0, 100, 200], [1, 1.2, 0.9]); | ||
| const rotate = interpolate(scrollY.value, [0, 150, 300], [0, 5, -5]); | ||
|
|
||
| return { | ||
| width: 100, | ||
| transform: [{ scale }, { rotate: `${rotate}deg` }], | ||
| }; | ||
| }); | ||
|
|
||
| const renderItem = useCallback( | ||
| ({ item }: { item: number }) => <ListItem index={item} />, | ||
| [] | ||
| ); | ||
|
|
||
| const keyExtractor = useCallback((item: number) => `item-${item}`, []); | ||
| const data = Array.from({ length: LIST_ITEM_COUNT }, (_, index) => index); | ||
|
|
||
| return ( | ||
| <View style={listStyles.container}> | ||
| <Animated.View style={[listStyles.floatingBadge, floatingBadgeStyle]}> | ||
| <Text style={listStyles.badgeText}>scrollY</Text> | ||
| </Animated.View> | ||
|
|
||
| <Animated.FlatList | ||
| data={data} | ||
| renderItem={renderItem} | ||
| keyExtractor={keyExtractor} | ||
| onScroll={scrollHandler} | ||
| scrollEventThrottle={16} | ||
| contentContainerStyle={listStyles.listContent} | ||
| showsVerticalScrollIndicator | ||
| /> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| const descriptionStyles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| }, | ||
| centered: { | ||
| flex: 1, | ||
| alignItems: 'center', | ||
| gap: 16, | ||
| padding: 24, | ||
| }, | ||
| title: { | ||
| fontSize: 20, | ||
| fontWeight: '700', | ||
| marginBottom: 4, | ||
| }, | ||
| description: { | ||
| color: '#333', | ||
| fontSize: 15, | ||
| lineHeight: 22, | ||
| }, | ||
| bold: { | ||
| fontWeight: '700', | ||
| }, | ||
| }); | ||
|
|
||
| const listStyles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| }, | ||
| floatingBadge: { | ||
| position: 'absolute', | ||
| top: 100, | ||
| right: 20, | ||
| zIndex: 10, | ||
| paddingVertical: 8, | ||
| paddingHorizontal: 14, | ||
| borderRadius: 12, | ||
| backgroundColor: 'rgba(255, 149, 0, 0.9)', | ||
| }, | ||
| badgeText: { | ||
| color: '#fff', | ||
| fontWeight: '600', | ||
| }, | ||
| listContent: { | ||
| paddingTop: 24, | ||
| paddingBottom: 40, | ||
| paddingHorizontal: 20, | ||
| }, | ||
| listItem: { | ||
| marginBottom: 8, | ||
| borderRadius: 8, | ||
| paddingVertical: 16, | ||
| paddingHorizontal: 12, | ||
| backgroundColor: 'rgba(128, 128, 128, 0.12)', | ||
| }, | ||
| listItemSubtext: { | ||
| marginTop: 6, | ||
| opacity: 0.8, | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.