diff --git a/apps/mobile/app.config.ts b/apps/mobile/app.config.ts index a75f9f06d1..680d689f36 100644 --- a/apps/mobile/app.config.ts +++ b/apps/mobile/app.config.ts @@ -17,6 +17,7 @@ const VARIANT_CONFIG: Record< readonly iosIcon: string; readonly iosBundleIdentifier: string; readonly androidPackage: string; + readonly relyingParty?: string; } > = { development: { @@ -25,6 +26,7 @@ const VARIANT_CONFIG: Record< iosIcon: "./assets/icon-composer-dev.icon", iosBundleIdentifier: "com.t3tools.t3code.dev", androidPackage: "com.t3tools.t3code.dev", + relyingParty: "clerk.t3.codes", }, preview: { appName: "T3 Code Preview", @@ -32,6 +34,7 @@ const VARIANT_CONFIG: Record< iosIcon: "./assets/icon-composer-prod.icon", iosBundleIdentifier: "com.t3tools.t3code.preview", androidPackage: "com.t3tools.t3code.preview", + relyingParty: "clerk.t3.codes", }, production: { appName: "T3 Code", @@ -39,6 +42,7 @@ const VARIANT_CONFIG: Record< iosIcon: "./assets/icon-composer-prod.icon", iosBundleIdentifier: "com.t3tools.t3code", androidPackage: "com.t3tools.t3code", + relyingParty: "clerk.t3.codes", }, }; @@ -64,7 +68,7 @@ const config: ExpoConfig = { runtimeVersion: { policy: process.env.MOBILE_VERSION_POLICY ?? "appVersion", }, - orientation: "default", + orientation: "portrait", icon: "./assets/icon.png", userInterfaceStyle: "automatic", updates: { @@ -77,6 +81,10 @@ const config: ExpoConfig = { icon: variant.iosIcon, supportsTablet: true, bundleIdentifier: variant.iosBundleIdentifier, + associatedDomains: [ + `applinks:${variant.relyingParty}`, + `webcredentials:${variant.relyingParty}`, + ], infoPlist: { NSAppTransportSecurity: { NSAllowsArbitraryLoads: true, diff --git a/apps/mobile/src/app/_layout.tsx b/apps/mobile/src/app/_layout.tsx index 43b490edcb..23762c4cdc 100644 --- a/apps/mobile/src/app/_layout.tsx +++ b/apps/mobile/src/app/_layout.tsx @@ -95,7 +95,7 @@ function WorkspaceNavigator() { }; const settingsScreenOptions = layout.usesSplitView ? { - animation: "fade" as const, + animation: "none" as const, contentStyle: sheetStyle, gestureEnabled: false, headerShown: false, diff --git a/apps/mobile/src/app/threads/[environmentId]/[threadId]/_layout.tsx b/apps/mobile/src/app/threads/[environmentId]/[threadId]/_layout.tsx index 6f2fb22833..d69e42310b 100644 --- a/apps/mobile/src/app/threads/[environmentId]/[threadId]/_layout.tsx +++ b/apps/mobile/src/app/threads/[environmentId]/[threadId]/_layout.tsx @@ -2,6 +2,7 @@ import Stack from "expo-router/stack"; import { StyleSheet } from "react-native"; import { useResolveClassNames } from "uniwind"; import { useAdaptiveWorkspaceLayout } from "../../../../features/layout/AdaptiveWorkspaceLayout"; +import { ThreadSelectionProvider } from "../../../../state/use-thread-selection"; export default function ThreadLayout() { const { fileInspector } = useAdaptiveWorkspaceLayout(); @@ -11,101 +12,102 @@ export default function ThreadLayout() { }; return ( - - - - - - - - - - + + + + + + + + + + + + ); } diff --git a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx index 3b97521783..2dccb7c357 100644 --- a/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx +++ b/apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx @@ -1,18 +1,8 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; import { EnvironmentId, ThreadId } from "@t3tools/contracts"; import { useFocusEffect, useGlobalSearchParams, usePathname, useRouter } from "expo-router"; -import { - createContext, - use, - useCallback, - useEffect, - useMemo, - useRef, - useState, - type ReactNode, -} from "react"; +import { createContext, use, useCallback, useMemo, useRef, useState, type ReactNode } from "react"; import { useWindowDimensions, View } from "react-native"; -import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated"; import { deriveFileInspectorPaneLayout, @@ -27,7 +17,6 @@ import { resolveThreadSelectionNavigationAction } from "../../lib/adaptive-navig import { buildThreadRoutePath } from "../../lib/routes"; import { scopedThreadKey } from "../../lib/scopedEntities"; import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar"; -import { WORKSPACE_PANE_LAYOUT_TRANSITION } from "./workspace-pane-transition"; interface AdaptiveWorkspaceContextValue { readonly layout: Layout; @@ -86,7 +75,6 @@ export function AdaptiveWorkspaceLayout(props: { readonly children: ReactNode }) const [fileInspectorPreferredVisible, setFileInspectorPreferredVisible] = useState(true); const [focusedAuxiliaryPaneRole, setFocusedAuxiliaryPaneRole] = useState(null); - const sidebarProgress = useSharedValue(1); const params = useGlobalSearchParams<{ environmentId?: string | string[]; threadId?: string | string[]; @@ -181,13 +169,12 @@ export function AdaptiveWorkspaceLayout(props: { readonly children: ReactNode }) ], ); - useEffect(() => { - sidebarProgress.value = withTiming(panes.primarySidebarVisible ? 1 : 0, { duration: 220 }); - }, [panes.primarySidebarVisible, sidebarProgress]); - const sidebarStyle = useAnimatedStyle(() => ({ - opacity: sidebarProgress.value, - transform: [{ translateX: (sidebarProgress.value - 1) * 24 }], - })); + const handleOpenSettings = useCallback(() => { + router.push("/settings"); + }, [router]); + const handleStartNewTask = useCallback(() => { + router.push("/new"); + }, [router]); const handleSelectThread = useCallback( (thread: EnvironmentThreadShell) => { @@ -197,8 +184,10 @@ export function AdaptiveWorkspaceLayout(props: { readonly children: ReactNode }) pathname, }); if (navigationAction === "set-params") { - // Auxiliary content belongs to the current thread. Close it before - // reusing the current native detail screen for a peer thread selection. + const nextThreadKey = scopedThreadKey(thread.environmentId, thread.id); + if (nextThreadKey === selectedThreadKey) { + return; + } setFileInspectorPreferredVisible(false); router.setParams({ environmentId: String(thread.environmentId), @@ -213,44 +202,36 @@ export function AdaptiveWorkspaceLayout(props: { readonly children: ReactNode }) } router.push(destination); }, - [layout.usesSplitView, pathname, router], + [layout.usesSplitView, pathname, router, selectedThreadKey], ); return ( {layout.usesSplitView && layout.listPaneWidth !== null ? ( - router.push("/settings")} + onOpenSettings={handleOpenSettings} onSelectThread={handleSelectThread} - onStartNewTask={() => router.push("/new")} + onStartNewTask={handleStartNewTask} /> - + ) : null} - + {props.children} - + ); diff --git a/apps/mobile/src/features/layout/adaptive-inspector-layout.tsx b/apps/mobile/src/features/layout/adaptive-inspector-layout.tsx index 0920f409eb..4af0e8e313 100644 --- a/apps/mobile/src/features/layout/adaptive-inspector-layout.tsx +++ b/apps/mobile/src/features/layout/adaptive-inspector-layout.tsx @@ -8,7 +8,6 @@ import Animated, { } from "react-native-reanimated"; import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout"; -import { WORKSPACE_PANE_LAYOUT_TRANSITION } from "./workspace-pane-transition"; export function AdaptiveInspectorLayout(props: { readonly children: ReactNode; @@ -41,11 +40,7 @@ export function AdaptiveInspectorLayout(props: { return ( - + {props.children} {inspectorSupported ? ( @@ -53,7 +48,6 @@ export function AdaptiveInspectorLayout(props: { accessibilityElementsHidden={!inspectorVisible} collapsable={false} importantForAccessibility={inspectorVisible ? "auto" : "no-hide-descendants"} - layout={WORKSPACE_PANE_LAYOUT_TRANSITION} pointerEvents={inspectorVisible ? "auto" : "none"} style={[ { diff --git a/apps/mobile/src/features/layout/workspace-pane-transition.ts b/apps/mobile/src/features/layout/workspace-pane-transition.ts deleted file mode 100644 index d688b6b739..0000000000 --- a/apps/mobile/src/features/layout/workspace-pane-transition.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Easing, LinearTransition } from "react-native-reanimated"; - -/** - * Animates between final Yoga layouts on the UI thread. Keeping pane widths - * out of animated styles avoids recalculating the entire workspace on every - * display frame while a sidebar or inspector moves. - */ -export const WORKSPACE_PANE_LAYOUT_TRANSITION = LinearTransition.duration(220).easing( - Easing.out(Easing.cubic), -); diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx index 39e4dc4c6d..2f9e4a9482 100644 --- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx +++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx @@ -69,6 +69,7 @@ export interface ThreadDetailScreenProps { readonly selectedThreadQueueCount: number; readonly serverConfig: T3ServerConfig | null; readonly layoutVariant?: LayoutVariant; + readonly usesAutomaticContentInsets?: boolean; readonly onOpenDrawer: () => void; readonly onOpenConnectionEditor: () => void; readonly onChangeDraftMessage: (value: string) => void; @@ -387,6 +388,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread contentBottomInset={estimatedOverlayHeight} contentMaxWidth={contentMaxWidth} layoutVariant={layoutVariant} + usesAutomaticContentInsets={props.usesAutomaticContentInsets} skills={selectedProviderSkills} /> diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx index 9d5d480882..4ffdbe04d9 100644 --- a/apps/mobile/src/features/threads/ThreadFeed.tsx +++ b/apps/mobile/src/features/threads/ThreadFeed.tsx @@ -38,7 +38,7 @@ import { import { TouchableOpacity } from "react-native-gesture-handler"; import ImageViewing from "react-native-image-viewing"; import { useSafeAreaInsets } from "react-native-safe-area-context"; -import type { SharedValue } from "react-native-reanimated"; +import { type SharedValue } from "react-native-reanimated"; import { useThemeColor } from "../../lib/useThemeColor"; import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic"; import { @@ -108,6 +108,7 @@ export interface ThreadFeedProps { readonly contentBottomInset?: number; readonly contentMaxWidth?: number; readonly layoutVariant?: LayoutVariant; + readonly usesAutomaticContentInsets?: boolean; readonly skills?: ReadonlyArray; } @@ -1156,7 +1157,6 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) { const insets = useSafeAreaInsets(); const topContentInset = props.contentTopInset ?? insets.top + 44; const bottomContentInset = props.contentBottomInset ?? 18; - const handleViewportLayout = useCallback((event: LayoutChangeEvent) => { const nextWidth = Math.round(event.nativeEvent.layout.width); setViewportWidth((current) => (Math.abs(current - nextWidth) > 1 ? nextWidth : current)); @@ -1473,8 +1473,14 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) { ref={props.listRef} key={props.threadId} style={{ flex: 1 }} + contentInsetAdjustmentBehavior="never" automaticallyAdjustsScrollIndicatorInsets={false} - scrollIndicatorInsets={{ top: topContentInset, bottom: 0 }} + {...(props.usesAutomaticContentInsets + ? { + contentInset: { top: topContentInset, left: 0, right: 0, bottom: 0 }, + scrollIndicatorInsets: { top: 0, left: 0, right: 0, bottom: 0 }, + } + : { scrollIndicatorInsets: { top: topContentInset, bottom: 0 } })} {...(anchoredEndSpace ? { anchoredEndSpace } : {})} contentInsetEndAdjustment={props.contentInsetEndAdjustment} freeze={props.freeze} @@ -1503,7 +1509,9 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) { keyboardLiftBehavior="whenAtEnd" estimatedItemSize={180} initialScrollAtEnd - ListHeaderComponent={} + ListHeaderComponent={ + props.usesAutomaticContentInsets ? null : + } contentContainerStyle={{ paddingTop: 12, paddingHorizontal: contentHorizontalPadding, diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx index db84429f87..83341ccc55 100644 --- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx +++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx @@ -71,16 +71,13 @@ const ThreadNavigationRow = memo(function ThreadNavigationRow(props: { primaryAction={primaryAction} threadTitle={thread.title} > - {(close) => ( + {() => ( { - close(); - onSelectThread(thread); - }} + onPress={() => onSelectThread(thread)} style={({ pressed }) => [ styles.threadRow, { @@ -144,6 +141,13 @@ export function ThreadNavigationSidebar(props: { openSwipeableRef.current = null; } }, []); + const handleSelectThread = useCallback( + (thread: EnvironmentThreadShell) => { + props.onSelectThread(thread); + openSwipeableRef.current?.close(); + }, + [props.onSelectThread], + ); return ( ; } +interface ThreadRouteScreenProps { + readonly onReturnToThread?: () => void; + readonly renderInspector?: () => ReactNode; +} + +function ThreadUnavailableScreen() { + return ( + + + + ); +} + +export function ThreadRouteScreen(props: ThreadRouteScreenProps = {}) { + const { state: workspaceState } = useWorkspaceState(); + const { connectionState } = useRemoteConnectionStatus(); + const { selectedThread } = useThreadSelection(); + const params = useLocalSearchParams<{ + environmentId?: string | string[]; + threadId?: string | string[]; + }>(); + const environmentIdRaw = firstRouteParam(params.environmentId); + const threadIdRaw = firstRouteParam(params.threadId); + const environmentId = environmentIdRaw ? EnvironmentId.make(environmentIdRaw) : null; + const routeEnvironmentRuntime = useRemoteEnvironmentRuntime(environmentId); + const routeConnectionState = + routeEnvironmentRuntime?.connectionState ?? (environmentId ? "available" : connectionState); + const routeThreadKey = + environmentId !== null && threadIdRaw !== null + ? scopedThreadKey(environmentId, ThreadId.make(threadIdRaw)) + : null; + const selectedThreadKey = + selectedThread === null + ? null + : scopedThreadKey(selectedThread.environmentId, selectedThread.id); + const selectedThreadDetailState = useSelectedThreadDetailState(); + const hasThreadDetail = Option.isSome(selectedThreadDetailState.data); + const hasTerminalDetailState = + selectedThreadDetailState.status === "deleted" || + Option.isSome(selectedThreadDetailState.error); + + if (environmentId === null || threadIdRaw === null) { + return ; + } + + if (selectedThread !== null && selectedThreadKey === routeThreadKey) { + if (!hasThreadDetail && !hasTerminalDetailState) { + return ; + } + return ; + } + + const stillHydrating = + workspaceState.isLoadingConnections || + routeConnectionState === "connecting" || + routeConnectionState === "reconnecting"; + + if (stillHydrating) { + return ; + } + + return ; +} + function ThreadHeaderTitle(props: { readonly foregroundColor: string; readonly secondaryForegroundColor: string; @@ -128,21 +209,19 @@ function ThreadHeaderTitle(props: { ); } -export function ThreadRouteScreen( - props: { - readonly onReturnToThread?: () => void; - readonly renderInspector?: () => ReactNode; - } = {}, +function ThreadRouteContent( + props: ThreadRouteScreenProps & { + readonly selectedThreadDetailState: ReturnType; + }, ) { const { fileInspector, layout, showAuxiliaryPane, toggleAuxiliaryPane } = useAdaptiveWorkspaceLayout(); const headerHeight = useHeaderHeight(); - const { state: workspaceState } = useWorkspaceState(); const { connectionState } = useRemoteConnectionStatus(); const { onReconnectEnvironment } = useRemoteConnections(); const { selectedThread, selectedThreadProject, selectedEnvironmentConnection } = useThreadSelection(); - const selectedThreadDetailState = useSelectedThreadDetailState(); + const selectedThreadDetailState = props.selectedThreadDetailState; const selectedThreadDetail = Option.getOrNull(selectedThreadDetailState.data); const { selectedThreadCwd } = useSelectedThreadWorktree(); const composer = useThreadComposerState(); @@ -208,18 +287,6 @@ export function ThreadRouteScreen( ] .filter(Boolean) .join(" · "); - const renderHeaderTitle = useCallback( - () => ( - - ), - [foregroundColor, headerSubtitle, secondaryFg, selectedThread?.title], - ); - /* ─── Git status for native header trigger ───────────────────────── */ const gitStatus = useEnvironmentQuery( selectedThread !== null && selectedThreadCwd !== null @@ -484,32 +551,7 @@ export function ThreadRouteScreen( } if (!selectedThread) { - const stillHydrating = - workspaceState.isLoadingConnections || - routeConnectionState === "connecting" || - routeConnectionState === "reconnecting"; - - if (stillHydrating) { - return ; - } - - return ( - - - - ); + return ; } const selectedThreadKey = scopedThreadKey(selectedThread.environmentId, selectedThread.id); @@ -527,16 +569,37 @@ export function ThreadRouteScreen( + + + + {props.onReturnToThread ? ( { + it("keeps the automatic native treatment on iOS 26", () => { + expect(nativeTopScrollEdgeEffect("ios", "26.5")).toBe("automatic"); + }); + + it("uses the native hard treatment on iOS 27 and later", () => { + expect(nativeTopScrollEdgeEffect("ios", "27.0")).toBe("hard"); + expect(nativeTopScrollEdgeEffect("ios", 28)).toBe("hard"); + }); + + it("does not apply the iOS workaround to other platforms", () => { + expect(nativeTopScrollEdgeEffect("android", 27)).toBe("automatic"); + }); +}); diff --git a/apps/mobile/src/lib/native-scroll-edge-effect.ts b/apps/mobile/src/lib/native-scroll-edge-effect.ts new file mode 100644 index 0000000000..a0704b5c1d --- /dev/null +++ b/apps/mobile/src/lib/native-scroll-edge-effect.ts @@ -0,0 +1,23 @@ +export type NativeTopScrollEdgeEffect = "automatic" | "hard"; + +function majorVersion(version: number | string): number { + if (typeof version === "number") { + return Math.trunc(version); + } + + const parsed = Number.parseInt(version, 10); + return Number.isNaN(parsed) ? 0 : parsed; +} + +/** + * iOS 27 beta currently renders the automatic/soft top scroll-edge effect as + * fully transparent. Keep the subtler automatic treatment on iOS 26 and use + * UIKit's native hard treatment on iOS 27+ until the platform regression is + * resolved. + */ +export function nativeTopScrollEdgeEffect( + os: string, + version: number | string, +): NativeTopScrollEdgeEffect { + return os === "ios" && majorVersion(version) >= 27 ? "hard" : "automatic"; +} diff --git a/apps/mobile/src/state/use-thread-selection.ts b/apps/mobile/src/state/use-thread-selection.ts index 06175b6d23..8f3a1c2d1c 100644 --- a/apps/mobile/src/state/use-thread-selection.ts +++ b/apps/mobile/src/state/use-thread-selection.ts @@ -1,6 +1,11 @@ -import { useLocalSearchParams } from "expo-router"; -import { useMemo } from "react"; -import { EnvironmentId, ThreadId, type ScopedProjectRef } from "@t3tools/contracts"; +import { useGlobalSearchParams } from "expo-router"; +import { createContext, createElement, use, useMemo, useRef, type ReactNode } from "react"; +import { + EnvironmentId, + ThreadId, + type ScopedProjectRef, + type ScopedThreadRef, +} from "@t3tools/contracts"; import { useProject, useThreadShell } from "../state/entities"; import { @@ -16,12 +21,12 @@ function firstRouteParam(value: string | string[] | undefined): string | null { return value ?? null; } -export function useThreadSelection() { - const params = useLocalSearchParams<{ +function useResolvedThreadSelection() { + const params = useGlobalSearchParams<{ environmentId?: string | string[]; threadId?: string | string[]; }>(); - const selectedThreadRef = useMemo(() => { + const routeThreadRef = useMemo(() => { const environmentId = firstRouteParam(params.environmentId); const threadId = firstRouteParam(params.threadId); if (!environmentId || !threadId) { @@ -33,6 +38,11 @@ export function useThreadSelection() { threadId: ThreadId.make(threadId), }; }, [params.environmentId, params.threadId]); + const lastRouteThreadRef = useRef(null); + if (routeThreadRef !== null) { + lastRouteThreadRef.current = routeThreadRef; + } + const selectedThreadRef = routeThreadRef ?? lastRouteThreadRef.current; const selectedThread = useThreadShell(selectedThreadRef); const selectedProjectRef = useMemo( () => @@ -49,11 +59,37 @@ export function useThreadSelection() { const selectedEnvironmentConnection = useSavedRemoteConnection(selectedEnvironmentId); const selectedEnvironmentRuntime = useRemoteEnvironmentRuntime(selectedEnvironmentId); - return { - selectedThreadRef, - selectedThread, - selectedThreadProject, - selectedEnvironmentConnection, - selectedEnvironmentRuntime, - }; + return useMemo( + () => ({ + selectedThreadRef, + selectedThread, + selectedThreadProject, + selectedEnvironmentConnection, + selectedEnvironmentRuntime, + }), + [ + selectedEnvironmentConnection, + selectedEnvironmentRuntime, + selectedThread, + selectedThreadProject, + selectedThreadRef, + ], + ); +} + +type ThreadSelectionState = ReturnType; + +const ThreadSelectionContext = createContext(null); + +export function ThreadSelectionProvider(props: { readonly children: ReactNode }) { + const selection = useResolvedThreadSelection(); + return createElement(ThreadSelectionContext.Provider, { value: selection }, props.children); +} + +export function useThreadSelection(): ThreadSelectionState { + const selection = use(ThreadSelectionContext); + if (selection === null) { + throw new Error("useThreadSelection must be used within ThreadSelectionProvider"); + } + return selection; }