Skip to content

Commit 9d74cc2

Browse files
fix(mobile): keep usage tabs below the header when switching
1 parent 7f8cf30 commit 9d74cc2

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

‎apps/mobile/src/features/usage/UsageRouteScreen.tsx‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
formatUsd,
1212
makeWindow,
1313
} from "@t3tools/shared/usageFormat";
14-
import { useMemo, useRef, useState } from "react";
14+
import { useMemo, useState } from "react";
1515
import { Platform, Pressable, RefreshControl, ScrollView, View } from "react-native";
1616
import { useSafeAreaInsets } from "react-native-safe-area-context";
1717

@@ -96,14 +96,6 @@ export function UsageRouteScreen() {
9696
// environment stays pending forever — neither may pin the spinner on.
9797
const refreshingUsage = environments.some((entry) => entry.isPending && entry.summary !== null);
9898
const showingLimits = tab === "limits";
99-
// One ScrollView serves both tabs, so the offset would otherwise carry over
100-
// and a short Limits list could open scrolled past its own content.
101-
const scrollRef = useRef<ScrollView>(null);
102-
const selectTab = (next: UsageTab) => {
103-
if (next === tab) return;
104-
setTab(next);
105-
scrollRef.current?.scrollTo({ y: 0, animated: false });
106-
};
10799
const selectWindow = (days: number) => {
108100
setWindowSelection({
109101
days,
@@ -133,7 +125,9 @@ export function UsageRouteScreen() {
133125
</>
134126
) : null}
135127
<ScrollView
136-
ref={scrollRef}
128+
// Remount at each tab's native top. Scrolling to y: 0 ignores iOS's
129+
// automatic header inset and hides the tab bar under the header.
130+
key={tab}
137131
contentInsetAdjustmentBehavior="automatic"
138132
showsVerticalScrollIndicator={false}
139133
className="flex-1"
@@ -146,7 +140,7 @@ export function UsageRouteScreen() {
146140
/>
147141
}
148142
>
149-
<SegmentedControl options={TAB_OPTIONS} selected={tab} onSelect={selectTab} role="tab" />
143+
<SegmentedControl options={TAB_OPTIONS} selected={tab} onSelect={setTab} role="tab" />
150144

151145
{showingLimits ? (
152146
<UsageLimitsSection now={limits.now} failedLabels={limits.failedLabels} />

0 commit comments

Comments
 (0)