Skip to content
TypeScript

fix(mobile): the iPhone Duo's search field and composer line up with its tab bar (#23148)

Julius Marmingee6c2aeb3608d
diff --git a/apps/mobile/modules/t3-native-controls/ios/T3LayoutMetricsView.swift b/apps/mobile/modules/t3-native-controls/ios/T3LayoutMetricsView.swift
index 936efe7676e..b970936b1fe 100644
--- a/apps/mobile/modules/t3-native-controls/ios/T3LayoutMetricsView.swift
+++ b/apps/mobile/modules/t3-native-controls/ios/T3LayoutMetricsView.swift
@@ -69,6 +69,7 @@ final class T3LayoutMetricsView: ExpoView {
}
var verticalBarEdge = "none"
var regions: [[String: Any]] = []
+ var bottomBarInset: CGFloat?
#if canImport(UIKit, _version: 9127.0.85)
if #available(iOS 27.1, *) {
let rtl = effectiveUserInterfaceLayoutDirection == .rightToLeft
@@ -77,6 +78,8 @@ final class T3LayoutMetricsView: ExpoView {
case .trailing: verticalBarEdge = rtl ? "left" : "right"
default: break
}
+ // Where UIKit floats a bar as tall as the app's bottom controls, level with its tab bar.
+ bottomBarInset = edgeInsets(for: .bar(onEdge: UIRectEdge.bottom, extent: 48)).bottom
for kind in [UIView.ReservedRegion.Kind.division, .occlusion] {
for region in reservedRegions(kind: kind) where region.isActive {
let frame = region.frame.intersection(bounds)
@@ -90,7 +93,7 @@ final class T3LayoutMetricsView: ExpoView {
}
}
#endif
- let metrics: [String: Any] = [
+ var metrics: [String: Any] = [
"width": bounds.width, "height": bounds.height,
"hasHinge": hasHinge,
"horizontalSizeClass": traitCollection.horizontalSizeClass == .regular ? "regular" : "compact",
@@ -101,6 +104,7 @@ final class T3LayoutMetricsView: ExpoView {
],
"reservedRegions": regions,
]
+ metrics["bottomBarInset"] = bottomBarInset
let next = metrics as NSDictionary
guard lastMetrics?.isEqual(next) != true else { return }
lastMetrics = next
diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsx
index 1df4dcab7e4..a55498552b4 100644
--- a/apps/mobile/src/features/threads/ThreadComposer.tsx
+++ b/apps/mobile/src/features/threads/ThreadComposer.tsx
@@ -349,6 +349,9 @@ export function ComposerSurface(props: {
);
}
+/** Space below the composer pill, inside the bottom inset it is given. */
+export const THREAD_COMPOSER_BOTTOM_GUTTER = 6;
+
export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps) {
const project = useProject(scopeProjectRef(props.environmentId, props.selectedThread.projectId));
const { themeVariables: materialTheme } = useAppearancePreferences();
@@ -804,7 +807,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
className="px-[12px]"
style={{
paddingTop: usesCard ? 8 : 6,
- paddingBottom: (props.bottomInset ?? 0) + (usesCard ? 8 : 6),
+ paddingBottom: (props.bottomInset ?? 0) + (usesCard ? 8 : THREAD_COMPOSER_BOTTOM_GUTTER),
backgroundColor:
Platform.OS === "android" ? themeColorWithAlpha(composerPanel, 1) : undefined,
}}
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
index 9741e464444..6961f742872 100644
--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
@@ -102,7 +102,10 @@ import Animated, {
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useWorkspaceContentWidth } from "../layout/workspace-content-width";
import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspaceColumns";
-import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
+import {
+ useDuoBottomBarInset,
+ useNativeColumnLayoutMetrics,
+} from "../../native/native-layout-metrics";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
import { collectProviderUsageLimits } from "@t3tools/shared/usageLimits";
import type { ComposerEditorHandle } from "../../components/ComposerEditor";
@@ -159,6 +162,7 @@ import {
COMPOSER_EXPANDED_CHROME,
COMPOSER_LAYOUT_TRANSITION,
COMPOSER_TRANSITION_DURATION_MS,
+ THREAD_COMPOSER_BOTTOM_GUTTER,
ThreadComposer,
} from "./ThreadComposer";
import { ComposerPopoverHost } from "./ComposerPopoverHost";
@@ -536,10 +540,13 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
const [endFollowEnabled, setEndFollowEnabled] = useState(true);
// Android Back hides the keyboard without blurring. Keep its safe-area padding
// fixed through the animation and cancel it with matching composer/list offsets.
+ const bottomBarInset = useDuoBottomBarInset();
const composerBottomInset =
Platform.OS === "ios" && (composerExpanded || composerFocused)
? 0
- : Math.max(insets.bottom, 12);
+ : bottomBarInset !== undefined
+ ? bottomBarInset - THREAD_COMPOSER_BOTTOM_GUTTER
+ : Math.max(insets.bottom, 12);
const composerKeyboardOffset = Platform.OS === "android" ? composerBottomInset : 0;
const contentPresentationKind = props.contentPresentation.kind;
const realThreadSyncLabel = (() => {
diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
index b27c028b4cc..97a11068057 100644
--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
@@ -11,6 +11,7 @@ import { NativeStackScreenOptions } from "../../native/StackHeader";
import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
import {
useDeviceType,
+ useDuoBottomBarInset,
useNativeColumnLayoutMetrics,
useNativeLayoutMetrics,
} from "../../native/native-layout-metrics";
@@ -70,6 +71,7 @@ function WorkspaceRootContent() {
(nativeMetrics !== null && nativeMetrics.verticalBarEdge !== "none"));
const width = columnMetrics?.width ?? windowWidth;
const insets = useSafeAreaInsets();
+ const bottomBarInset = useDuoBottomBarInset();
const keyboardHeight = useKeyboardState((keyboard) => keyboard.height);
const workspace = useWorkspaceTabs()!;
const { state } = workspace;
@@ -90,7 +92,9 @@ function WorkspaceRootContent() {
const tab = state.tabs[state.selectedTab];
const bottomClearance =
Platform.OS === "ios" && isDuoDevice(deviceType)
- ? Math.max(insets.bottom, 12, keyboardHeight + 8) + WORKSPACE_TOOLBAR.height + 16
+ ? Math.max(bottomBarInset ?? Math.max(insets.bottom, 12), keyboardHeight + 8) +
+ WORKSPACE_TOOLBAR.height +
+ 16
: Platform.OS === "ios"
? Math.max(insets.bottom, keyboardHeight) +
(systemTabBar || sidebarTabs || tab.searchMode !== "resting"
diff --git a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
index a500826522b..00febb5781f 100644
--- a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
@@ -6,7 +6,7 @@ import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller
import Animated, { useAnimatedStyle } from "react-native-reanimated";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { isDuoDevice } from "../../lib/device-type";
-import { useDeviceType } from "../../native/native-layout-metrics";
+import { useDeviceType, useDuoBottomBarInset } from "../../native/native-layout-metrics";
import type { SearchBarCommands } from "react-native-screens";
import { SymbolView } from "../../components/ui/AppSymbol";
@@ -75,6 +75,7 @@ export function WorkspaceToolbar(props: {
// each fold replaces the search field.
const listSearch = isDuoDevice(deviceType);
const insets = useSafeAreaInsets();
+ const bottomBarInset = useDuoBottomBarInset();
const { isTabActive } = workspace;
const tabActive = use(NativeWorkspaceTabActivityContext)?.active ?? true;
const { panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
@@ -216,7 +217,7 @@ export function WorkspaceToolbar(props: {
) : null}
</Toolbar>
{listSearch ? (
- <AboveKeyboard bottom={Math.max(insets.bottom, 12)}>
+ <AboveKeyboard bottom={bottomBarInset ?? Math.max(insets.bottom, 12)}>
<WorkspaceSearchField
ref={fieldRef}
tab={selectedTab}
diff --git a/apps/mobile/src/lib/reserved-regions.ts b/apps/mobile/src/lib/reserved-regions.ts
index c212dffd311..f88af9239c3 100644
--- a/apps/mobile/src/lib/reserved-regions.ts
+++ b/apps/mobile/src/lib/reserved-regions.ts
@@ -19,6 +19,8 @@ export interface NativeLayoutMetrics {
readonly right: number;
};
readonly reservedRegions: ReadonlyArray<ReservedRegion>;
+ /** How far above the bottom edge UIKit floats a 48pt bottom bar, level with its tab bar. iOS 27.1+. */
+ readonly bottomBarInset?: number;
}
export function deriveBottomControlInsets(metrics: NativeLayoutMetrics | null) {
diff --git a/apps/mobile/src/native/native-layout-metrics.tsx b/apps/mobile/src/native/native-layout-metrics.tsx
index 44d12142d52..195e7a2cec0 100644
--- a/apps/mobile/src/native/native-layout-metrics.tsx
+++ b/apps/mobile/src/native/native-layout-metrics.tsx
@@ -1,6 +1,6 @@
import { createContext, use, useState, type ReactNode } from "react";
import { Platform } from "react-native";
-import { deriveDeviceType, type DeviceType } from "../lib/device-type";
+import { deriveDeviceType, isDuoDevice, type DeviceType } from "../lib/device-type";
import type { NativeLayoutMetrics } from "../lib/reserved-regions";
import { NativeLayoutObserver } from "./NativeLayoutObserver";
@@ -38,3 +38,13 @@ export function useNativeColumnLayoutMetrics() {
export function useDeviceType() {
return use(DeviceTypeContext);
}
+
+/**
+ * Where the Duo's floating bottom controls end in this column. Its tab bar floats below the safe
+ * area, and the controls beside it sit on the same line.
+ */
+export function useDuoBottomBarInset() {
+ const deviceType = useDeviceType();
+ const inset = use(NativeColumnLayoutMetricsContext)?.bottomBarInset;
+ return isDuoDevice(deviceType) ? inset : undefined;
+}