From 56cefcbeece9256e0f99153ea521d71d1dd12d75 Mon Sep 17 00:00:00 2001 From: Rishi Balakrishnan Date: Mon, 5 Oct 2026 16:45:21 -0400 Subject: [PATCH] fix(live): open chat on the newest message and keep the composer above the keyboard Render chat in an inverted list so history starts at the most recent message instead of filling top-down and jumping, and fetch sender profiles in parallel. Replace KeyboardAvoidingView with explicit keyboard state: the composer sits on the keyboard, the stream info and chat label hide while typing, and dragging the chat dismisses the keyboard. Use an icon send button that stays visible when disabled in dark mode. --- src/features/streamplace/ChatComposer.tsx | 29 ++++++---- src/features/streamplace/ChatList.tsx | 18 ++----- src/features/streamplace/useChatProfiles.ts | 18 +++---- src/screens/StreamplaceWatch/index.tsx | 60 ++++++++++++--------- 4 files changed, 68 insertions(+), 57 deletions(-) diff --git a/src/features/streamplace/ChatComposer.tsx b/src/features/streamplace/ChatComposer.tsx index 6a72c7947..cd6d4eecc 100644 --- a/src/features/streamplace/ChatComposer.tsx +++ b/src/features/streamplace/ChatComposer.tsx @@ -1,11 +1,11 @@ import {useState} from 'react' -import {TextInput, View} from 'react-native' +import {Pressable, TextInput, View} from 'react-native' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {countGraphemes} from 'unicode-segmenter/grapheme' import {atoms as a, useTheme} from '#/alf' -import {Button, ButtonText} from '#/components/Button' +import {PaperPlaneVertical_Filled_Stroke2_Corner1_Rounded as PaperPlaneIcon} from '#/components/icons/PaperPlane' const MAX_GRAPHEMES = 300 @@ -63,15 +63,26 @@ export function ChatComposer({ ]} onSubmitEditing={submit} /> - + style={[ + a.rounded_full, + a.align_center, + a.justify_center, + { + width: 40, + height: 40, + backgroundColor: t.palette.primary_500, + opacity: disabled ? 0.5 : 1, + }, + ]}> + + ) } diff --git a/src/features/streamplace/ChatList.tsx b/src/features/streamplace/ChatList.tsx index 617a81e3f..d645c4471 100644 --- a/src/features/streamplace/ChatList.tsx +++ b/src/features/streamplace/ChatList.tsx @@ -1,4 +1,3 @@ -import {useRef} from 'react' import {FlatList, Pressable, View} from 'react-native' import { type AppBskyActorDefs, @@ -40,24 +39,15 @@ export function ChatList({ const data: ChatItem[] = [ ...messages.map(item => ({kind: 'message' as const, item})), ...pending.map(item => ({kind: 'pending' as const, item})), - ] - const listRef = useRef>(null) - const atBottom = useRef(true) + ].reverse() return ( { - const {contentOffset, contentSize, layoutMeasurement} = e.nativeEvent - atBottom.current = - contentOffset.y + layoutMeasurement.height >= contentSize.height - 40 - }} - onContentSizeChange={() => { - if (atBottom.current) listRef.current?.scrollToEnd({animated: false}) - }} + keyboardDismissMode="on-drag" + keyboardShouldPersistTaps="handled" keyExtractor={(item: ChatItem) => item.kind === 'message' ? item.item.message.uri diff --git a/src/features/streamplace/useChatProfiles.ts b/src/features/streamplace/useChatProfiles.ts index 97c6dd03c..88c86ca91 100644 --- a/src/features/streamplace/useChatProfiles.ts +++ b/src/features/streamplace/useChatProfiles.ts @@ -16,21 +16,21 @@ export function useChatProfiles(dids: string[]) { const missing = [...new Set(dids)].filter(d => !requested.current.has(d)) if (!missing.length) return missing.forEach(d => requested.current.add(d)) - void (async () => { - for (let i = 0; i < missing.length; i += BATCH) { - const chunk = missing.slice(i, i + BATCH) - try { - const res = await agent.getProfiles({actors: chunk}) + for (let i = 0; i < missing.length; i += BATCH) { + const chunk = missing.slice(i, i + BATCH) + agent + .getProfiles({actors: chunk}) + .then(res => { setProfiles(prev => { const next = new Map(prev) for (const p of res.data.profiles) next.set(p.did, p) return next }) - } catch { + }) + .catch(() => { chunk.forEach(d => requested.current.delete(d)) - } - } - })() + }) + } }, [dids, agent]) return profiles diff --git a/src/screens/StreamplaceWatch/index.tsx b/src/screens/StreamplaceWatch/index.tsx index c7e5eee61..64c9abddc 100644 --- a/src/screens/StreamplaceWatch/index.tsx +++ b/src/screens/StreamplaceWatch/index.tsx @@ -1,6 +1,7 @@ import {useEffect, useMemo} from 'react' import {Pressable, View} from 'react-native' -import {KeyboardAvoidingView} from 'react-native-keyboard-controller' +import {useKeyboardState} from 'react-native-keyboard-controller' +import {useSafeAreaInsets} from 'react-native-safe-area-context' import {moderateProfile} from '@atproto/api' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' @@ -24,6 +25,7 @@ import {EmbedConsentDialog} from '#/components/dialogs/EmbedConsent' import * as Layout from '#/components/Layout' import {Text} from '#/components/Typography' import {useAnalytics} from '#/analytics' +import {IS_NATIVE} from '#/env' import {ChatComposer} from '#/features/streamplace/ChatComposer' import {ChatList} from '#/features/streamplace/ChatList' import {LivePlayer} from '#/features/streamplace/LivePlayer' @@ -145,6 +147,10 @@ function Watch({actor}: {actor: string}) { ) const visibleChat = useMemo(() => visible.map(v => v.message), [visible]) const {pending, send} = useSendChat(did, visibleChat) + const {bottom} = useSafeAreaInsets() + const keyboardVisible = useKeyboardState(s => s.isVisible) + const keyboardHeight = useKeyboardState(s => s.height) + const typing = IS_NATIVE && keyboardVisible useEffect(() => { ax.metric('live:watch:open', {subject: actor}) @@ -168,7 +174,11 @@ function Watch({actor}: {actor: string}) { ) : null return ( - + {did ? ( ) : ( @@ -176,29 +186,29 @@ function Watch({actor}: {actor: string}) { style={[a.w_full, {aspectRatio: 16 / 9, backgroundColor: 'black'}]} /> )} - { - navigation.push('Profile', {name: profile?.did ?? actor}) - }} - /> - - Live chat - - - {chat} - + {!typing && ( + <> + { + navigation.push('Profile', {name: profile?.did ?? actor}) + }} + /> + + Live chat + + + )} + {chat} ) } -- knotmirror 0.0.1