Skip to content
TypeScript

feat(mobile): redesign the Add environment sheet (#17092)

Julius Marminge30cc78897550
diff --git a/apps/mobile/modules/t3-native-controls/ios/T3FrostedCutoutView.swift b/apps/mobile/modules/t3-native-controls/ios/T3FrostedCutoutView.swift
new file mode 100644
index 00000000000..3f6dc5fda7a
--- /dev/null
+++ b/apps/mobile/modules/t3-native-controls/ios/T3FrostedCutoutView.swift
@@ -0,0 +1,49 @@
+import ExpoModulesCore
+import UIKit
+
+/// One continuous blur with a rounded-rect hole, horizontally centered. A
+/// single masked effect view avoids the seams of tiling separate blurs.
+final class T3FrostedCutoutView: ExpoView {
+ var cutoutTop: CGFloat = 0 { didSet { setNeedsLayout() } }
+ var cutoutWidth: CGFloat = 0 { didSet { setNeedsLayout() } }
+ var cutoutHeight: CGFloat = 0 { didSet { setNeedsLayout() } }
+ var cutoutRadius: CGFloat = 0 { didSet { setNeedsLayout() } }
+ /// Follows the app theme, which can differ from the system appearance.
+ var appearance: String = "dark" {
+ didSet {
+ effectView.effect = UIBlurEffect(
+ style: appearance == "light" ? .systemThinMaterialLight : .systemThinMaterialDark)
+ }
+ }
+
+ private let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThinMaterialDark))
+ private let cutoutMaskView = UIView()
+ private let maskLayer = CAShapeLayer()
+
+ required init(appContext: AppContext? = nil) {
+ super.init(appContext: appContext)
+ isUserInteractionEnabled = false
+ maskLayer.fillRule = .evenOdd
+ cutoutMaskView.layer.addSublayer(maskLayer)
+ effectView.mask = cutoutMaskView
+ addSubview(effectView)
+ }
+
+ override func layoutSubviews() {
+ super.layoutSubviews()
+ effectView.frame = bounds
+ cutoutMaskView.frame = bounds
+ maskLayer.frame = bounds
+ let path = UIBezierPath(rect: bounds)
+ if cutoutWidth > 0, cutoutHeight > 0 {
+ let hole = CGRect(
+ x: (bounds.width - cutoutWidth) / 2,
+ y: cutoutTop,
+ width: cutoutWidth,
+ height: cutoutHeight
+ )
+ path.append(UIBezierPath(roundedRect: hole, cornerRadius: cutoutRadius))
+ }
+ maskLayer.path = path.cgPath
+ }
+}
diff --git a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift
index 3674e232ee5..3749badcd5e 100644
--- a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift
+++ b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift
@@ -54,6 +54,15 @@ public final class T3NativeControlsModule: Module {
}
}
+ View(T3FrostedCutoutView.self) {
+ ViewName("FrostedCutout")
+ Prop("cutoutTop") { (view: T3FrostedCutoutView, value: Double) in view.cutoutTop = CGFloat(value) }
+ Prop("cutoutWidth") { (view: T3FrostedCutoutView, value: Double) in view.cutoutWidth = CGFloat(value) }
+ Prop("cutoutHeight") { (view: T3FrostedCutoutView, value: Double) in view.cutoutHeight = CGFloat(value) }
+ Prop("cutoutRadius") { (view: T3FrostedCutoutView, value: Double) in view.cutoutRadius = CGFloat(value) }
+ Prop("appearance") { (view: T3FrostedCutoutView, value: String) in view.appearance = value }
+ }
+
View(T3ContextSheetSizeView.self) {
ViewName("ContextSheetSize")
Prop("contentHeight") { (view: T3ContextSheetSizeView, height: Double) in
diff --git a/apps/mobile/src/components/AndroidScreenHeader.tsx b/apps/mobile/src/components/AndroidScreenHeader.tsx
index a8841f39061..b660e267019 100644
--- a/apps/mobile/src/components/AndroidScreenHeader.tsx
+++ b/apps/mobile/src/components/AndroidScreenHeader.tsx
@@ -1,5 +1,5 @@
import { useState, type ReactNode } from "react";
-import { View } from "react-native";
+import { ActivityIndicator, View } from "react-native";
import type { AppSymbolName } from "./AppSymbol";
import { AppText as Text } from "./AppText";
@@ -14,6 +14,7 @@ export interface AndroidHeaderAction {
readonly icon: AppSymbolName;
readonly onPress: () => void;
readonly disabled?: boolean;
+ readonly loading?: boolean;
readonly selected?: boolean;
}
@@ -84,16 +85,26 @@ export function AndroidScreenHeader(props: {
) : null}
</View>
- {visibleActions.map((action) => (
- <AndroidHeaderIconButton
- key={action.accessibilityLabel}
- accessibilityLabel={action.accessibilityLabel}
- disabled={action.disabled}
- selected={action.selected}
- icon={action.icon}
- onPress={action.onPress}
- />
- ))}
+ {visibleActions.map((action) =>
+ action.loading ? (
+ <View
+ key={action.accessibilityLabel}
+ accessibilityLabel={action.accessibilityLabel}
+ className="size-12 items-center justify-center"
+ >
+ <ActivityIndicator colorClassName="accent-header-foreground" />
+ </View>
+ ) : (
+ <AndroidHeaderIconButton
+ key={action.accessibilityLabel}
+ accessibilityLabel={action.accessibilityLabel}
+ disabled={action.disabled}
+ selected={action.selected}
+ icon={action.icon}
+ onPress={action.onPress}
+ />
+ ),
+ )}
{overflowActions.length > 0 ? (
<AndroidAnchoredMenu
actions={overflowActions.map((action, index) => ({
diff --git a/apps/mobile/src/components/FrostedCutout.ios.tsx b/apps/mobile/src/components/FrostedCutout.ios.tsx
new file mode 100644
index 00000000000..af2db67465c
--- /dev/null
+++ b/apps/mobile/src/components/FrostedCutout.ios.tsx
@@ -0,0 +1,14 @@
+import { requireNativeView } from "expo";
+import { StyleSheet, type ViewProps } from "react-native";
+
+import type { FrostedCutoutProps } from "./FrostedCutout.types";
+
+const NativeFrostedCutout = requireNativeView<ViewProps & FrostedCutoutProps>(
+ "T3NativeControls",
+ "FrostedCutout",
+);
+
+/** Fills its parent with one native blur that leaves a rounded hole clear. */
+export function FrostedCutout(props: FrostedCutoutProps) {
+ return <NativeFrostedCutout {...props} pointerEvents="none" style={StyleSheet.absoluteFill} />;
+}
diff --git a/apps/mobile/src/components/FrostedCutout.tsx b/apps/mobile/src/components/FrostedCutout.tsx
new file mode 100644
index 00000000000..b26b3270324
--- /dev/null
+++ b/apps/mobile/src/components/FrostedCutout.tsx
@@ -0,0 +1,39 @@
+import { useState } from "react";
+import { StyleSheet, View } from "react-native";
+import Svg, { Path } from "react-native-svg";
+
+import type { FrostedCutoutProps } from "./FrostedCutout.types";
+
+/** Fills its parent with a theme-matched tint that leaves a rounded hole clear. iOS blurs instead. */
+export function FrostedCutout(props: FrostedCutoutProps) {
+ const [width, setWidth] = useState(0);
+ const [height, setHeight] = useState(0);
+ const x = (width - props.cutoutWidth) / 2;
+ const y = props.cutoutTop;
+ const w = props.cutoutWidth;
+ const h = props.cutoutHeight;
+ const r = Math.min(props.cutoutRadius, w / 2, h / 2);
+ const hole = `M${x + r},${y} H${x + w - r} A${r},${r} 0 0 1 ${x + w},${y + r} V${y + h - r} A${r},${r} 0 0 1 ${x + w - r},${y + h} H${x + r} A${r},${r} 0 0 1 ${x},${y + h - r} V${y + r} A${r},${r} 0 0 1 ${x + r},${y} Z`;
+
+ return (
+ <View
+ pointerEvents="none"
+ style={StyleSheet.absoluteFill}
+ onLayout={(event) => {
+ setWidth(event.nativeEvent.layout.width);
+ setHeight(event.nativeEvent.layout.height);
+ }}
+ >
+ {width > 0 ? (
+ <Svg height={height} width={width}>
+ <Path
+ d={`M0,0 H${width} V${height} H0 Z ${hole}`}
+ fill={props.appearance === "light" ? "#ffffff" : "#000000"}
+ fillOpacity={0.55}
+ fillRule="evenodd"
+ />
+ </Svg>
+ ) : null}
+ </View>
+ );
+}
diff --git a/apps/mobile/src/components/FrostedCutout.types.ts b/apps/mobile/src/components/FrostedCutout.types.ts
new file mode 100644
index 00000000000..2d5917a33b6
--- /dev/null
+++ b/apps/mobile/src/components/FrostedCutout.types.ts
@@ -0,0 +1,8 @@
+export interface FrostedCutoutProps {
+ /** Distance from the top edge to the clear hole; the hole is centered horizontally. */
+ readonly cutoutTop: number;
+ readonly cutoutWidth: number;
+ readonly cutoutHeight: number;
+ readonly cutoutRadius: number;
+ readonly appearance: "light" | "dark";
+}
diff --git a/apps/mobile/src/components/ScreenHeader.tsx b/apps/mobile/src/components/ScreenHeader.tsx
index 4a387757196..40a9be5a602 100644
--- a/apps/mobile/src/components/ScreenHeader.tsx
+++ b/apps/mobile/src/components/ScreenHeader.tsx
@@ -1,5 +1,6 @@
import type { HeaderBarButtonMailSearchToolbarItem } from "react-native-screens";
import { useId } from "react";
+import { ActivityIndicator, View } from "react-native";
import { createNativeHeaderMenu } from "./nativeHeaderMenu.ios";
import { ScreenHeaderButton } from "./ScreenHeaderButton";
import { NativeHeaderToolbar, NativeStackScreenOptions } from "../native/StackHeader";
@@ -139,14 +140,25 @@ export function ScreenHeader(props: ScreenHeaderProps) {
props.trailing) &&
props.options?.unstable_headerRightItems === undefined ? (
<NativeHeaderToolbar placement="right">
- {props.actions?.map((action) => (
- <ScreenHeaderButton
- key={action.accessibilityLabel}
- {...action}
- icon={iosIcon(action.icon)}
- separateBackground
- />
- ))}
+ {props.actions?.map(({ loading, ...action }) =>
+ loading ? (
+ <NativeHeaderToolbar.Custom key={action.accessibilityLabel}>
+ <View
+ accessibilityLabel={action.accessibilityLabel}
+ className="size-9 items-center justify-center"
+ >
+ <ActivityIndicator color={action.tintColor} />
+ </View>
+ </NativeHeaderToolbar.Custom>
+ ) : (
+ <ScreenHeaderButton
+ key={action.accessibilityLabel}
+ {...action}
+ icon={iosIcon(action.icon)}
+ separateBackground
+ />
+ ),
+ )}
{refresh && !compactSearch ? (
<ScreenHeaderButton
accessibilityLabel={search?.refreshAccessibilityLabel}
diff --git a/apps/mobile/src/components/ScreenHeader.types.ts b/apps/mobile/src/components/ScreenHeader.types.ts
index 3373181a356..6d308aff397 100644
--- a/apps/mobile/src/components/ScreenHeader.types.ts
+++ b/apps/mobile/src/components/ScreenHeader.types.ts
@@ -8,6 +8,8 @@ export interface ScreenHeaderAction {
readonly icon: AppSymbolName;
readonly onPress: () => void;
readonly disabled?: boolean;
+ /** Shows a spinner in place of the icon while the action's work is pending. */
+ readonly loading?: boolean;
readonly selected?: boolean;
readonly tintColor?: ColorValue;
}
diff --git a/apps/mobile/src/features/connection/ConnectionSheetButton.tsx b/apps/mobile/src/features/connection/ConnectionSheetButton.tsx
deleted file mode 100644
index e9ac17b665a..00000000000
--- a/apps/mobile/src/features/connection/ConnectionSheetButton.tsx
+++ /dev/null
@@ -1,111 +0,0 @@
-import { SymbolView } from "../../components/AppSymbol";
-import { Platform, Pressable } from "react-native";
-
-import { AppText as Text } from "../../components/AppText";
-import { cn } from "../../lib/cn";
-import { MaterialButton } from "../../components/MaterialButton";
-
-const CARD_SHADOW = Platform.select({
- ios: {
- shadowColor: "rgba(23,23,23,0.08)",
- shadowOffset: { width: 0, height: 4 },
- shadowOpacity: 1,
- shadowRadius: 16,
- },
- android: { elevation: 3 },
-});
-
-const CARD_SHADOW_DARK = Platform.select({
- ios: {
- shadowColor: "#000",
- shadowOffset: { width: 0, height: 2 },
- shadowOpacity: 0.18,
- shadowRadius: 8,
- },
- android: { elevation: 4 },
-});
-
-export { CARD_SHADOW, CARD_SHADOW_DARK };
-
-export function ConnectionSheetButton(props: {
- readonly icon: React.ComponentProps<typeof SymbolView>["name"];
- readonly label: string;
- readonly disabled?: boolean;
- readonly tone?: "primary" | "secondary" | "danger";
- readonly compact?: boolean;
- readonly fullWidth?: boolean;
- readonly onPress: () => void;
-}) {
- if (Platform.OS === "android")
- return (
- <MaterialButton
- label={props.label}
- disabled={props.disabled}
- onPress={props.onPress}
- tone={props.tone}
- fullWidth={props.fullWidth}
- />
- );
- const tone = props.tone ?? "secondary";
-
- const textColorClassName =
- tone === "primary"
- ? "accent-primary-foreground"
- : tone === "danger"
- ? "accent-danger-foreground"
- : "accent-secondary-foreground";
-
- const primaryShadow =
- tone === "primary"
- ? Platform.select({
- ios: {
- shadowColor: "#000",
- shadowOffset: { width: 0, height: 3 },
- shadowOpacity: 0.14,
- shadowRadius: 6,
- },
- android: { elevation: 3 },
- })
- : undefined;
-
- return (
- <Pressable
- accessibilityLabel={props.label}
- accessibilityRole="button"
- accessibilityState={{ disabled: props.disabled ?? false }}
- className={cn(
- props.compact
- ? "min-h-[42px] flex-row items-center justify-center gap-1.5 rounded-[14px] px-3.5 py-2.5"
- : "min-h-[48px] flex-row items-center justify-center gap-2 rounded-[16px] px-4 py-3",
- "disabled:opacity-50",
- tone === "primary"
- ? "bg-primary"
- : tone === "danger"
- ? "border border-danger-border bg-danger"
- : "border border-border bg-secondary",
- )}
- disabled={props.disabled}
- onPress={props.onPress}
- style={primaryShadow}
- >
- <SymbolView
- name={props.icon}
- size={props.compact ? 13 : 14}
- tintColorClassName={textColorClassName}
- type="monochrome"
- />
- <Text
- className={cn(
- "text-xs font-t3-bold tracking-[0.8px] uppercase",
- tone === "primary"
- ? "text-primary-foreground"
- : tone === "danger"
- ? "text-danger-foreground"
- : "text-secondary-foreground",
- )}
- >
- {props.label}
- </Text>
- </Pressable>
- );
-}
diff --git a/apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx b/apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx
index c633f67db79..81d48a94848 100644
--- a/apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx
+++ b/apps/mobile/src/features/connection/ConnectionsNewRouteScreen.tsx
@@ -1,7 +1,10 @@
import { ScreenScrollView as ScrollView } from "../../components/ScreenScrollView";
+import { useAuth } from "@clerk/expo";
import { CameraView, useCameraPermissions } from "expo-camera";
+import * as Haptics from "expo-haptics";
import {
StackActions,
+ useIsFocused,
useNavigation,
useRoute,
type StaticScreenProps,
@@ -9,16 +12,24 @@ import {
import type { EnvironmentId } from "@t3tools/contracts";
import { AsyncResult } from "effect/reactivity";
import { useCallback, useEffect, useRef, useState } from "react";
-import { Alert, Linking, Platform, View } from "react-native";
+import { Alert, Linking, Pressable, StyleSheet, View } from "react-native";
+import Svg, { Defs, RadialGradient, Rect, Stop } from "react-native-svg";
import { useSafeAreaInsets } from "react-native-safe-area-context";
+import { cn } from "../../lib/cn";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
+import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
import { SettingsScreen } from "../settings/components/SettingsScreen";
-import { AppText as Text } from "../../components/AppText";
-import { ErrorBanner } from "../../components/ErrorBanner";
-import { ConnectionFormField } from "./ConnectionFormField";
-import { ConnectionSheetButton } from "./ConnectionSheetButton";
+import { AppText as Text, AppTextInput, type AppTextInputProps } from "../../components/AppText";
+import { FrostedCutout } from "../../components/FrostedCutout";
import { buildPairingUrl, extractPairingUrlFromQrPayload, parsePairingUrl } from "./pairing";
-import { useRemoteConnections } from "../../state/use-remote-environment-registry";
+import {
+ setPendingConnectionError,
+ useRemoteConnections,
+} from "../../state/use-remote-environment-registry";
+import { SymbolView } from "../../components/AppSymbol";
+import { hasCloudPublicConfig } from "../cloud/publicConfig";
+import { CloudEnvironmentRows } from "./CloudEnvironmentRows";
+import { splitEnvironmentSections } from "./environmentSections";
type ConnectionsNewRouteParams = {
readonly mode?: string;
@@ -51,9 +62,11 @@ export function ConnectionsNewRouteScreen({
const [hostInput, setHostInput] = useState("");
const [codeInput, setCodeInput] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
- const [showScanner, setShowScanner] = useState(params.mode === "scan_qr");
const [cameraPermission, requestCameraPermission] = useCameraPermissions();
+ const screenFocused = useIsFocused();
const [scannerLocked, setScannerLocked] = useState(false);
+ // A good scan parks the camera so it can't re-read the code over later edits.
+ const [scanComplete, setScanComplete] = useState(false);
const attemptedAutoConnectRef = useRef<string | null>(null);
const headerIconColor = useUniwindTheme()["--color-icon"];
@@ -84,34 +97,25 @@ export function ConnectionsNewRouteScreen({
const handleHostChange = useCallback((value: string) => {
setHostInput(value);
+ setPendingConnectionError(null);
}, []);
const handleCodeChange = useCallback((value: string) => {
setCodeInput(value);
+ setPendingConnectionError(null);
}, []);
- const openScanner = useCallback(async () => {
- if (cameraPermission?.granted) {
- setScannerLocked(false);
- setShowScanner(true);
- return;
- }
+ // The error is shared app state; a stale failure must not greet the next visit.
+ useEffect(() => () => setPendingConnectionError(null), []);
+ // Opening the sheet never prompts; a tap on the scan card asks for the camera.
+ const handleScanPress = useCallback(async () => {
const permission = await requestCameraPermission();
if (permission.granted) {
- setScannerLocked(false);
- setShowScanner(true);
- return;
- }
-
- if (permission.canAskAgain) {
- Alert.alert(
- "Camera access needed",
- "Allow camera access to scan an environment pairing QR code.",
- );
+ setScanComplete(false);
return;
}
-
+ if (permission.canAskAgain) return;
Alert.alert(
"Camera access needed",
"Camera access was denied for this app. Open Settings to enable it.",
@@ -120,12 +124,7 @@ export function ConnectionsNewRouteScreen({
{ text: "Open Settings", onPress: () => void Linking.openSettings() },
],
);
- }, [cameraPermission?.granted, requestCameraPermission]);
-
- const closeScanner = useCallback(() => {
- setShowScanner(false);
- setScannerLocked(false);
- }, []);
+ }, [requestCameraPermission]);
const handleQrScan = useCallback(
({ data }: { readonly data: string }) => {
@@ -141,13 +140,14 @@ export function ConnectionsNewRouteScreen({
setHostInput(host);
setCodeInput(code);
onChangeConnectionPairingUrl(pairingUrl);
- setShowScanner(false);
+ setScanComplete(true);
+ setScannerLocked(false);
} catch (error) {
+ void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
Alert.alert(
"Invalid QR code",
error instanceof Error ? error.message : "Scanned QR code was not recognized.",
);
- } finally {
setTimeout(() => {
setScannerLocked(false);
}, 600);
@@ -162,6 +162,11 @@ export function ConnectionsNewRouteScreen({
onChangeConnectionPairingUrl(pairingUrl);
try {
const result = await onConnectPress(pairingUrl, params.routeFor);
+ void Haptics.notificationAsync(
+ AsyncResult.isSuccess(result)
+ ? Haptics.NotificationFeedbackType.Success
+ : Haptics.NotificationFeedbackType.Error,
+ );
if (AsyncResult.isSuccess(result)) {
if (replaceWithHome || !navigation.canGoBack()) {
navigation.dispatch(StackActions.replace("Home"));
@@ -192,96 +197,260 @@ export function ConnectionsNewRouteScreen({
return (
<SettingsScreen
formSheet={routeName === "ConnectionsNew"}
- title={showScanner ? "Scan QR Code" : "Add Environment"}
+ title="Add environment"
actions={[
{
- accessibilityLabel: showScanner ? "Close scanner" : "Scan QR code",
- icon: showScanner ? "xmark" : Platform.OS === "ios" ? "qrcode.viewfinder" : "camera",
+ accessibilityLabel: isSubmitting ? "Connecting" : "Add environment",
+ loading: isSubmitting,
+ icon: "checkmark",
tintColor: headerIconColor,
+ disabled: connectDisabled,
onPress: () => {
- if (showScanner) {
- closeScanner();
- } else {
- void openScanner();
- }
+ void handleSubmit();
},
},
]}
>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
+ keyboardShouldPersistTaps="handled"
showsVerticalScrollIndicator={false}
className="flex-1"
contentInset={{ bottom: Math.max(insets.bottom, 18) + 18 }}
contentContainerStyle={{
- paddingHorizontal: 20,
- paddingTop: 16,
+ paddingHorizontal: 16,
+ paddingTop: 4,
}}
>
- <View collapsable={false} className="gap-5">
- {showScanner ? (
- cameraPermission?.granted ? (
- <View className="overflow-hidden rounded-[24px] border-continuous">
- <CameraView
- barcodeScannerSettings={{ barcodeTypes: ["qr"] }}
- onBarcodeScanned={handleQrScan}
- style={{ aspectRatio: 1, width: "100%" }}
- />
- </View>
- ) : (
- <View className="items-center gap-3 rounded-[24px] border-continuous bg-grouped-card px-5 py-8">
- <Text className="text-center text-sm leading-normal text-foreground-muted">
- Camera permission is required to scan a QR code.
- </Text>
- <ConnectionSheetButton
- compact
- icon="camera"
- label="Allow camera"
- tone="secondary"
- onPress={() => {
- void openScanner();
- }}
- />
- </View>
- )
- ) : (
- <View collapsable={false} className="gap-4 rounded-[24px] bg-grouped-card p-4">
- <ConnectionFormField
- label="Host"
- autoCapitalize="none"
- autoCorrect={false}
+ <View collapsable={false} className="gap-6.5">
+ <PairingScanCard
+ cameraActive={cameraPermission?.granted === true && screenFocused && !scanComplete}
+ onScan={handleQrScan}
+ onScanPress={() => {
+ void handleScanPress();
+ }}
+ />
+
+ <View collapsable={false} className="gap-2">
+ <Text className="px-4 text-sm font-t3-medium text-foreground-muted">Or enter it</Text>
+ <View
+ collapsable={false}
+ className={cn(
+ "overflow-hidden rounded-[26px] border-continuous border bg-grouped-card",
+ pairingConnectionError ? "border-danger-foreground" : "border-transparent",
+ )}
+ >
+ <PairingInputRow
+ label="Address"
keyboardType="url"
- placeholder="192.168.1.100:8080"
+ placeholder="192.168.1.100:3773"
value={hostInput}
onChangeText={handleHostChange}
/>
-
- <ConnectionFormField
- label="Pairing code"
- autoCapitalize="none"
- autoCorrect={false}
- placeholder="abc-123-xyz"
+ <View className="ml-4 border-t border-border-subtle" />
+ <PairingInputRow
+ label="Code"
+ placeholder="Pairing code"
+ returnKeyType="go"
value={codeInput}
onChangeText={handleCodeChange}
+ onSubmitEditing={() => {
+ if (!connectDisabled) void handleSubmit();
+ }}
/>
-
- {pairingConnectionError ? <ErrorBanner message={pairingConnectionError} /> : null}
-
- <View className="android:flex-row android:justify-end">
- <ConnectionSheetButton
- icon="plus"
- label={isSubmitting ? "Pairing..." : "Add environment"}
- disabled={connectDisabled}
- tone="primary"
- onPress={() => {
- void handleSubmit();
- }}
- />
- </View>
</View>
- )}
+ <Text
+ accessibilityLiveRegion="polite"
+ className={cn(
+ "px-4 text-sm leading-normal",
+ pairingConnectionError ? "text-danger-foreground" : "text-foreground-muted",
+ )}
+ >
+ {pairingConnectionError ??
+ "For machines on your local network or tailnet. The machine keeps its own provider credentials."}
+ </Text>
+ </View>
+
+ {hasCloudPublicConfig() ? <T3ConnectSection /> : null}
</View>
</ScrollView>
</SettingsScreen>
);
}
+
+const SCAN_CARD_HEIGHT = 250;
+const SCAN_RETICLE_SIZE = 150;
+const SCAN_RETICLE_TOP = 36;
+const SCAN_RETICLE_RADIUS = 28;
+
+/**
+ * Live QR scanner: the camera fills the card, blurred everywhere except the
+ * reticle so the code being aimed at stays sharp. Without a camera it shows the
+ * same frame over a dark gradient.
+ */
+function PairingScanCard(props: {
+ readonly cameraActive: boolean;
+ readonly onScan: (result: { readonly data: string }) => void;
+ readonly onScanPress: () => void;
+}) {
+ const light = useAppearancePreferences().themeAppearance === "light";
+ return (
+ <Pressable
+ accessibilityRole={props.cameraActive ? undefined : "button"}
+ accessibilityLabel={props.cameraActive ? undefined : "Scan QR code"}
+ disabled={props.cameraActive}
+ onPress={props.onScanPress}
+ className={cn(
+ "overflow-hidden rounded-[26px] border-continuous",
+ light ? "bg-white" : "bg-black",
+ )}
+ style={{ height: SCAN_CARD_HEIGHT }}
+ >
+ <Svg accessibilityElementsHidden height="100%" style={StyleSheet.absoluteFill} width="100%">
+ <Defs>
+ <RadialGradient id="pairing-scan-backdrop" cx="50%" cy="50%" r="50%">
+ <Stop offset="0%" stopColor={light ? "#f4f4f5" : "#2e2e2e"} />
+ <Stop offset="100%" stopColor={light ? "#d9d9dc" : "#0e0e0e"} />
+ </RadialGradient>
+ </Defs>
+ <Rect fill="url(#pairing-scan-backdrop)" height="100%" width="100%" />
+ </Svg>
+
+ {props.cameraActive ? (
+ <>
+ <CameraView
+ active
+ barcodeScannerSettings={{ barcodeTypes: ["qr"] }}
+ onBarcodeScanned={props.onScan}
+ style={StyleSheet.absoluteFill}
+ />
+ <FrostedCutout
+ cutoutTop={SCAN_RETICLE_TOP}
+ cutoutWidth={SCAN_RETICLE_SIZE}
+ cutoutHeight={SCAN_RETICLE_SIZE}
+ cutoutRadius={SCAN_RETICLE_RADIUS}
+ appearance={light ? "light" : "dark"}
+ />
+ </>
+ ) : null}
+
+ <View
+ pointerEvents="none"
+ className="absolute inset-x-0 items-center gap-3.5"
+ style={{ top: SCAN_RETICLE_TOP }}
+ >
+ <View
+ className={cn(
+ "items-center justify-center gap-2 border-continuous border-[3px]",
+ light ? "border-black/70" : "border-white/80",
+ )}
+ style={{
+ borderRadius: SCAN_RETICLE_RADIUS,
+ height: SCAN_RETICLE_SIZE,
+ width: SCAN_RETICLE_SIZE,
+ }}
+ >
+ {props.cameraActive ? null : (
+ <>
+ <SymbolView
+ name="qrcode.viewfinder"
+ size={44}
+ tintColorClassName={light ? "accent-black/60" : "accent-white/70"}
+ type="monochrome"
+ weight="light"
+ />
+ <Text
+ className={cn("font-t3-medium text-sm", light ? "text-black/70" : "text-white/80")}
+ >
+ Tap to scan
+ </Text>
+ </>
+ )}
+ </View>
+ <Text className={cn("text-center text-sm", light ? "text-black/70" : "text-white/80")}>
+ Scan the code from t3 pair or desktop Connections settings
+ </Text>
+ </View>
+ </Pressable>
+ );
+}
+
+/**
+ * Managed-relay alternative to manual pairing: signed in, the account's
+ * published environments connect with a switch; signed out, one row opens the
+ * T3 Account sheet.
+ */
+function T3ConnectSection() {
+ const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
+ const navigation = useNavigation();
+ const { connectedEnvironments, onSetEnvironmentEnabled, onRemoveEnvironmentPress } =
+ useRemoteConnections();
+ const { connectedCloudEnvironments } = splitEnvironmentSections({
+ connectedEnvironments,
+ cloudEnvironments: null,
+ });
+
+ return (
+ <View collapsable={false} className="gap-2">
+ <Text className="px-4 text-sm font-t3-medium text-foreground-muted">
+ Or use the managed relay
+ </Text>
+ {isSignedIn ? (
+ <CloudEnvironmentRows
+ connectedCloudEnvironments={connectedCloudEnvironments}
+ onSetEnvironmentEnabled={onSetEnvironmentEnabled}
+ onRemoveEnvironment={onRemoveEnvironmentPress}
+ showHeader={false}
+ />
+ ) : (
+ <Pressable
+ accessibilityRole="button"
+ disabled={!isLoaded}
+ onPress={() => navigation.navigate("SettingsSheet", { screen: "SettingsAuth" })}
+ className="min-h-13 flex-row items-center gap-3 rounded-[26px] border-continuous bg-grouped-card px-4 active:opacity-70"
+ >
+ <View className="min-w-0 flex-1 py-3">
+ <Text className="text-base text-foreground">Sign in to T3 Connect</Text>
+ <Text className="text-sm text-foreground-muted">
+ Reach your machines from anywhere, no network setup.
+ </Text>
+ </View>
+ <SymbolView
+ name="chevron.right"
+ size={14}
+ tintColorClassName="accent-chevron"
+ type="monochrome"
+ weight="semibold"
+ />
+ </Pressable>
+ )}
+ </View>
+ );
+}
+
+/** Inline grouped-list field: fixed label column, input filling the rest. */
+function PairingInputRow({
+ label,
+ ...inputProps
+}: Omit<AppTextInputProps, "accessibilityLabel" | "className"> & {
+ readonly label: string;
+}) {
+ return (
+ <View collapsable={false} className="h-13 flex-row items-center gap-3 px-4">
+ <Text
+ accessibilityElementsHidden
+ importantForAccessibility="no-hide-descendants"
+ className="w-20 text-base leading-[23px] text-foreground-muted"
+ >
+ {label}
+ </Text>
+ <AppTextInput
+ {...inputProps}
+ accessibilityLabel={label}
+ autoCapitalize="none"
+ autoCorrect={false}
+ className="min-h-0 flex-1 rounded-none border-0 bg-transparent p-0 text-base leading-[23px]"
+ />
+ </View>
+ );
+}
diff --git a/apps/mobile/src/native/NativeHeaderToolbar.tsx b/apps/mobile/src/native/NativeHeaderToolbar.tsx
index 3bab99546bb..5bf5aa27c91 100644
--- a/apps/mobile/src/native/NativeHeaderToolbar.tsx
+++ b/apps/mobile/src/native/NativeHeaderToolbar.tsx
@@ -118,6 +118,10 @@ function convertToolbarChild(child: ReactNode): NativeStackHeaderItem | null {
}
const typeName = elementTypeName(child);
+ if (typeName === "NativeHeaderToolbarCustom" && isValidElement(child.props.children)) {
+ return { type: "custom", element: child.props.children };
+ }
+
if (typeName === "NativeHeaderToolbarButton") {
return {
type: "button",
@@ -263,6 +267,12 @@ function NativeHeaderToolbarMenuAction(_props: {
}
NativeHeaderToolbarMenuAction.displayName = "NativeHeaderToolbarMenuAction";
+/** Renders an arbitrary element as a bar item, e.g. a spinner standing in for a button. */
+function NativeHeaderToolbarCustom(_props: { readonly children: ReactElement }) {
+ return null;
+}
+NativeHeaderToolbarCustom.displayName = "NativeHeaderToolbarCustom";
+
function NativeHeaderToolbarLabel(_props: { readonly children?: ReactNode }) {
return null;
}
@@ -284,6 +294,7 @@ NativeHeaderToolbarSearchBarSlot.displayName = "NativeHeaderToolbarSearchBarSlot
export const NativeHeaderToolbar = Object.assign(NativeHeaderToolbarRoot, {
Button: NativeHeaderToolbarButton,
+ Custom: NativeHeaderToolbarCustom,
Label: NativeHeaderToolbarLabel,
Menu: Object.assign(NativeHeaderToolbarMenu, {
Action: NativeHeaderToolbarMenuAction,