Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 顶栏与输入框边缘磨砂改为从透明缓入,并按输入框起算 (#5358)
Dash4487d9b734ac
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsxindex ca82d6c658..660ae50aeb 100644--- a/apps/mobile/app/sessions/[sessionId].tsx+++ b/apps/mobile/app/sessions/[sessionId].tsx@@ -198,7 +198,7 @@ import { createComposerDraftSource, useComposerVoiceDraftWriter, type ComposerDrimport { InlineQueueSection } from '@/session/InlineQueueSection';import { inputProjectionErrorI18nKey } from '@/session/inputProjectionError';import { RewindPreviewPanel } from '@/session/RewindPreviewPanel';-import { BlurBackdrop } from '@/session/BlurBackdrop';+import { BlurBackdrop, FLOATING_CHROME_BLUR_INTENSITY } from '@/session/BlurBackdrop';import { SheetModal } from '@/session/SheetModal';import { SheetGrabber, SheetSurface } from '@/session/SheetSurface';import { NativePermissionSheet } from '@/session/NativePermissionSheet';@@ -1694,6 +1694,9 @@ export default function SessionScreen() {const outboxSessionAliveRef = useRef<string | null>(sessionId);const [messageListFollowLatestRequestKey, setMessageListFollowLatestRequestKey] = useState(0);const [bottomOverlayContentHeight, setBottomOverlayContentHeight] = useState(0);+ // Where the input starts inside the bottom overlay. Status rows and bars+ // above it carry their own surfaces, so the edge blur starts at the input.+ const [composerInputTop, setComposerInputTop] = useState(0);const [topOverlayHeight, setTopOverlayHeight] = useState(0);const composerResizeDraggingRef = useRef(false);const pendingBottomOverlayHeightRef = useRef<number | null>(null);@@ -2292,6 +2295,8 @@ export default function SessionScreen() {const sessionResourceCards = useSessionResourceCards(deviceId, deviceName, sessionId, currentSession?.source, remoteSessionRunning,);+ // Without a mounted input there is no marker; fall back to the whole bottom layer.+ const composerBackdropTop = sessionResourceCards.blocked ? 0 : composerInputTop;// AppState 门槛:锁屏 / 切后台时导航焦点不变,useFocusEffect 的 cleanup 不会跑,// 驻留计时器可能在没有真实前台展示的情况下(甚至后台恢复补跑时)发出 explicit// 回执。把 AppState 作为回执 effect 的重算信号:离开 active 立刻取消未到期的@@ -5557,6 +5562,11 @@ export default function SessionScreen() {));}, []);+ const handleComposerInputTopLayout = useCallback((event: LayoutChangeEvent) => {+ const nextTop = Math.floor(event.nativeEvent.layout.y);+ setComposerInputTop((currentTop) => (Math.abs(currentTop - nextTop) > 1 ? nextTop : currentTop));+ }, []);+const handleComposerDragActiveChange = useCallback((active: boolean) => {composerResizeDraggingRef.current = active;if (active) return;@@ -9002,7 +9012,7 @@ export default function SessionScreen() {style={[styles.keyboard, { marginLeft: paneLayout.detail.x, marginRight: Math.max(0, windowDimensions.width - paneLayout.detail.x - paneLayout.detail.width) }]}>{Platform.OS === 'ios' ? (- <SessionHeaderNativeBlur height={Math.max(topOverlayHeight, insets.top + 44) + spacing.xxl} />+ <SessionHeaderNativeBlur height={Math.max(topOverlayHeight, insets.top + 44)} />) : null}<SessionChromeLayerhiddenFromAccessibility={sessionListDrawerOverlayMounted}@@ -9604,7 +9614,7 @@ export default function SessionScreen() {pointerEvents="none" style={StyleSheet.absoluteFill}><SessionHeaderNativeBluredge="bottom"- height={bottomOverlayHeight + spacing.xxl}+ height={Math.max(0, bottomOverlayHeight - composerBackdropTop)}inset={dockKeyboardFollow ? 0 : nativeShellLayout.keyboardBottomInset}/></DockKeyboardLift>@@ -9664,7 +9674,11 @@ export default function SessionScreen() {>{androidFrostedComposer ? (// 与顶栏同一底:半透明 surface + 模糊,消息从输入区下面滚过时能透出一点。- <View pointerEvents="none" style={StyleSheet.absoluteFill} testID="session.composerFrost">+ // 从输入框顶部起算:上方的状态胶囊自带底,再垫一层会叠成两层底。+ <View pointerEvents="none" style={[+ StyleSheet.absoluteFill,+ sessionOperationLayout.composerSlot === 'editable' && !shareSelectionActive && { top: composerBackdropTop },+ ]} testID="session.composerFrost"><BlurBackdrop intensity={50} overlayColor={colors.surfaceTranslucent} /></View>) : null}@@ -9970,6 +9984,7 @@ export default function SessionScreen() {pendingUploadCount={pendingUploads.length}onPasteImages={(uris) => void addPastedImageAttachments(uris)}onDragActiveChange={handleComposerDragActiveChange}+ onInputTopLayout={handleComposerInputTopLayout}renderControls={renderComposerControls}/> : null}</>@@ -10793,6 +10808,8 @@ interface SessionComposerInputProps {resolvePastedSessionLinkLabel: NonNullable<React.ComponentProps<typeof ComposerRichInput>['resolveSessionLinkLabel']>;openVoiceSettings: () => void;onDragActiveChange: (active: boolean) => void;+ /** Reports where the input itself starts in the bottom overlay (below any recommendation card). */+ onInputTopLayout: (event: LayoutChangeEvent) => void;renderControls: (state: SessionComposerControlState) => SessionComposerControls;}@@ -10802,7 +10819,7 @@ function SessionComposerInput({onDismissPromptRecommendation,source, sessionId, composerInputRef, canUseComposer, canStopComposer, canUseRemoteSessionControls, remoteUnavailableReason, voiceState, voiceStartPending, voiceError, composerVoiceHoldArmed, setComposerVoiceHoldArmed, modelSheetOpen, permissionSheetOpen, sending, queueBusy, nativeShellLayout, composerTouchLayout, keyboardState, attachmentError, visualFocusComposer, applyRichComposerChange, setComposerDraft, handleComposerInputPressIn, beginPastePlaceholders, failPastePlaceholders, resolvePastedSessionLinkLabel, openVoiceSettings,composerSendUnavailableReason, attachmentCount, pendingUploadCount,- onPasteImages, onDragActiveChange, renderControls,+ onPasteImages, onDragActiveChange, onInputTopLayout, renderControls,}: SessionComposerInputProps) {const creationTask = useNewSessionCreationTask(sessionId);const { document: composerDocument, draft } = useSyncExternalStore(source.subscribe, source.getSnapshot);@@ -11137,6 +11154,8 @@ function SessionComposerInput({/></View>) : null}+ {/* Zero-height marker: the edge backdrop starts at the input, not at cards above it. */}+ <View onLayout={onInputTopLayout} pointerEvents="none" testID="session.composerInputTop" /><Reanimated.Viewstyle={[styles.composer,@@ -11774,9 +11793,12 @@ function ComposerActivityStatus({? t('session.screen.tokenRate', { rate: rateValue }): null;const showUsageMeta = !showElapsedOnly && (Boolean(rateText) || tokenUsage > 0);+ // iOS pills share the header/composer edge glass; Android's blur is too weak+ // to carry text alone, so it keeps the translucent surface underneath.+ const pillOverlayColor = Platform.OS === 'ios' ? 'transparent' : colors.surfaceTranslucent;const usageMeta = (<View style={[styles.composerActivityPill, styles.composerActivityMeta]}>- <BlurBackdrop intensity={20} overlayColor={colors.surfaceTranslucent} style={styles.composerActivityPillBackdrop} />+ <BlurBackdrop intensity={FLOATING_CHROME_BLUR_INTENSITY} overlayColor={pillOverlayColor} style={styles.composerActivityPillBackdrop} /><Text style={styles.composerActivityMetaText}>{elapsedText}</Text>{showUsageMeta ? (<>@@ -11822,7 +11844,7 @@ function ComposerActivityStatus({testID="session.composerActivityStatus"><View pointerEvents="none" style={[styles.composerActivityPill, styles.composerActivityPrimary]}>- <BlurBackdrop intensity={20} overlayColor={colors.surfaceTranslucent} style={styles.composerActivityPillBackdrop} />+ <BlurBackdrop intensity={FLOATING_CHROME_BLUR_INTENSITY} overlayColor={pillOverlayColor} style={styles.composerActivityPillBackdrop} /><Sparkles color={colors.statusAccent} size={iconSize.sm} strokeWidth={iconStroke.regular} /><Text numberOfLines={1} style={styles.composerActivityStatusText}>{activityText}</Text>{reconnectAttempt ? (diff --git a/apps/mobile/src/__tests__/edgeBlurMask.test.ts b/apps/mobile/src/__tests__/edgeBlurMask.test.tsnew file mode 100644index 0000000000..6121388a1d--- /dev/null+++ b/apps/mobile/src/__tests__/edgeBlurMask.test.ts@@ -0,0 +1,72 @@+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { describe, expect, it } from 'vitest';+import { EDGE_BLUR_FADE_INSIDE, EDGE_BLUR_FADE_OUTSIDE, edgeBlurMask } from '@/session/edgeBlurMask';++const readTextLf = (path: string): string =>+ String(readFileSync(resolve(process.cwd(), path), 'utf8')).replace(/\r\n/g, '\n');+const alpha = (color: string): number => Number(/rgba\(0, 0, 0, ([\d.]+)\)/.exec(color)?.[1]);++describe('edge blur mask', () => {+ it('feathers the top chrome across its lower edge, from solid to clear', () => {+ const mask = edgeBlurMask(100, 'top');+ expect(EDGE_BLUR_FADE_INSIDE).toBe(24);+ expect(EDGE_BLUR_FADE_OUTSIDE).toBe(16);+ expect(mask.height).toBe(116);+ // The fade starts 24pt inside the chrome and ends at the backdrop edge, 16pt past it.+ expect(mask.startPoint.y * mask.height).toBeCloseTo(100 - 24);+ expect(mask.endPoint.y).toBe(1);+ expect(alpha(mask.colors[0])).toBe(1);+ expect(alpha(mask.colors.at(-1)!)).toBe(0);+ });++ it('mirrors the feather for the bottom chrome, facing up toward content', () => {+ const mask = edgeBlurMask(100, 'bottom');+ expect(mask.height).toBe(116);+ expect(mask.startPoint.y).toBe(0);+ expect(mask.endPoint.y * mask.height).toBeCloseTo(16 + 24);+ expect(alpha(mask.colors[0])).toBe(0);+ expect(alpha(mask.colors.at(-1)!)).toBe(1);+ });++ it('eases both ends of the fade instead of a linear ramp', () => {+ const alphas = edgeBlurMask(100, 'top').colors.map(alpha);+ expect(alphas).toHaveLength(9);+ for (let index = 1; index < alphas.length; index += 1) expect(alphas[index]).toBeLessThan(alphas[index - 1]);+ // Smoothstep: shallow steps at both ends, steep in the middle.+ expect(alphas[0] - alphas[1]).toBeLessThan(alphas[4] - alphas[5]);+ expect(alphas[7] - alphas[8]).toBeLessThan(alphas[4] - alphas[5]);+ });++ it('keeps short chrome partly solid by capping the inside feather at half its height', () => {+ const mask = edgeBlurMask(20, 'top');+ expect(mask.startPoint.y * mask.height).toBeCloseTo(10);+ });+});++describe('composer edge backdrop placement', () => {+ const source = readTextLf('app/sessions/[sessionId].tsx');++ it('measures the input start inside the composer, after any recommendation card', () => {+ const composer = source.slice(source.indexOf('function SessionComposerInput('));+ const recommendation = composer.indexOf('<PromptRecommendation');+ const marker = composer.indexOf('testID="session.composerInputTop"');+ const input = composer.indexOf('testID="session.composer"');+ expect(recommendation).toBeGreaterThan(-1);+ expect(marker).toBeGreaterThan(recommendation);+ expect(input).toBeGreaterThan(marker);+ expect(source.match(/testID="session\.composerInputTop"/g)).toHaveLength(1);+ });++ it('starts the iOS edge blur and the Android frost at the input, not at status rows above it', () => {+ expect(source).toContain('const composerBackdropTop = sessionResourceCards.blocked ? 0 : composerInputTop;');+ expect(source).toContain('height={Math.max(0, bottomOverlayHeight - composerBackdropTop)}');+ const frost = source.slice(source.indexOf('{androidFrostedComposer ? ('), source.indexOf('testID="session.composerFrost"'));+ expect(frost).toContain("sessionOperationLayout.composerSlot === 'editable' && !shareSelectionActive && { top: composerBackdropTop }");+ });++ it('frosts the activity pills with the shared chrome glass', () => {+ expect(source).toContain("const pillOverlayColor = Platform.OS === 'ios' ? 'transparent' : colors.surfaceTranslucent;");+ expect(source.match(/<BlurBackdrop intensity=\{FLOATING_CHROME_BLUR_INTENSITY\} overlayColor=\{pillOverlayColor\}/g)).toHaveLength(2);+ });+});diff --git a/apps/mobile/src/__tests__/runningTokenRatePopover.test.tsx b/apps/mobile/src/__tests__/runningTokenRatePopover.test.tsxindex acb1dd97bc..27f846d0b1 100644--- a/apps/mobile/src/__tests__/runningTokenRatePopover.test.tsx+++ b/apps/mobile/src/__tests__/runningTokenRatePopover.test.tsx@@ -185,6 +185,8 @@ const bindings = {View: ({ children }: any) => createElement("div", {}, children),Text: ({ children }: any) => createElement("span", {}, children),BlurBackdrop: () => null,+ FLOATING_CHROME_BLUR_INTENSITY: 55,+ Platform: { OS: "ios" },Sparkles: () => null,ArrowDown: () => null,iconSize: {},diff --git a/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts b/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.tsindex 8d260f63d2..030123be08 100644--- a/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts+++ b/apps/mobile/src/__tests__/sessionComposerDesktopFirst.test.ts@@ -262,7 +262,7 @@ describe('mobile session composer desktop-first surface', () => {expect(source).toContain('composerRuntimePillTextRisky');expect(source).toContain('color: colors.statusAccent');expect(source).not.toContain("import { BlurView } from 'expo-blur';");- expect(source).toContain("import { BlurBackdrop } from '@/session/BlurBackdrop';");+ expect(source).toContain("import { BlurBackdrop, FLOATING_CHROME_BLUR_INTENSITY } from '@/session/BlurBackdrop';");expect(source).toContain('<SessionHeaderNativeBlur height=');expect(source).toMatch(/<SessionHeaderNativeTitle\s+title=\{sharedTaskEnded \? t\('sharedTask.ended'\) : title\}/);expect(source).toContain('<SessionHeaderNativeActions');diff --git a/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts b/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.tsindex 5ab77119d2..42269b87a0 100644--- a/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts+++ b/apps/mobile/src/__tests__/sessionHeaderDesktopFirst.test.ts@@ -62,7 +62,7 @@ describe('mobile session header desktop-first surface', () => {expect(source).toContain('<View style={styles.safeArea} testID="session.screen">');expect(source).not.toContain('<SafeAreaView style={styles.safeArea} testID="session.screen">');expect(source).not.toContain("import { BlurView } from 'expo-blur';");- expect(source).toContain("import { BlurBackdrop } from '@/session/BlurBackdrop';");+ expect(source).toContain("import { BlurBackdrop, FLOATING_CHROME_BLUR_INTENSITY } from '@/session/BlurBackdrop';");// iOS floats individual glass capsules over the message canvas.expect(source).not.toContain('<TranslucentBackdrop />');expect(source).not.toContain('colors.chatHeaderSurface');diff --git a/apps/mobile/src/session/BlurBackdrop.tsx b/apps/mobile/src/session/BlurBackdrop.tsxindex 07416e0f87..640ddbbb9e 100644--- a/apps/mobile/src/session/BlurBackdrop.tsx+++ b/apps/mobile/src/session/BlurBackdrop.tsx@@ -30,6 +30,13 @@ import { BlurView } from 'expo-blur';import { StyleSheet, View, type StyleProp, type ViewStyle } from 'react-native';import { useTheme } from '@/theme';+/**+ * Frosting for chrome that floats over scrolling content (session header and+ * composer edge blur, composer activity pills). Pair with a transparent+ * overlay so every floating surface reads as the same glass.+ */+export const FLOATING_CHROME_BLUR_INTENSITY = 55;+export interface BlurBackdropProps {/** iOS BlurView intensity(R1 模式1 ≈ 50;模式3 浮层可传更低)。默认 50。 */intensity?: number;diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsxindex cd1f5dcda7..fd5987a0c8 100644--- a/apps/mobile/src/session/HomeSurface.tsx+++ b/apps/mobile/src/session/HomeSurface.tsx@@ -2854,7 +2854,7 @@ function HomeScreenContent({ active = true, onModeChange, width, onDismiss, newSstyle={[styles.safeArea, { paddingLeft: embedded ? 0 : edgePadding.paddingLeft, paddingRight: embedded ? 0 : edgePadding.paddingRight }]}testID="devices.screen">- {nativeHomeHeader ? <SessionHeaderNativeBlur height={nativeHeaderHeight + spacing.xxl} /> : null}+ {nativeHomeHeader ? <SessionHeaderNativeBlur height={nativeHeaderHeight} /> : null}{nativeHomeHeader && active ? (<HomeNativeStackHeaderkeepMenuTopLeft={keepMenuTopLeft}diff --git a/apps/mobile/src/session/SessionHeaderNativeControls.ios.tsx b/apps/mobile/src/session/SessionHeaderNativeControls.ios.tsxindex 8545b73dc5..3a7e8e157c 100644--- a/apps/mobile/src/session/SessionHeaderNativeControls.ios.tsx+++ b/apps/mobile/src/session/SessionHeaderNativeControls.ios.tsx@@ -37,29 +37,22 @@ import {fontWeight,useTheme,} from "@/theme";-import { BlurBackdrop } from "./BlurBackdrop";+import { BlurBackdrop, FLOATING_CHROME_BLUR_INTENSITY } from "./BlurBackdrop";+import { edgeBlurMask } from "./edgeBlurMask";import type {SessionHeaderNativeActionsProps,SessionHeaderNativeBackProps,SessionHeaderNativeTitleProps,} from "./SessionHeaderNativeControls";-/** A stationary, feathered backdrop: scrolling content passes beneath it. */-/** Fade length at the content edge; the chrome area itself stays fully blurred. */-const BLUR_FADE = 32;/**- * A two-stop gradient left the title row at roughly half blur, so text that- * scrolled under a header stayed legible and read as overlapping it. Keep the- * mask opaque over the chrome and fade only the last BLUR_FADE points- * (evenly spaced stops approximate the break point).+ * A stationary, feathered backdrop: scrolling content passes beneath it.+ * `height` is the chrome area; the blur is solid over most of it and eases out+ * across its content-side edge (see edgeBlurMask).*/-function blurMaskStops(height: number): string[] {- const solid = Math.max(1, Math.round(height / Math.min(BLUR_FADE, height / 2)) - 1);- return [...Array<string>(solid).fill("black"), "transparent"];-}--export function SessionHeaderNativeBlur({ height, edge = 'top', inset = 0 }: { height: number; edge?: 'top' | 'bottom'; inset?: number }) {+export function SessionHeaderNativeBlur({ height: chromeHeight, edge = 'top', inset = 0 }: { height: number; edge?: 'top' | 'bottom'; inset?: number }) {const { mode } = useTheme();+ const mask = edgeBlurMask(chromeHeight, edge);return (<ViewpointerEvents="none"@@ -69,7 +62,7 @@ export function SessionHeaderNativeBlur({ height, edge = 'top', inset = 0 }: { h...(edge === 'top' ? { top: inset } : { bottom: inset }),left: 0,right: 0,- height,+ height: mask.height,zIndex: 9,}}>@@ -77,7 +70,7 @@ export function SessionHeaderNativeBlur({ height, edge = 'top', inset = 0 }: { h<Mask modifiers={[frame({ maxWidth: Infinity, maxHeight: Infinity })]}><RNHostView><View style={{ flex: 1 }}>- <BlurBackdrop intensity={55} overlayColor="transparent" />+ <BlurBackdrop intensity={FLOATING_CHROME_BLUR_INTENSITY} overlayColor="transparent" /></View></RNHostView><Mask.Content>@@ -85,10 +78,9 @@ export function SessionHeaderNativeBlur({ height, edge = 'top', inset = 0 }: { hmodifiers={[foregroundStyle({type: "linearGradient",- // Mask colors encode alpha only; they never tint the content.- colors: edge === 'top' ? blurMaskStops(height) : blurMaskStops(height).reverse(),- startPoint: { x: 0.5, y: 0 },- endPoint: { x: 0.5, y: 1 },+ colors: mask.colors,+ startPoint: mask.startPoint,+ endPoint: mask.endPoint,}),]}/>diff --git a/apps/mobile/src/session/edgeBlurMask.ts b/apps/mobile/src/session/edgeBlurMask.tsnew file mode 100644index 0000000000..9b088c7a6c--- /dev/null+++ b/apps/mobile/src/session/edgeBlurMask.ts@@ -0,0 +1,51 @@+import { spacing } from '@/theme/tokens';++/**+ * The feather straddles the chrome edge: it begins inside the chrome and only+ * reaches a short way past it, so content starts to soften as it arrives at the+ * chrome rather than well before it.+ */+export const EDGE_BLUR_FADE_INSIDE = spacing.xl;+export const EDGE_BLUR_FADE_OUTSIDE = spacing.lg;++/**+ * Mask opacity from fully blurred to clear along a smoothstep curve. A linear+ * ramp reads as a visible band at both of its ends; easing both ends lets the+ * frosting emerge from transparent instead. Ordered from the chrome side.+ */+const FADE_STOP_COUNT = 9;+const FADE_STOPS = Array.from({ length: FADE_STOP_COUNT }, (_, index) => {+ const t = index / (FADE_STOP_COUNT - 1);+ const opacity = 1 - t * t * (3 - 2 * t);+ return `rgba(0, 0, 0, ${opacity.toFixed(3)})`;+});++export interface EdgeBlurMask {+ /** Backdrop height: the chrome plus the outside feather. */+ height: number;+ /** Mask colors encode alpha only; they never tint the content. */+ colors: string[];+ /** Unit points; outside them the end colors extend. */+ startPoint: { x: number; y: number };+ endPoint: { x: number; y: number };+}++/** Mask geometry for a backdrop whose chrome sits at `edge` and whose feather faces the content. */+export function edgeBlurMask(chromeHeight: number, edge: 'top' | 'bottom'): EdgeBlurMask {+ const height = chromeHeight + EDGE_BLUR_FADE_OUTSIDE;+ const fadeLength = Math.min(EDGE_BLUR_FADE_INSIDE, chromeHeight / 2) + EDGE_BLUR_FADE_OUTSIDE;+ const fadeFraction = fadeLength / height;+ return edge === 'top'+ ? {+ height,+ colors: FADE_STOPS,+ startPoint: { x: 0.5, y: 1 - fadeFraction },+ endPoint: { x: 0.5, y: 1 },+ }+ : {+ height,+ colors: [...FADE_STOPS].reverse(),+ startPoint: { x: 0.5, y: 0 },+ endPoint: { x: 0.5, y: fadeFraction },+ };+}