diff options
author | Hailey <me@haileyok.com> | 2024-05-10 07:49:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-10 07:49:08 -0700 |
commit | 1a90426026aa4fc851f61044d27fa0c1febdb715 (patch) | |
tree | 622704788c5e01ee849240a1934de798cb056611 /src/screens/Messages/Conversation/MessagesList.tsx | |
parent | 195c9f10456a988a7b09369e41c8a8cf6c94431f (diff) | |
download | voidsky-1a90426026aa4fc851f61044d27fa0c1febdb715.tar.zst |
[🐴] Remove extra spinner states from chat screen (#3947)
* remove extra loading states from chat * nits * fix scrolling animation to bottom * nit * move spinner to top
Diffstat (limited to 'src/screens/Messages/Conversation/MessagesList.tsx')
-rw-r--r-- | src/screens/Messages/Conversation/MessagesList.tsx | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/screens/Messages/Conversation/MessagesList.tsx b/src/screens/Messages/Conversation/MessagesList.tsx index f99a41b7f..a92f3d50a 100644 --- a/src/screens/Messages/Conversation/MessagesList.tsx +++ b/src/screens/Messages/Conversation/MessagesList.tsx @@ -10,7 +10,7 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context' import {AppBskyRichtextFacet, RichText} from '@atproto/api' import {shortenLinks} from '#/lib/strings/rich-text-manip' -import {isIOS} from '#/platform/detection' +import {isIOS, isNative} from '#/platform/detection' import {useConvo} from '#/state/messages/convo' import {ConvoItem, ConvoStatus} from '#/state/messages/convo/types' import {useAgent} from '#/state/session' @@ -85,7 +85,7 @@ export function MessagesList() { // Instead, we use `onMomentumScrollEnd` and this value to determine if we need to start scrolling or not. const isMomentumScrolling = useSharedValue(false) - const [hasInitiallyScrolled, setHasInitiallyScrolled] = React.useState(false) + const hasInitiallyScrolled = useSharedValue(false) // Every time the content size changes, that means one of two things is happening: // 1. New messages are being added from the log or from a message you have sent @@ -101,7 +101,7 @@ export function MessagesList() { (_: number, height: number) => { // Because web does not have `maintainVisibleContentPosition` support, we will need to manually scroll to the // previous offset whenever we add new content to the previous offset whenever we add new content to the list. - if (isWeb && isAtTop.value && hasInitiallyScrolled) { + if (isWeb && isAtTop.value && hasInitiallyScrolled.value) { flatListRef.current?.scrollToOffset({ animated: false, offset: height - contentHeight.value, @@ -116,7 +116,7 @@ export function MessagesList() { } flatListRef.current?.scrollToOffset({ - animated: hasInitiallyScrolled, + animated: hasInitiallyScrolled.value, offset: height, }) isMomentumScrolling.value = true @@ -133,7 +133,7 @@ export function MessagesList() { // The check for `hasInitiallyScrolled` prevents an initial fetch on mount. FlatList triggers `onStartReached` // immediately on mount, since we are in fact at an offset of zero, so we have to ignore those initial calls. const onStartReached = useCallback(() => { - if (convo.status === ConvoStatus.Ready && hasInitiallyScrolled) { + if (convo.status === ConvoStatus.Ready && hasInitiallyScrolled.value) { convo.fetchMessageHistory() } }, [convo, hasInitiallyScrolled]) @@ -178,8 +178,8 @@ export function MessagesList() { // This number _must_ be the height of the MaybeLoader component. // We don't check for zero, because the `MaybeLoader` component is always present, even when not visible, which // adds a 50 pixel offset. - if (contentHeight.value > 50 && !hasInitiallyScrolled) { - runOnJS(setHasInitiallyScrolled)(true) + if (contentHeight.value > 50 && !hasInitiallyScrolled.value) { + hasInitiallyScrolled.value = true } }, [contentHeight.value, hasInitiallyScrolled, isAtBottom, isAtTop], @@ -228,17 +228,20 @@ export function MessagesList() { data={convo.items} renderItem={renderItem} keyExtractor={keyExtractor} + containWeb={true} + contentContainerStyle={{ + paddingHorizontal: 10, + }} disableVirtualization={true} - initialNumToRender={isWeb ? 50 : 25} - maxToRenderPerBatch={isWeb ? 50 : 25} + initialNumToRender={isNative ? 30 : 60} + maxToRenderPerBatch={isWeb ? 30 : 60} keyboardDismissMode="on-drag" keyboardShouldPersistTaps="handled" maintainVisibleContentPosition={{ minIndexForVisible: 1, }} - containWeb={true} - contentContainerStyle={{paddingHorizontal: 10}} removeClippedSubviews={false} + sideBorders={false} onContentSizeChange={onContentSizeChange} onStartReached={onStartReached} onScrollToIndexFailed={onScrollToIndexFailed} @@ -246,7 +249,6 @@ export function MessagesList() { ListHeaderComponent={ <MaybeLoader isLoading={convo.isFetchingHistory} /> } - sideBorders={false} /> </ScrollProvider> <MessageInput onSendMessage={onSendMessage} scrollToEnd={scrollToEnd} /> |