Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): iOS composer text stays vertically aligned at every text size #17855

Mergedakbarakma(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/17855/headmerged by juliusmarminge View on GitHub

Showing 1 changed file with 19 additions and 2 deletions.

x
0 of 1 viewed, 1 left
19 additions and 2 deletionsapps/mobile/src/features/threads/ThreadComposer.tsxModified
View file
@@ -88,8 +88,9 @@
groupByProvider,
isModelSelectionUnavailable,
} from "../../lib/modelOptions";
-import { useScaledTextRole } from "../settings/appearance/useScaledTextRole";
+import { useScaledTextRole, type ScaledTextRole } from "../settings/appearance/useScaledTextRole";
import type { RemoteClientConnectionState } from "../../lib/connection";
+import { MOBILE_TYPOGRAPHY } from "../../lib/typography";
import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
import { Menu } from "../../components/ui/Menu";
import type { ActiveTurnComposerAction } from "@t3tools/client-runtime/state/composer-dispatch";
@@ -127,6 +128,20 @@
​
export const COMPOSER_COLLAPSED_CHROME = 60;
​
+const COLLAPSED_EDITOR_DEFAULT_INSET = 6;
+// iOS puts line-height slack above glyphs. DM Sans's lowercase midline is
+// descender (0.31em) + half x-height (0.504em) above the line bottom.
+const LOWERCASE_MIDLINE_EM = 0.562;
+​
+function lowercaseMidline(text: ScaledTextRole): number {
+ return text.lineHeight - LOWERCASE_MIDLINE_EM * text.fontSize;
+}
+​
+function collapsedEditorInset(text: ScaledTextRole): number {
+ const shift = lowercaseMidline(text) - lowercaseMidline(MOBILE_TYPOGRAPHY.body);
+ return Math.max(0, Math.round(COLLAPSED_EDITOR_DEFAULT_INSET - shift));
+}
+​