GeezerVison is showing github.com — Merge remote-tracking branch 'origin/main' into fix/composer-banner-b… · pingdotgg/t3code@b95ba8f
File treeExpand file treeCollapse file tree Open diff view settings modules/t3-composer-editor
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -749,6 +749,7 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro | 749 | 749 |
| 750 | 750 | func setPlaceholder(_ placeholder: String) { | 751 | 751 | placeholderLabel.text = placeholder | | 752 | + textView.accessibilityLabel = placeholder | 752 | 753 | setNeedsLayout() | 753 | 754 | } | 754 | 755 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/modules/t3-composer-editor/tests/ios/main.swift +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -139,6 +139,13 @@ do { | 139 | 139 | check(view.text.utf16.elementsEqual("@e\u{0301}".utf16), "A renormalized chip source kept the old text") | 140 | 140 | } | 141 | 141 |
| | 142 | +// The placeholder label is hidden from VoiceOver, so the text view must carry it. | | 143 | +do { | | 144 | + let view = makeEditor("") | | 145 | + view.setPlaceholder("Ask anything") | | 146 | + check(view.editor.accessibilityLabel == "Ask anything", "VoiceOver label: \(String(describing: view.editor.accessibilityLabel))") | | 147 | +} | | 148 | + | 142 | 149 | print("composer editor tests passed") | 143 | 150 |
| 144 | 151 | private let dropEditor = ComposerTextView() | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/components/ComposerEditor.ios.test.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -128,7 +128,7 @@ vi.mock("../lib/useUniwindTheme", () => ({ useUniwindTheme: () => ({}) })); | 128 | 128 | vi.mock("../lib/nativeComposerTheme", () => ({ createNativeComposerTheme: () => ({}) })); | 129 | 129 | vi.mock("../lib/contextChipIconSource", () => ({ contextChipIconUri: () => "" })); | 130 | 130 | vi.mock("../features/settings/appearance/useScaledTextRole", () => ({ | 131 | | - useScaledTextRole: () => ({ fontSize: 16, lineHeight: 22 }), | | 131 | + useComposerTextRole: () => ({ fontSize: 16, lineHeight: 22 }), | 132 | 132 | })); | 133 | 133 | vi.mock("../lib/uuid", () => ({ uuidv4: () => "uuid", randomHex: () => "0000" })); | 134 | 134 | vi.mock("../state/assets", () => ({ assetEnvironment: {} })); | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx +9-5Lines changed: 9 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -107,7 +107,10 @@ function ColumnScreen(props: { | 107 | 107 | readonly selectedThreadKey?: string | null; | 108 | 108 | readonly selectedPullRequestKey?: string | null; | 109 | 109 | readonly onDismiss: (routeKey: string, native: boolean) => void; | 110 | | - readonly onAppearance: (type: "willAppear" | "didAppear" | "willDisappear", key: string) => void; | | 110 | + readonly onAppearance: ( | | 111 | + type: "willAppear" | "didAppear" | "willDisappear" | "didDisappear", | | 112 | + key: string, | | 113 | + ) => void; | 111 | 114 | readonly onCompose?: () => void; | 112 | 115 | readonly navigation: ViewProps["navigation"]; | 113 | 116 | readonly footer?: ReactNode; | @@ -152,9 +155,10 @@ function ColumnScreen(props: { | 152 | 155 | props.onAppearance("willDisappear", key); | 153 | 156 | props.navigation.emit({ type: "transitionStart", target: key, data: { closing: true } }); | 154 | 157 | }} | 155 | | - onDidDisappear={() => | 156 | | - props.navigation.emit({ type: "transitionEnd", target: key, data: { closing: true } }) | 157 | | - } | | 158 | + onDidDisappear={() => { | | 159 | + props.onAppearance("didDisappear", key); | | 160 | + props.navigation.emit({ type: "transitionEnd", target: key, data: { closing: true } }); | | 161 | + }} | 158 | 162 | > | 159 | 163 | <PaneContext value={sidebar ? "sidebar" : "content"}> | 160 | 164 | <NavigationContext value={descriptor.navigation}> | @@ -307,7 +311,7 @@ function WorkspaceColumns( | 307 | 311 | } | 308 | 312 | }; | 309 | 313 | const followCollapsedSplit = ( | 310 | | - type: "willAppear" | "didAppear" | "willDisappear", | | 314 | + type: "willAppear" | "didAppear" | "willDisappear" | "didDisappear", | 311 | 315 | key: string, | 312 | 316 | ) => { | 313 | 317 | if (!collapsed.current || layout.usesSplitView) return; | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/settings/appearance/useScaledTextRole.ts +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { resolveScaledTextRole } from "../../../lib/appearancePreferences"; | | 1 | +import { Platform, useWindowDimensions } from "react-native"; | | 2 | + | | 3 | +import { resolveComposerTextRole, resolveScaledTextRole } from "../../../lib/appearancePreferences"; | 2 | 4 | import { MOBILE_TYPOGRAPHY } from "../../../lib/typography"; | 3 | 5 | import { useAppearancePreferences } from "./AppearancePreferencesProvider"; | 4 | 6 |
| @@ -12,3 +14,9 @@ export function useScaledTextRole(role: keyof typeof MOBILE_TYPOGRAPHY): ScaledT | 12 | 14 | const { appearance } = useAppearancePreferences(); | 13 | 15 | return resolveScaledTextRole(role, appearance.baseFontSize); | 14 | 16 | } | | 17 | + | | 18 | +export function useComposerTextRole(): ScaledTextRole { | | 19 | + const body = useScaledTextRole("body"); | | 20 | + const { fontScale } = useWindowDimensions(); | | 21 | + return resolveComposerTextRole(body, fontScale, Platform.OS); | | 22 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/ThreadComposer.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -96,7 +96,7 @@ import { | 96 | 96 | isModelSelectionUnavailable, | 97 | 97 | serverConfigForCwd, | 98 | 98 | } from "../../lib/modelOptions"; | 99 | | -import { useScaledTextRole, type ScaledTextRole } from "../settings/appearance/useScaledTextRole"; | | 99 | +import { useComposerTextRole, type ScaledTextRole } from "../settings/appearance/useScaledTextRole"; | 100 | 100 | import type { RemoteClientConnectionState } from "../../lib/connection"; | 101 | 101 | import { MOBILE_TYPOGRAPHY } from "../../lib/typography"; | 102 | 102 | import { Menu } from "../../components/ui/Menu"; | @@ -432,7 +432,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps | 432 | 432 | const composerPanel = materialTheme["--color-composer-panel"]; | 433 | 433 | const navigation = useNavigation(); | 434 | 434 | const foregroundColor = useUniwindTheme()["--color-foreground"]; | 435 | | - const bodyText = useScaledTextRole("body"); | | 435 | + const bodyText = useComposerTextRole(); | 436 | 436 | const fallbackInputRef = useRef<ComposerEditorHandle>(null); | 437 | 437 | const inputRef = props.editorRef ?? fallbackInputRef; | 438 | 438 | const [isFocused, setIsFocused] = useState(false); | |
Collapse file Copy file name to clipboard +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { describe, expect, it } from "vite-plus/test"; | 2 | 2 |
| 3 | | -import { resolveAppearancePreferences } from "./appearancePreferences"; | | 3 | +import { resolveAppearancePreferences, resolveComposerTextRole } from "./appearancePreferences"; | 4 | 4 |
| 5 | 5 | describe("appearancePreferences", () => { | 6 | 6 | it("migrates the legacy markdownFontSize key to baseFontSize", () => { | @@ -9,4 +9,14 @@ describe("appearancePreferences", () => { | 9 | 9 | resolveAppearancePreferences({ baseFontSize: 16, markdownFontSize: 18 }).baseFontSize, | 10 | 10 | ).toBe(16); | 11 | 11 | }); | | 12 | + | | 13 | + it("scales the iOS composer text with the system text size", () => { | | 14 | + const body = { fontSize: 16, lineHeight: 23 }; | | 15 | + expect(resolveComposerTextRole(body, 1, "ios")).toEqual(body); | | 16 | + expect(resolveComposerTextRole(body, 2.643, "ios")).toEqual({ | | 17 | + fontSize: 16 * 2.643, | | 18 | + lineHeight: 23 * 2.643, | | 19 | + }); | | 20 | + expect(resolveComposerTextRole(body, 2.643, "android")).toEqual(body); | | 21 | + }); | 12 | 22 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/appearancePreferences.ts +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -205,6 +205,17 @@ export function resolveScaledTextRole(role: keyof typeof MOBILE_TYPOGRAPHY, base | 205 | 205 | }; | 206 | 206 | } | 207 | 207 |
| | 208 | +// React Native text applies the system text size itself, but the iOS composer sets a fixed | | 209 | +// UIFont, so it needs pre-scaled metrics. Android's editor already sizes text in sp. | | 210 | +export function resolveComposerTextRole( | | 211 | + role: { readonly fontSize: number; readonly lineHeight: number }, | | 212 | + fontScale: number, | | 213 | + os: string, | | 214 | +) { | | 215 | + if (os !== "ios") return role; | | 216 | + return { fontSize: role.fontSize * fontScale, lineHeight: role.lineHeight * fontScale }; | | 217 | +} | | 218 | + | 208 | 219 | export function resolveNativeMarkdownTypography(baseFontSize: number): NativeMarkdownTypography { | 209 | 220 | const fontSizes = resolveMarkdownFontSizes(baseFontSize); | 210 | 221 | return { | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/native/T3ComposerEditor.ios.tsx +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,7 @@ import { contextChipIconUri, modelChipIcon, modelChipIconUri } from "../lib/cont | 27 | 27 | import { useUniwindTheme } from "../lib/useUniwindTheme"; | 28 | 28 | import { createNativeComposerTheme } from "../lib/nativeComposerTheme"; | 29 | 29 | import { FONT_FAMILIES } from "../lib/fontFamilies"; | 30 | | -import { useScaledTextRole } from "../features/settings/appearance/useScaledTextRole"; | | 30 | +import { useComposerTextRole } from "../features/settings/appearance/useScaledTextRole"; | 31 | 31 | import { | 32 | 32 | acknowledgeComposerNativeEvent, | 33 | 33 | assumeComposerControlledState, | @@ -176,7 +176,7 @@ export function ComposerEditor({ | 176 | 176 | }); | 177 | 177 | setConfirmedTokens({ value: props.value, tokens }); | 178 | 178 | } | 179 | | - const bodyText = useScaledTextRole("body"); | | 179 | + const bodyText = useComposerTextRole(); | 180 | 180 | const theme = useUniwindTheme(); | 181 | 181 | const fontFamily = FONT_FAMILIES.regular; | 182 | 182 |
| |
Collapse file Copy file name to clipboard +95Lines changed: 95 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import type { ParamListBase, StackNavigationState } from "@react-navigation/native"; | | 2 | +import { act, createContext, type ComponentProps, type ReactNode } from "react"; | | 3 | +import { createRoot } from "react-dom/client"; | | 4 | +import type { Stack as NativeStack } from "react-native-screens"; | | 5 | +import { expect, it, vi } from "vite-plus/test"; | | 6 | + | | 7 | +type ScreenProps = ComponentProps<typeof NativeStack.Screen>; | | 8 | +const screens = vi.hoisted(() => new Map<string, ScreenProps>()); | | 9 | + | | 10 | +vi.mock("react-native", () => ({ | | 11 | + StyleSheet: { flatten: (style: unknown) => style }, | | 12 | + View: ({ children }: { children?: ReactNode }) => children, | | 13 | +})); | | 14 | +vi.mock("react-native-screens", () => ({ | | 15 | + Stack: { | | 16 | + Host: ({ children }: { children?: ReactNode }) => children, | | 17 | + Screen: (props: ScreenProps) => { | | 18 | + screens.set(props.screenKey, props); | | 19 | + return null; | | 20 | + }, | | 21 | + }, | | 22 | +})); | | 23 | +vi.mock("@react-navigation/native", () => ({ | | 24 | + NavigationContext: createContext(undefined), | | 25 | + NavigationRouteContext: createContext(undefined), | | 26 | + usePreventRemoveContext: () => ({ preventedRoutes: {} }), | | 27 | +})); | | 28 | +vi.mock("@react-navigation/native-stack", () => ({ NativeStackView: () => null })); | | 29 | +vi.mock("./V5StackHeader.ios", () => ({ V5StackHeader: () => null })); | | 30 | +vi.mock("./NativeColumnContent.ios", () => ({ NativeColumnContent: () => null })); | | 31 | +vi.mock("./NativeScrollViewMarker", () => ({ | | 32 | + NativeScrollEdgeEffectsContext: createContext(undefined), | | 33 | +})); | | 34 | + | | 35 | +import { V5CardStackView, type V5StackViewProps } from "./createV5StackNavigator.ios"; | | 36 | + | | 37 | +const home = { key: "home", name: "Home" }; | | 38 | +const thread = { key: "thread", name: "Thread" }; | | 39 | + | | 40 | +function fire(key: string, event: "onWillAppear" | "onWillDisappear" | "onDidDisappear") { | | 41 | + const handler = screens.get(key)?.[event] as (() => void) | undefined; | | 42 | + if (!handler) throw new Error(`No ${event} for ${key}`); | | 43 | + act(() => handler()); | | 44 | +} | | 45 | + | | 46 | +it("forgets native Back when a full-screen presentation covers the top card", () => { | | 47 | + vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true); | | 48 | + const state: StackNavigationState<ParamListBase> = { | | 49 | + key: "stack", | | 50 | + type: "stack", | | 51 | + stale: false, | | 52 | + index: 1, | | 53 | + routeNames: ["Home", "Thread"], | | 54 | + routes: [home, thread], | | 55 | + preloadedRoutes: [], | | 56 | + }; | | 57 | + const navigation = { getState: () => state, emit: vi.fn(), dispatch: vi.fn() }; | | 58 | + const descriptor = (route: typeof home) => ({ | | 59 | + route, | | 60 | + navigation, | | 61 | + options: {}, | | 62 | + render: () => null, | | 63 | + }); | | 64 | + const onNativePopChange = vi.fn(); | | 65 | + const root = createRoot(document.createElement("div")); | | 66 | + try { | | 67 | + act(() => | | 68 | + root.render( | | 69 | + <V5CardStackView | | 70 | + {...({ | | 71 | + state, | | 72 | + navigation, | | 73 | + descriptors: { home: descriptor(home), thread: descriptor(thread) }, | | 74 | + describe: () => descriptor(home), | | 75 | + } as unknown as V5StackViewProps)} | | 76 | + onNativePopChange={onNativePopChange} | | 77 | + />, | | 78 | + ), | | 79 | + ); | | 80 | + | | 81 | + // A presentation covers the thread: nothing in the stack appears beneath it. | | 82 | + fire("thread", "onWillDisappear"); | | 83 | + fire("thread", "onDidDisappear"); | | 84 | + expect(onNativePopChange).toHaveBeenLastCalledWith(null); | | 85 | + | | 86 | + // Native Back reveals Home, so the thread stays the card being popped. | | 87 | + fire("thread", "onWillDisappear"); | | 88 | + fire("home", "onWillAppear"); | | 89 | + fire("thread", "onDidDisappear"); | | 90 | + expect(onNativePopChange).toHaveBeenLastCalledWith("thread"); | | 91 | + } finally { | | 92 | + act(() => root.unmount()); | | 93 | + vi.unstubAllGlobals(); | | 94 | + } | | 95 | +}); |
|