Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): stabilize home device title layout when switching devices

DavidShenb703cae4215d
diff --git a/apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx b/apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx
index fb34bca12a..e8a7903b11 100644
--- a/apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx
+++ b/apps/mobile/src/platform/chrome/HomeNativeStackHeader.tsx
@@ -5,6 +5,7 @@ import { BlurBackdrop } from "@/session/BlurBackdrop";
import { QuietSyncIndicator } from '@/components/QuietSyncIndicator';
import { ChevronDown, Menu } from "lucide-react-native";
import { Pressable, StyleSheet, View } from "react-native";
+import { useSafeAreaFrame, useSafeAreaInsets } from "react-native-safe-area-context";
import { Text } from "@/components/AppText";
import {
NativePullDownMenu,
@@ -21,7 +22,7 @@ import {
useThemedStyles,
type ThemeColors,
} from "@/theme";
-import { lineHeight, radius, spacing } from "@/theme/tokens";
+import { lineHeight, navigationChrome, radius, spacing } from "@/theme/tokens";
/**
* 首页 iOS 顶栏走系统 UINavigationBar。
@@ -64,6 +65,14 @@ export function HomeNativeStackHeader({
const { colors } = useTheme();
const styles = useThemedStyles(makeStyles);
const nativeMenus = usesNativePullDownMenu();
+ const { width } = useSafeAreaFrame();
+ const insets = useSafeAreaInsets();
+ // Keep the native title view's width independent of the selected device and
+ // sync indicator. Reserve the two-action toolbar footprint on both sides so
+ // UIKit can keep the title centered, including when the device name is long.
+ const sideSpace = navigationChrome.target * 2 + spacing.lg * 2;
+ const titleWidth = Math.max(navigationChrome.target,
+ Math.min(220, width - insets.left - insets.right - sideSpace * 2));
if (!usesNativeStackHeader()) return null;
@@ -109,7 +118,11 @@ export function HomeNativeStackHeader({
headerStyle: { backgroundColor: "transparent" },
headerTintColor: colors.textPrimary,
headerTransparent: true,
- headerTitle: () => titleNode,
+ headerTitle: () => (
+ <View style={[styles.titleFrame, { width: titleWidth }]}>
+ {titleNode}
+ </View>
+ ),
}}
/>
<Stack.Header
@@ -165,6 +178,11 @@ function displayMenuItems(actions: readonly NativePullDownAction[], onAction: (i
const makeStyles = (colors: ThemeColors) =>
StyleSheet.create({
pressed: { opacity: 0.72 },
+ titleFrame: {
+ flexShrink: 1,
+ justifyContent: "center",
+ height: navigationChrome.target,
+ },
title: {
color: colors.textPrimary,
flexShrink: 1,
@@ -177,7 +195,7 @@ const makeStyles = (colors: ThemeColors) =>
flexDirection: "row",
flexShrink: 1,
gap: spacing.xs,
- maxWidth: 220,
+ maxWidth: "100%",
minWidth: 0,
},
titleHit: {