[Chat] Persist left column scroll in splitview (#10513)

This commit is contained in:
Samuel Newman
2026-05-18 18:47:41 +01:00
committed by GitHub
parent b1ce519361
commit e40c9bcf98
3 changed files with 43 additions and 6 deletions
@@ -1,8 +1,11 @@
import {useCallback} from 'react'
import {View} from 'react-native'
import {type ReanimatedScrollEvent} from 'react-native-reanimated/lib/typescript/hook/commonTypes'
import {type ScreenLayoutArgs, useIsFocused} from '@react-navigation/native'
import {type NativeStackNavigationProp} from '@react-navigation/native-stack'
import {type FlatNavigatorParams} from '#/lib/routes/types'
import {ScrollProvider} from '#/lib/ScrollContext'
import {type NativeStackNavigationOptionsWithAuth} from '#/view/shell/createNativeStackNavigatorWithAuth'
import {atoms as a, useLayoutBreakpoints, useTheme, web} from '#/alf'
import {useDialogControl} from '#/components/Dialog'
@@ -13,6 +16,7 @@ import {useAgeAssurance} from '#/ageAssurance'
import {IS_WEB} from '#/env'
import {ChatList, Header as ChatListHeader} from '../../ChatList'
import {SplitViewProvider} from './context'
import {splitViewLeftScroll} from './leftColumnScroll'
const CENTER_COLUMN_WIDTH = 600
const LEFT_NAV_FULL_WIDTH = 245
@@ -48,6 +52,11 @@ function MessagesSplitViewLayout({children, navigation, route}: LayoutProps) {
const aa = useAgeAssurance()
const isFocused = useIsFocused()
const onLeftColumnScroll = useCallback((e: ReanimatedScrollEvent) => {
'worklet'
splitViewLeftScroll.current = e.contentOffset.y
}, [])
if (!IS_WEB || !rightNavVisible || aa.state.access !== aa.Access.Full) {
return children
}
@@ -106,10 +115,12 @@ function MessagesSplitViewLayout({children, navigation, route}: LayoutProps) {
{width: containerWidth - centerColumnWidth},
]}>
<ChatListHeader newChatControl={newChatControl} />
<ChatList
newChatControl={newChatControl}
selectedChat={selectedChat}
/>
<ScrollProvider onScroll={onLeftColumnScroll}>
<ChatList
newChatControl={newChatControl}
selectedChat={selectedChat}
/>
</ScrollProvider>
<NewChat onNewChat={onNewChat} control={newChatControl} />
</View>
</SplitViewProvider>
@@ -0,0 +1,4 @@
// Holds the splitview left column's scroll offset across re-mounts caused
// by in-splitview navigation. Reset on full page reload, mirroring the
// in-memory semantics of useWebScrollRestoration.
export const splitViewLeftScroll = {current: 0}