Skip to content
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

fix: properly invert list manually android #2685

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 40 additions & 31 deletions package/src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ 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 @@ -634,15 +630,15 @@ const MessageListWithContext = <

if (message.type === 'system') {
return (
<>
<View style={[shouldApplyAndroidWorkaround ? styles.invertAndroid : undefined]}>
<View testID={`message-list-item-${index}`}>
<MessageSystem
message={message}
style={[{ paddingHorizontal: screenPadding }, messageContainer]}
/>
</View>
{insertInlineUnreadIndicator && <InlineUnreadIndicator />}
</>
</View>
);
}

Expand All @@ -664,26 +660,30 @@ const MessageListWithContext = <
threadList={threadList}
/>
);
return wrapMessageInTheme ? (
<>
{shouldApplyAndroidWorkaround && renderDateSeperator}
<ThemeProvider mergedStyle={modifiedTheme}>
<View testID={`message-list-item-${index}`}>{renderMessage}</View>
</ThemeProvider>
{!shouldApplyAndroidWorkaround && renderDateSeperator}
{/* Adding indicator below the messages, since the list is inverted */}
{insertInlineUnreadIndicator && <InlineUnreadIndicator />}
</>
) : (
<>
<View testID={`message-list-item-${index}`}>
{shouldApplyAndroidWorkaround && renderDateSeperator}
{renderMessage}
</View>
{!shouldApplyAndroidWorkaround && renderDateSeperator}
{/* Adding indicator below the messages, since the list is inverted */}
{insertInlineUnreadIndicator && <InlineUnreadIndicator />}
</>
return (
<View style={[shouldApplyAndroidWorkaround ? styles.invertAndroid : undefined]}>
{wrapMessageInTheme ? (
<>
{shouldApplyAndroidWorkaround && renderDateSeperator}
<ThemeProvider mergedStyle={modifiedTheme}>
<View testID={`message-list-item-${index}`}>{renderMessage}</View>
</ThemeProvider>
{!shouldApplyAndroidWorkaround && renderDateSeperator}
{/* Adding indicator below the messages, since the list is inverted */}
{insertInlineUnreadIndicator && <InlineUnreadIndicator />}
</>
) : (
<>
<View testID={`message-list-item-${index}`}>
{shouldApplyAndroidWorkaround && renderDateSeperator}
{renderMessage}
</View>
{!shouldApplyAndroidWorkaround && renderDateSeperator}
{/* Adding indicator below the messages, since the list is inverted */}
{insertInlineUnreadIndicator && <InlineUnreadIndicator />}
</>
)}
</View>
);
};

Expand Down Expand Up @@ -1083,12 +1083,16 @@ const MessageListWithContext = <

// We need to omit the style related props from the additionalFlatListProps and add them directly instead of spreading
let additionalFlatListPropsExcludingStyle:
| Omit<NonNullable<typeof additionalFlatListProps>, 'style' | 'contentContainerStyle'>
| Omit<
NonNullable<typeof additionalFlatListProps>,
'style' | 'contentContainerStyle' | 'ItemSeparatorComponent'
>
| undefined;

if (additionalFlatListProps) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { contentContainerStyle, style, ...rest } = additionalFlatListProps;
const { contentContainerStyle, ItemSeparatorComponent, style, ...rest } =
additionalFlatListProps;
additionalFlatListPropsExcludingStyle = rest;
}

Expand All @@ -1102,6 +1106,13 @@ const MessageListWithContext = <
);
}

const ItemSeparatorComponent = additionalFlatListProps?.ItemSeparatorComponent;
const WrappedItemSeparatorComponent = () => (
<View style={[shouldApplyAndroidWorkaround ? styles.invertAndroid : undefined]}>
{ItemSeparatorComponent ? <ItemSeparatorComponent /> : null}
</View>
);
isekovanic marked this conversation as resolved.
Show resolved Hide resolved

return (
<View
style={[styles.container, { backgroundColor: white_snow }, container]}
Expand All @@ -1114,9 +1125,6 @@ const MessageListWithContext = <
</View>
) : (
<FlatList
CellRendererComponent={
shouldApplyAndroidWorkaround ? InvertedCellRendererComponent : undefined
}
contentContainerStyle={[
styles.contentContainer,
additionalFlatListProps?.contentContainerStyle,
Expand All @@ -1126,6 +1134,7 @@ const MessageListWithContext = <
data={processedMessageList}
extraData={disabled || !hasNoMoreRecentMessagesToLoad}
inverted={shouldApplyAndroidWorkaround ? false : inverted}
ItemSeparatorComponent={WrappedItemSeparatorComponent}
keyboardShouldPersistTaps='handled'
keyExtractor={keyExtractor}
ListFooterComponent={ListFooterComponent}
Expand Down
Loading