fix(mobile): keep usage tabs below the header when switching (#9876)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-04 19:53:45 -07:00
1 parent 84b99f3fb7
commit ac90950f1a
1 file changed
+5 -11
@@ -11,7 +11,7 @@ import {
formatUsd,
makeWindow,
} from "@t3tools/shared/usageFormat";
import { useMemo, useRef, useState } from "react";
import { useMemo, useState } from "react";
import { Platform, Pressable, RefreshControl, ScrollView, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -96,14 +96,6 @@ export function UsageRouteScreen() {
// environment stays pending forever — neither may pin the spinner on.
const refreshingUsage = environments.some((entry) => entry.isPending && entry.summary !== null);
const showingLimits = tab === "limits";
// One ScrollView serves both tabs, so the offset would otherwise carry over
// and a short Limits list could open scrolled past its own content.
const scrollRef = useRef<ScrollView>(null);
const selectTab = (next: UsageTab) => {
if (next === tab) return;
setTab(next);
scrollRef.current?.scrollTo({ y: 0, animated: false });
};
const selectWindow = (days: number) => {
setWindowSelection({
days,
@@ -133,7 +125,9 @@ export function UsageRouteScreen() {
</>
) : null}
<ScrollView
ref={scrollRef}
// Remount at each tab's native top. Scrolling to y: 0 ignores iOS's
// automatic header inset and hides the tab bar under the header.
key={tab}
contentInsetAdjustmentBehavior="automatic"
showsVerticalScrollIndicator={false}
className="flex-1"
@@ -146,7 +140,7 @@ export function UsageRouteScreen() {
/>
}
>
<SegmentedControl options={TAB_OPTIONS} selected={tab} onSelect={selectTab} role="tab" />
<SegmentedControl options={TAB_OPTIONS} selected={tab} onSelect={setTab} role="tab" />
{showingLimits ? (
<UsageLimitsSection now={limits.now} failedLabels={limits.failedLabels} />