Skip to content
TypeScript

fix(mobile): respect Duo safe areas in overlays (#22977)

Julius Marmingeec2fd4d37c34
diff --git a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
index 368c3286e35..3e5899f870a 100644
--- a/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
+++ b/apps/mobile/src/features/devices/DevicePreviewRouteScreen.tsx
@@ -27,6 +27,8 @@ import {
findHeaderMenuAction,
} from "../../components/ui/headerMenu.android";
import type { AppBarMenuItem } from "../../components/ui/AppBar.types";
+import { deriveBottomControlInsets } from "../../lib/reserved-regions";
+import { useNativeColumnLayoutMetrics } from "../../native/native-layout-metrics";
import { deviceEnvironment, refreshDeviceHubAccess, useDeviceHubAccess } from "../../state/device";
import { useEnvironmentQuery } from "../../state/query";
import { useAtomCommand } from "../../state/use-atom-command";
@@ -75,6 +77,8 @@ function DevicePreviewScreen({
readonly onClose: () => void;
}) {
const insets = useSafeAreaInsets();
+ // NativeColumnContent already insets the sides, so only a book fold moves the reveal handle.
+ const handleBounds = deriveBottomControlInsets(useNativeColumnLayoutMetrics());
const { themeVariables } = useAppearancePreferences();
const focused = useIsFocused();
const [foreground, setForeground] = useState(AppState.currentState !== "background");
@@ -318,7 +322,10 @@ function DevicePreviewScreen({
accessibilityHint="Shaking the phone also shows them"
hitSlop={12}
className="absolute h-6 w-16 items-center justify-center self-center"
- style={{ top: Math.max(insets.top - 18, 4) }}
+ style={{
+ top: Math.max(insets.top - 18, 4),
+ transform: [{ translateX: (handleBounds.left - handleBounds.right) / 2 }],
+ }}
onPress={() => setControlsVisible(true)}
>
<View className="h-1.5 w-10 rounded-full bg-white/40" />
diff --git a/apps/mobile/src/features/keyboard/CommandPalette.tsx b/apps/mobile/src/features/keyboard/CommandPalette.tsx
index d264c0765bc..3c3fd349c20 100644
--- a/apps/mobile/src/features/keyboard/CommandPalette.tsx
+++ b/apps/mobile/src/features/keyboard/CommandPalette.tsx
@@ -22,7 +22,9 @@ import { RowPressable } from "../../components/ui/RowPressable";
import { AppText as Text } from "../../components/ui/AppText";
import { SymbolView, type AppSymbolName } from "../../components/ui/AppSymbol";
import { cn } from "../../lib/cn";
+import { deriveBottomControlInsets } from "../../lib/reserved-regions";
import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
+import { useNativeLayoutMetrics } from "../../native/native-layout-metrics";
import { T3KeyboardCommands } from "../../native/T3KeyboardCommands";
import { useProjects, useThreadShell, useThreadShells } from "../../state/entities";
import { useThreadSearch } from "../../state/queries";
@@ -156,6 +158,9 @@ export function CommandPalette(props: {
const inputRef = useRef<TextInputInstance>(null);
const listRef = useRef<FlatList<CommandPaletteItem>>(null);
const { width, height } = useWindowDimensions();
+ // The palette floats above every column, so it keeps itself inside the window's side insets
+ // and to one side of a book fold.
+ const bounds = deriveBottomControlInsets(useNativeLayoutMetrics());
const searchEnvironmentIds = useMemo(
() =>
environments
@@ -423,7 +428,8 @@ export function CommandPalette(props: {
<T3KeyboardCommands enabledCommands={PALETTE_COMMANDS} onCommand={onCommand}>
<KeyboardAvoidingView
behavior="padding"
- className="flex-1 items-center justify-center p-4"
+ className="flex-1 items-center justify-center py-4"
+ style={{ paddingLeft: 16 + bounds.left, paddingRight: 16 + bounds.right }}
>
<Pressable
className="absolute inset-0 bg-backdrop"
@@ -436,7 +442,7 @@ export function CommandPalette(props: {
tintColorClassName="accent-sheet/20"
fallbackColor={themeVariables["--color-sheet"]}
style={{
- width: Math.min(600, width - 32),
+ width: Math.min(600, width - 32 - bounds.left - bounds.right),
height: Math.min(520, height - 80),
borderRadius: 20,
}}
diff --git a/apps/mobile/src/features/settings/components/SettingsEnvironmentFilterHeader.tsx b/apps/mobile/src/features/settings/components/SettingsEnvironmentFilterHeader.tsx
index b2a03f0cbd5..bbc8515f04c 100644
--- a/apps/mobile/src/features/settings/components/SettingsEnvironmentFilterHeader.tsx
+++ b/apps/mobile/src/features/settings/components/SettingsEnvironmentFilterHeader.tsx
@@ -54,7 +54,6 @@ export function SettingsEnvironmentFilterHeader(props: {
options={{
unstable_headerRightItems: () => [
withNativeGlassHeaderItem({
- axisBehavior: "horizontalOnly",
accessibilityLabel: "Filter settings environments and projects",
icon: { name: filterIcon, type: "sfSymbol" },
label: "",
@@ -121,7 +120,6 @@ export function SettingsEnvironmentFilterHeader(props: {
...(closeSettings
? [
withNativeGlassHeaderItem({
- axisBehavior: "horizontalOnly",
accessibilityLabel: "Close settings",
icon: { name: "xmark", type: "sfSymbol" },
identifier: "settings-close",
diff --git a/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx b/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
index 77ecc530b90..447254e2bbf 100644
--- a/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
+++ b/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
@@ -9,7 +9,7 @@ import { Animated, FlatList, Modal, Pressable, View } from "react-native";
import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";
import Reanimated, { ReduceMotion, useAnimatedStyle, withTiming } from "react-native-reanimated";
import { threadDragGapOffset } from "./threadDragGap";
-import { useSafeAreaInsets } from "react-native-safe-area-context";
+import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import { AppText as Text } from "../../components/ui/AppText";
import { SymbolView } from "../../components/ui/AppSymbol";
@@ -149,7 +149,6 @@ function DragHandle(props: {
}
export function ThreadArrangementSheet(props: { onClose: () => void }) {
- const insets = useSafeAreaInsets();
const threads = useAtomValue(environmentThreadShells.navigationThreadShellsAtom);
const configs = useAtomValue(environmentServerConfigsAtom);
const queuedThreadKeys = useAtomValue(queuedThreadKeysAtom);
@@ -373,184 +372,187 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
onRequestClose={props.onClose}
>
<GestureHandlerRootView style={{ flex: 1 }}>
- <View
- className="flex-1 bg-screen"
- style={{ paddingTop: insets.top, paddingBottom: insets.bottom }}
- >
- <SheetHeader
- presentation="inline"
- title="Arrange threads"
- onClose={props.onClose}
- accessibilityLabel="Close arrange threads"
- />
- <Text className="px-5 pb-3 text-sm text-foreground-muted">
- Drag to reorder, pin, or settle. Changes save when you drop.
- </Text>
- <View
- onLayout={(event) => {
- geometry.current.height = event.nativeEvent.layout.height;
- }}
- className="flex-1"
- style={{ overflow: "hidden" }}
- >
- <FlatList
- ref={list}
- data={rows}
- keyExtractor={(row) => row.key}
- scrollEnabled={visiblePreview === null}
- removeClippedSubviews={false}
- onScroll={(event) => {
- geometry.current.offset = event.nativeEvent.contentOffset.y;
- }}
- scrollEventThrottle={16}
- getItemLayout={(_, index) => ({
- length: rows[index]!.height,
- offset: rows[index]!.offset,
- index,
- })}
- renderItem={({ item }) => {
- const thread = item.thread;
- const planner =
- item.section === "pinned" || item.section === "active"
- ? planners[item.section]
- : null;
- const capabilities =
- thread && configs.get(thread.environmentId)?.environment.capabilities;
- const sectionActions = thread
- ? (["pinned", "active", "settled"] as const).flatMap<{
- name: "pinned" | "active" | "settled";
- label: string;
- }>((section) => {
- if (section === item.section) return [];
- const label = threadDragAction(item.section, section);
- if (!label) return [];
- if (section === "settled")
- return capabilities?.threadSettlement ? [{ name: section, label }] : [];
- if (
- ((section === "pinned" || thread.pinnedAt != null) &&
- !capabilities?.threadPinning) ||
- (section === "active" &&
- item.section === "settled" &&
- !capabilities?.threadSettlement) ||
- (section === "active" &&
- item.section === "snoozed" &&
- !capabilities?.threadSnooze)
- )
- return [];
- return planners[section](item.key, {
- section,
- targetId: null,
- placement: "before",
- })
- ? [{ name: section, label }]
- : [];
- })
- : [];
- return (
- <ArrangementRow
- height={item.height}
- dragging={visiblePreview !== null}
- lifted={item.key === sourceRow?.key}
- offset={
- sourceRow && insertionOffset !== undefined
- ? threadDragGapOffset(
- item.offset,
- sourceRow.offset,
- sourceRow.height,
- insertionOffset,
+ {/* A Modal is its own native hierarchy, so measure its own safe area, including side
+ insets for the camera, instead of the presenting screen's. */}
+ <SafeAreaProvider style={{ flex: 1 }}>
+ <View className="flex-1 bg-screen">
+ <SafeAreaView style={{ flex: 1 }}>
+ <SheetHeader
+ presentation="inline"
+ title="Arrange threads"
+ onClose={props.onClose}
+ accessibilityLabel="Close arrange threads"
+ />
+ <Text className="px-5 pb-3 text-sm text-foreground-muted">
+ Drag to reorder, pin, or settle. Changes save when you drop.
+ </Text>
+ <View
+ onLayout={(event) => {
+ geometry.current.height = event.nativeEvent.layout.height;
+ }}
+ className="flex-1"
+ style={{ overflow: "hidden" }}
+ >
+ <FlatList
+ ref={list}
+ data={rows}
+ keyExtractor={(row) => row.key}
+ scrollEnabled={visiblePreview === null}
+ removeClippedSubviews={false}
+ onScroll={(event) => {
+ geometry.current.offset = event.nativeEvent.contentOffset.y;
+ }}
+ scrollEventThrottle={16}
+ getItemLayout={(_, index) => ({
+ length: rows[index]!.height,
+ offset: rows[index]!.offset,
+ index,
+ })}
+ renderItem={({ item }) => {
+ const thread = item.thread;
+ const planner =
+ item.section === "pinned" || item.section === "active"
+ ? planners[item.section]
+ : null;
+ const capabilities =
+ thread && configs.get(thread.environmentId)?.environment.capabilities;
+ const sectionActions = thread
+ ? (["pinned", "active", "settled"] as const).flatMap<{
+ name: "pinned" | "active" | "settled";
+ label: string;
+ }>((section) => {
+ if (section === item.section) return [];
+ const label = threadDragAction(item.section, section);
+ if (!label) return [];
+ if (section === "settled")
+ return capabilities?.threadSettlement ? [{ name: section, label }] : [];
+ if (
+ ((section === "pinned" || thread.pinnedAt != null) &&
+ !capabilities?.threadPinning) ||
+ (section === "active" &&
+ item.section === "settled" &&
+ !capabilities?.threadSettlement) ||
+ (section === "active" &&
+ item.section === "snoozed" &&
+ !capabilities?.threadSnooze)
)
- : 0
- }
- >
- {thread ? (
- <>
- <Text numberOfLines={2} className="flex-1 text-base">
- {thread.title}
- </Text>
- <DragHandle
- title={thread.title}
- disabled={
- dropBusy ||
- pendingOrder !== null ||
- !(
- configs.get(thread.environmentId)?.environment.capabilities
- .threadPinReorder ||
- configs.get(thread.environmentId)?.environment.capabilities
- .threadActiveReorder
- )
- }
- sectionActions={sectionActions}
- onSectionMove={(section) => {
- void moveThread(thread, {
- section,
- targetId: null,
- placement: "before",
- });
- }}
- canMoveUp={planner?.(item.key, "up") != null}
- canMoveDown={planner?.(item.key, "down") != null}
- onStep={(direction) => {
- void moveThread(thread, direction);
- }}
- onStart={() => start(item)}
- onMove={update}
- onEnd={(cancelled) => {
- const current = drag.current;
- if (cancelled || !current?.destination) {
- stop();
- return;
- }
- if (frame.current !== null) cancelAnimationFrame(frame.current);
- frame.current = null;
- drag.current = null;
- void moveThread(current.thread, current.destination).finally(stop);
- }}
- />
- </>
- ) : (
- <Pressable
- disabled={item.section === "pinned" || item.section === "active"}
- className="flex-1 justify-center self-stretch"
- onPress={() => {
- const section = item.section;
- if (section === "snoozed" || section === "settled")
- setExpanded((value) => ({ ...value, [section]: !value[section] }));
- }}
+ return [];
+ return planners[section](item.key, {
+ section,
+ targetId: null,
+ placement: "before",
+ })
+ ? [{ name: section, label }]
+ : [];
+ })
+ : [];
+ return (
+ <ArrangementRow
+ height={item.height}
+ dragging={visiblePreview !== null}
+ lifted={item.key === sourceRow?.key}
+ offset={
+ sourceRow && insertionOffset !== undefined
+ ? threadDragGapOffset(
+ item.offset,
+ sourceRow.offset,
+ sourceRow.height,
+ insertionOffset,
+ )
+ : 0
+ }
>
- <Text className="text-sm font-t3-semibold text-foreground-muted">
- {item.section[0]!.toUpperCase() + item.section.slice(1)} (
- {sections[item.section].length})
- </Text>
- </Pressable>
- )}
- </ArrangementRow>
- );
- }}
- />
- {visiblePreview ? (
- <Animated.View
- pointerEvents="none"
- className="absolute left-5 right-5 justify-center rounded-xl border border-border bg-screen px-4"
- style={{ top: 0, height: ROW_HEIGHT, transform: [{ translateY }] }}
- >
- <Text
- numberOfLines={visiblePreview.destination?.section ? 1 : 2}
- className="text-base font-t3-medium"
- >
- {visiblePreview.thread.title}
- </Text>
- {visiblePreview.destination?.section ? (
- <Text className="text-xs text-foreground-muted">
- {threadDragAction(
- visiblePreview.sourceSection,
- visiblePreview.destination.section,
- )}
- </Text>
+ {thread ? (
+ <>
+ <Text numberOfLines={2} className="flex-1 text-base">
+ {thread.title}
+ </Text>
+ <DragHandle
+ title={thread.title}
+ disabled={
+ dropBusy ||
+ pendingOrder !== null ||
+ !(
+ configs.get(thread.environmentId)?.environment.capabilities
+ .threadPinReorder ||
+ configs.get(thread.environmentId)?.environment.capabilities
+ .threadActiveReorder
+ )
+ }
+ sectionActions={sectionActions}
+ onSectionMove={(section) => {
+ void moveThread(thread, {
+ section,
+ targetId: null,
+ placement: "before",
+ });
+ }}
+ canMoveUp={planner?.(item.key, "up") != null}
+ canMoveDown={planner?.(item.key, "down") != null}
+ onStep={(direction) => {
+ void moveThread(thread, direction);
+ }}
+ onStart={() => start(item)}
+ onMove={update}
+ onEnd={(cancelled) => {
+ const current = drag.current;
+ if (cancelled || !current?.destination) {
+ stop();
+ return;
+ }
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
+ frame.current = null;
+ drag.current = null;
+ void moveThread(current.thread, current.destination).finally(stop);
+ }}
+ />
+ </>
+ ) : (
+ <Pressable
+ disabled={item.section === "pinned" || item.section === "active"}
+ className="flex-1 justify-center self-stretch"
+ onPress={() => {
+ const section = item.section;
+ if (section === "snoozed" || section === "settled")
+ setExpanded((value) => ({ ...value, [section]: !value[section] }));
+ }}
+ >
+ <Text className="text-sm font-t3-semibold text-foreground-muted">
+ {item.section[0]!.toUpperCase() + item.section.slice(1)} (
+ {sections[item.section].length})
+ </Text>
+ </Pressable>
+ )}
+ </ArrangementRow>
+ );
+ }}
+ />
+ {visiblePreview ? (
+ <Animated.View
+ pointerEvents="none"
+ className="absolute left-5 right-5 justify-center rounded-xl border border-border bg-screen px-4"
+ style={{ top: 0, height: ROW_HEIGHT, transform: [{ translateY }] }}
+ >
+ <Text
+ numberOfLines={visiblePreview.destination?.section ? 1 : 2}
+ className="text-base font-t3-medium"
+ >
+ {visiblePreview.thread.title}
+ </Text>
+ {visiblePreview.destination?.section ? (
+ <Text className="text-xs text-foreground-muted">
+ {threadDragAction(
+ visiblePreview.sourceSection,
+ visiblePreview.destination.section,
+ )}
+ </Text>
+ ) : null}
+ </Animated.View>
) : null}
- </Animated.View>
- ) : null}
+ </View>
+ </SafeAreaView>
</View>
- </View>
+ </SafeAreaProvider>
</GestureHandlerRootView>
</Modal>
);