Skip to content

Commit a356cef

Browse files
authored
fix: apply workaround for android anr (#1964)
* fix: apply workaround for android anr ref: Expensify/App#12820 * chore: simplify the cell renderer component * fix: update snapshots
1 parent 3cf9977 commit a356cef

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

package/src/components/MessageList/MessageList.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ const styles = StyleSheet.create({
7575
},
7676
flex: { flex: 1 },
7777
invert: { transform: [{ scaleY: -1 }] },
78+
invertAndroid: {
79+
// Invert the Y AND X axis to prevent a react native issue that can lead to ANRs on android 13
80+
// details: https://github.com/Expensify/App/pull/12820
81+
transform: [{ scaleX: -1 }, { scaleY: -1 }],
82+
},
7883
listContainer: {
7984
flex: 1,
8085
width: '100%',
@@ -88,6 +93,10 @@ const styles = StyleSheet.create({
8893
},
8994
});
9095

96+
const InvertedCellRendererComponent = (props: React.PropsWithChildren<unknown>) => (
97+
<View {...props} style={styles.invertAndroid} />
98+
);
99+
91100
const keyExtractor = <
92101
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
93102
>(
@@ -970,17 +979,23 @@ const MessageListWithContext = <
970979
return null;
971980
};
972981

982+
const shouldApplyAndroidWorkaround =
983+
inverted && Platform.OS === 'android' && Platform.Version >= 33;
984+
973985
return (
974986
<View
975987
style={[styles.container, { backgroundColor: white_snow }, container]}
976988
testID='message-flat-list-wrapper'
977989
>
978990
<FlatList
991+
CellRendererComponent={
992+
shouldApplyAndroidWorkaround ? InvertedCellRendererComponent : undefined
993+
}
979994
contentContainerStyle={[styles.contentContainer, contentContainer]}
980995
data={messageList}
981996
/** Disables the MessageList UI. Which means, message actions, reactions won't work. */
982997
extraData={disabled || !hasNoMoreRecentMessagesToLoad}
983-
inverted={inverted}
998+
inverted={shouldApplyAndroidWorkaround ? false : inverted}
984999
keyboardShouldPersistTaps='handled'
9851000
keyExtractor={keyExtractor}
9861001
ListEmptyComponent={renderListEmptyComponent}
@@ -1000,7 +1015,12 @@ const MessageListWithContext = <
10001015
ref={refCallback}
10011016
renderItem={renderItem}
10021017
scrollEnabled={overlay === 'none'}
1003-
style={[styles.listContainer, listContainer]}
1018+
showsVerticalScrollIndicator={!shouldApplyAndroidWorkaround}
1019+
style={[
1020+
styles.listContainer,
1021+
listContainer,
1022+
shouldApplyAndroidWorkaround ? styles.invertAndroid : undefined,
1023+
]}
10041024
testID='message-flat-list'
10051025
viewabilityConfig={flatListViewabilityConfig}
10061026
{...additionalFlatListProps}

package/src/components/Thread/__tests__/__snapshots__/Thread.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ exports[`Thread should match thread snapshot 1`] = `
162162
renderItem={[Function]}
163163
scrollEnabled={false}
164164
scrollEventThrottle={50}
165+
showsVerticalScrollIndicator={true}
165166
stickyHeaderIndices={Array []}
166167
style={
167168
Array [
@@ -178,6 +179,7 @@ exports[`Thread should match thread snapshot 1`] = `
178179
"width": "100%",
179180
},
180181
Object {},
182+
undefined,
181183
],
182184
]
183185
}

0 commit comments

Comments
 (0)