Skip to content
TypeScript

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

Julius Marmingeac90950f1ac3
diff --git a/apps/mobile/src/features/usage/UsageRouteScreen.tsx b/apps/mobile/src/features/usage/UsageRouteScreen.tsx
index be7c36173f1..17841cbd74f 100644
--- a/apps/mobile/src/features/usage/UsageRouteScreen.tsx
+++ b/apps/mobile/src/features/usage/UsageRouteScreen.tsx
@@ -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} />