Skip to content

Commit 0a7cd8a

Browse files
committed
fix(android): returning to the PR list keeps its place and its bars
Three things moved the PR list when switching back to it: - The PR header used the 64dp native app bar while Chats uses the 56dp list toolbar, so the floating header's padding changed after mount and nudged the list. The PR header now uses the list toolbar height. - Restoring the saved position fired a scroll that hid the bars. Until the list is dragged, scroll events now only move the anchor. - The restore used an index anchor, and LegendList adds the list header to index restores, so every return landed one header lower. It now restores the plain offset, like the chat list, and the unused anchor API is gone.
1 parent 2956dd8 commit 0a7cd8a

7 files changed

Lines changed: 37 additions & 40 deletions

File tree

‎apps/mobile/src/components/ui/AndroidScreenHeader.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export function AndroidScreenHeader(props: {
4646
readonly hideBottomBorder?: boolean;
4747
/** One row: the subtitle follows the title, for screens short on height. */
4848
readonly compact?: boolean;
49+
/**
50+
* Matches the thread list toolbar's height, so switching between list tabs keeps the
51+
* header and the content below it in place.
52+
*/
53+
readonly listToolbar?: boolean;
4954
}) {
5055
const { colors } = useControlTheme();
5156
const titleTypography = useScaledTextRole("title");
@@ -69,6 +74,7 @@ export function AndroidScreenHeader(props: {
6974
>
7075
<NativeAppBar
7176
singleLine={props.compact}
77+
listToolbar={props.listToolbar}
7278
navigationIcon={
7379
props.onBack || props.leading ? (
7480
<View collapsable={false} className="flex-row items-center">

‎apps/mobile/src/components/ui/NativeAppBar.android.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export function NativeAppBar(props: {
1212
readonly actions?: ReactElement;
1313
/** Shorter bar for a one-row title; Compose centers the fixed-height bar inside it. */
1414
readonly singleLine?: boolean;
15+
/** Use the shared list toolbar height instead of Material's 64dp minimum. */
16+
readonly listToolbar?: boolean;
1517
}) {
1618
const { colors } = useControlTheme();
1719
const layout = useToolbarLayout(false, props.singleLine);
@@ -21,7 +23,9 @@ export function NativeAppBar(props: {
2123
applyWindowInsets={false}
2224
modifiers={[
2325
fillMaxWidth(),
24-
height(props.singleLine ? layout.height : Math.max(64, layout.height)),
26+
height(
27+
props.singleLine || props.listToolbar ? layout.height : Math.max(64, layout.height),
28+
),
2529
]}
2630
colors={{
2731
containerColor: colors["--color-header"],

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,11 @@ export function HomeScreen(props: HomeScreenProps) {
313313
}, []);
314314

315315
const chrome = useCompactWorkspaceChrome();
316+
const chromeDragBegin = chrome?.onScrollBeginDrag;
316317
const handleScrollBeginDrag = useCallback(() => {
317318
openSwipeableRef.current?.close();
318-
}, []);
319+
chromeDragBegin?.();
320+
}, [chromeDragBegin]);
319321
const onFabScroll = useFabScroll();
320322
const listRef = useRef<LegendListRef>(null);
321323
const searchMode = workspace?.state.tabs.threads.searchMode;

‎apps/mobile/src/features/pull-requests/PullRequestToolbar.android.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export function PullRequestToolbar(props: { readonly onRequestVisibility?: () =>
5757
}, [searching, closeSearch, listFocused, navigation, isTabActive]);
5858
return (
5959
<AndroidScreenHeader
60+
listToolbar
6061
title="Pull requests"
6162
titleContent={
6263
searching ? (

‎apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx‎

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export function PullRequestsScreen(
6868
const configs = useAtomValue(environmentServerConfigsAtom);
6969
const insets = useSafeAreaInsets();
7070
const [initialOffset] = useState(() => workspace.getScrollOffset("pullRequests"));
71-
const [initialAnchor] = useState(() => workspace.getScrollAnchor("pullRequests"));
7271
const listRef = useRef<LegendListRef>(null);
7372
const tab = workspace.state.tabs.pullRequests;
7473
const maintainVisiblePosition = useMemo(
@@ -211,9 +210,6 @@ export function PullRequestsScreen(
211210
animated: false,
212211
});
213212
}, [tab.searchMode, tab.scrollOffset, insets.top]);
214-
const initialIndex = initialAnchor
215-
? entries.findIndex((entry) => pullRequestKey(entry) === initialAnchor.key)
216-
: -1;
217213

218214
return (
219215
<View className={sidebar ? "flex-1 bg-drawer" : "flex-1 bg-screen"}>
@@ -242,22 +238,17 @@ export function PullRequestsScreen(
242238
renderScrollComponent={Platform.OS === "ios" ? PullRequestScrollView : undefined}
243239
contentInsetAdjustmentBehavior="never"
244240
contentInset={Platform.OS === "ios" ? { top: insets.top } : undefined}
241+
// A plain offset: LegendList adds the list header to an index-based restore, which
242+
// landed every return one header lower.
245243
initialScrollOffset={
246-
!initialAnchor && initialOffset > 0
247-
? initialOffset - (Platform.OS === "ios" ? insets.top : 0)
248-
: undefined
249-
}
250-
initialScrollIndex={
251-
initialIndex >= 0 && initialAnchor
252-
? { index: initialIndex, viewOffset: initialAnchor.viewOffset, viewPosition: 0 }
253-
: undefined
244+
initialOffset > 0 ? initialOffset - (Platform.OS === "ios" ? insets.top : 0) : undefined
254245
}
255246
contentInsetStartAdjustment={Platform.OS === "ios" ? insets.top : 0}
256247
contentContainerStyle={{
257-
paddingTop: chrome?.headerHeight,
258248
paddingBottom:
259249
Math.max(insets.bottom, workspace.bottomClearance) + (chrome?.barHeight ?? 0),
260250
}}
251+
onScrollBeginDrag={chrome?.onScrollBeginDrag}
261252
onScroll={(event) => {
262253
chromeScroll?.(event);
263254
workspace.recordScrollOffset(
@@ -267,19 +258,13 @@ export function PullRequestsScreen(
267258
event.nativeEvent.contentOffset.y + (Platform.OS === "ios" ? insets.top : 0),
268259
),
269260
);
270-
const list = listRef.current?.getState();
271-
const item = list ? entries[list.start] : undefined;
272-
if (list && item)
273-
workspace.recordScrollAnchor("pullRequests", {
274-
key: pullRequestKey(item),
275-
viewOffset: list.positionAtIndex(list.start) - event.nativeEvent.contentOffset.y,
276-
});
277261
}}
278262
keyboardDismissMode="on-drag"
279263
keyboardShouldPersistTaps="handled"
280264
renderItem={renderPullRequest}
281265
ListHeaderComponent={
282-
<>
266+
<View>
267+
{chrome ? <View style={{ height: chrome.headerHeight }} /> : null}
283268
<PullRequestListFilters
284269
sidebar={sidebar}
285270
environments={environments.map((item) => ({
@@ -314,7 +299,7 @@ export function PullRequestsScreen(
314299
.join("\n")}
315300
</Text>
316301
) : null}
317-
</>
302+
</View>
318303
}
319304
ListFooterComponent={
320305
result.loadingMore ? (

‎apps/mobile/src/features/workspace/CompactWorkspaceChrome.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface CompactWorkspaceChrome {
3636
/** The window's bottom inset, which the content no longer sees under the bottom bar. */
3737
readonly bottomInset: number;
3838
readonly onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
39+
readonly onScrollBeginDrag: () => void;
3940
readonly setHeaderHeight: (height: number) => void;
4041
readonly setBarHeight: (height: number) => void;
4142
}
@@ -47,7 +48,9 @@ const CompactWorkspaceChromeContext = createContext<CompactWorkspaceChrome | nul
4748
* them back on the first scroll up, on the same cue that collapses the New thread FAB.
4849
* Both bars float over a list that never moves: a list that shifted under a dragging
4950
* finger would read the shift as a scroll the other way and flip the bars back.
50-
* Changing `resetKey` (the selected tab) shows the chrome again.
51+
* Changing `resetKey` (the selected tab) shows the chrome again. Until the list is
52+
* dragged after that, scroll events only move the anchor, so restoring a tab's saved
53+
* position doesn't read as a scroll down and hide the bars.
5154
*/
5255
export function CompactWorkspaceChromeProvider(props: {
5356
readonly resetKey: string;
@@ -60,8 +63,10 @@ export function CompactWorkspaceChromeProvider(props: {
6063
const [headerHeight, setHeaderHeight] = useState(0);
6164
const [barHeight, setBarHeightState] = useState(0);
6265
const scrollState = useRef({ anchor: 0, expanded: true });
66+
const dragged = useRef(false);
6367
useEffect(() => {
6468
scrollState.current = { anchor: 0, expanded: true };
69+
dragged.current = false;
6570
hidden.value = withTiming(0, CHROME_TIMING);
6671
setExpanded(true);
6772
}, [hidden, props.resetKey]);
@@ -75,6 +80,10 @@ export function CompactWorkspaceChromeProvider(props: {
7580
const onScroll = useCallback(
7681
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
7782
const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
83+
if (!dragged.current) {
84+
scrollState.current = { anchor: Math.max(0, contentOffset.y), expanded: true };
85+
return;
86+
}
7887
const next = updateFabScroll(
7988
scrollState.current,
8089
contentOffset.y,
@@ -88,6 +97,9 @@ export function CompactWorkspaceChromeProvider(props: {
8897
},
8998
[hidden],
9099
);
100+
const onScrollBeginDrag = useCallback(() => {
101+
dragged.current = true;
102+
}, []);
91103
return (
92104
<CompactWorkspaceChromeContext
93105
value={{
@@ -98,6 +110,7 @@ export function CompactWorkspaceChromeProvider(props: {
98110
barHeightValue,
99111
bottomInset: props.bottomInset,
100112
onScroll,
113+
onScrollBeginDrag,
101114
setHeaderHeight,
102115
setBarHeight,
103116
}}

‎apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,13 @@ import {
1717
type WorkspaceTabsState,
1818
} from "./workspace-tabs-state";
1919

20-
export interface WorkspaceScrollAnchor {
21-
readonly key: string;
22-
readonly viewOffset: number;
23-
}
24-
2520
export const WorkspaceTabsContext = createContext<{
2621
readonly state: WorkspaceTabsState;
2722
readonly dispatch: Dispatch<WorkspaceTabsAction>;
2823
readonly isTabActive: (tab: WorkspaceTab) => boolean;
2924
readonly bottomClearance: number;
3025
readonly getScrollOffset: (tab: WorkspaceTab) => number;
3126
readonly recordScrollOffset: (tab: WorkspaceTab, offset: number) => void;
32-
readonly getScrollAnchor: (tab: WorkspaceTab) => WorkspaceScrollAnchor | undefined;
33-
readonly recordScrollAnchor: (tab: WorkspaceTab, anchor: WorkspaceScrollAnchor) => void;
3427
} | null>(null);
3528

3629
export function useWorkspaceTabs() {
@@ -45,15 +38,10 @@ export function WorkspaceTabsProvider(props: { readonly children: ReactNode }) {
4538
}, [state.selectedTab]);
4639
const isTabActive = useCallback((tab: WorkspaceTab) => activeTab.current === tab, []);
4740
const scrollOffsets = useRef({ threads: 0, pullRequests: 0, settings: 0 });
48-
const scrollAnchors = useRef<Partial<Record<WorkspaceTab, WorkspaceScrollAnchor>>>({});
4941
const getScrollOffset = useCallback((tab: WorkspaceTab) => scrollOffsets.current[tab], []);
5042
const recordScrollOffset = useCallback((tab: WorkspaceTab, offset: number) => {
5143
scrollOffsets.current[tab] = offset;
5244
}, []);
53-
const getScrollAnchor = useCallback((tab: WorkspaceTab) => scrollAnchors.current[tab], []);
54-
const recordScrollAnchor = useCallback((tab: WorkspaceTab, anchor: WorkspaceScrollAnchor) => {
55-
scrollAnchors.current[tab] = anchor;
56-
}, []);
5745
const context = useMemo(
5846
() => ({
5947
state,
@@ -62,10 +50,8 @@ export function WorkspaceTabsProvider(props: { readonly children: ReactNode }) {
6250
bottomClearance: 0,
6351
getScrollOffset,
6452
recordScrollOffset,
65-
getScrollAnchor,
66-
recordScrollAnchor,
6753
}),
68-
[state, isTabActive, getScrollOffset, recordScrollOffset, getScrollAnchor, recordScrollAnchor],
54+
[state, isTabActive, getScrollOffset, recordScrollOffset],
6955
);
7056
return <WorkspaceTabsContext value={context}>{props.children}</WorkspaceTabsContext>;
7157
}

0 commit comments

Comments
 (0)