Skip to content

Commit

Permalink
fix: apply workaround for android anr (#1964)
Browse files Browse the repository at this point in the history
* fix: apply workaround for android anr

ref: Expensify/App#12820

* chore: simplify the cell renderer component

* fix: update snapshots
  • Loading branch information
santhoshvai authored Feb 10, 2023
1 parent 3cf9977 commit a356cef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 22 additions & 2 deletions package/src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const styles = StyleSheet.create({
},
flex: { flex: 1 },
invert: { transform: [{ scaleY: -1 }] },
invertAndroid: {
// Invert the Y AND X axis to prevent a react native issue that can lead to ANRs on android 13
// details: https://github.com/Expensify/App/pull/12820
transform: [{ scaleX: -1 }, { scaleY: -1 }],
},
listContainer: {
flex: 1,
width: '100%',
Expand All @@ -88,6 +93,10 @@ const styles = StyleSheet.create({
},
});

const InvertedCellRendererComponent = (props: React.PropsWithChildren<unknown>) => (
<View {...props} style={styles.invertAndroid} />
);

const keyExtractor = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
>(
Expand Down Expand Up @@ -970,17 +979,23 @@ const MessageListWithContext = <
return null;
};

const shouldApplyAndroidWorkaround =
inverted && Platform.OS === 'android' && Platform.Version >= 33;

return (
<View
style={[styles.container, { backgroundColor: white_snow }, container]}
testID='message-flat-list-wrapper'
>
<FlatList
CellRendererComponent={
shouldApplyAndroidWorkaround ? InvertedCellRendererComponent : undefined
}
contentContainerStyle={[styles.contentContainer, contentContainer]}
data={messageList}
/** Disables the MessageList UI. Which means, message actions, reactions won't work. */
extraData={disabled || !hasNoMoreRecentMessagesToLoad}
inverted={inverted}
inverted={shouldApplyAndroidWorkaround ? false : inverted}
keyboardShouldPersistTaps='handled'
keyExtractor={keyExtractor}
ListEmptyComponent={renderListEmptyComponent}
Expand All @@ -1000,7 +1015,12 @@ const MessageListWithContext = <
ref={refCallback}
renderItem={renderItem}
scrollEnabled={overlay === 'none'}
style={[styles.listContainer, listContainer]}
showsVerticalScrollIndicator={!shouldApplyAndroidWorkaround}
style={[
styles.listContainer,
listContainer,
shouldApplyAndroidWorkaround ? styles.invertAndroid : undefined,
]}
testID='message-flat-list'
viewabilityConfig={flatListViewabilityConfig}
{...additionalFlatListProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ exports[`Thread should match thread snapshot 1`] = `
renderItem={[Function]}
scrollEnabled={false}
scrollEventThrottle={50}
showsVerticalScrollIndicator={true}
stickyHeaderIndices={Array []}
style={
Array [
Expand All @@ -178,6 +179,7 @@ exports[`Thread should match thread snapshot 1`] = `
"width": "100%",
},
Object {},
undefined,
],
]
}
Expand Down

0 comments on commit a356cef

Please sign in to comment.