TypeScript
fix(mobile): iOS composer text stays vertically aligned at every text size (#17855)
Akbar Danial Akmad6c67ceb1f9d
diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsxindex 041855e4bba..705772f054f 100644--- a/apps/mobile/src/features/threads/ThreadComposer.tsx+++ b/apps/mobile/src/features/threads/ThreadComposer.tsx@@ -88,8 +88,9 @@ import {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 @@ import {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));+}+export const COMPOSER_EXPANDED_CHROME = 156;export interface ThreadComposerProps {@@ -914,7 +929,9 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps}scrollEnabled={isExpanded}singleLineCentered={!isExpanded}- contentInsetVertical={isExpanded || Platform.OS === "android" ? 0 : 6}+ contentInsetVertical={+ isExpanded || Platform.OS === "android" ? 0 : collapsedEditorInset(bodyText)+ }style={isExpanded? {