Skip to content

Commit dac3437

Browse files
juliusmarmingePixPMusict3dotggclaude
authored
fix(mobile): the composer stays one row until the draft wraps (pingdotgg#20812)
Co-authored-by: Pixel Perfect <[email protected]> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Claude Fable 5.1 <[email protected]>
1 parent 7e289ae commit dac3437

22 files changed

Lines changed: 469 additions & 201 deletions
-765 KB
Binary file not shown.
765 KB
Binary file not shown.

‎apps/mobile/modules/t3-composer-editor/android/src/main/java/expo/modules/t3composereditor/T3ComposerEditorView.kt‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
5757
private var applyingNativeValue = false
5858
private var desiredLineHeightPx = 0
5959
private var lastContentHeight = 0
60+
private var lastContentWidth = 0
6061
private var contentInsetVertical = 0
6162
private var tokensJson = "[]"
6263
private var tokens: List<ComposerToken> = emptyList()
@@ -424,12 +425,19 @@ class T3ComposerEditorView(context: Context, appContext: AppContext) : ExpoView(
424425
}
425426

426427
private fun emitContentSizeIfNeeded() {
427-
val height = editor.layout?.height ?: editor.measuredHeight
428-
val contentHeight = height + contentInsetVertical * 2
429-
if (contentHeight == lastContentHeight) return
428+
// The laid-out text without insets. A one-line draft reports its natural width, so
429+
// JS can tell whether it fits a narrower row than the one it is laid out in; past
430+
// one line only the height matters. Trailing whitespace hangs past a line without
431+
// wrapping it, so getLineMax leaves it out.
432+
val layout = editor.layout
433+
val contentHeight = layout?.height ?: editor.measuredHeight
434+
val contentWidth = if (layout?.lineCount == 1) layout.getLineMax(0).toInt() else 0
435+
if (contentHeight == lastContentHeight && contentWidth == lastContentWidth) return
430436
lastContentHeight = contentHeight
437+
lastContentWidth = contentWidth
438+
val density = resources.displayMetrics.density
431439
onComposerContentSizeChange(
432-
mapOf("height" to contentHeight / resources.displayMetrics.density),
440+
mapOf("width" to contentWidth / density, "height" to contentHeight / density),
433441
)
434442
}
435443

‎apps/mobile/modules/t3-composer-editor/ios/T3ComposerEditorView.swift‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,28 @@ public final class T3ComposerEditorView: ExpoView, UITextViewDelegate, UITextDro
12301230
}
12311231

12321232
private func emitContentSizeIfNeeded() {
1233-
let nextSize = textView.contentSize
1233+
// The laid-out text without insets. A one-line draft reports its natural width, so
1234+
// JS can tell whether it fits a narrower row than the one it is laid out in; past
1235+
// one line only the height matters, so layout stops at the second line. The width
1236+
// comes from the line fragment because usedRect spans the container once the view
1237+
// scrolls. A trailing newline's empty line only exists as the extra fragment.
1238+
let layout = textView.layoutManager
1239+
let container = textView.textContainer
1240+
var lines = 0
1241+
var width: CGFloat = 0
1242+
var height: CGFloat = 0
1243+
let glyphs = NSRange(location: 0, length: layout.numberOfGlyphs)
1244+
layout.enumerateLineFragments(forGlyphRange: glyphs) { _, used, _, _, stop in
1245+
lines += 1
1246+
width = used.width
1247+
height = used.maxY
1248+
if lines > 1 { stop.pointee = true }
1249+
}
1250+
if lines < 2, layout.extraLineFragmentTextContainer === container {
1251+
lines += 1
1252+
height = max(height, layout.extraLineFragmentUsedRect.maxY)
1253+
}
1254+
let nextSize = CGSize(width: lines == 1 ? ceil(width) : 0, height: ceil(height))
12341255
guard abs(nextSize.width - lastContentSize.width) > 0.5 ||
12351256
abs(nextSize.height - lastContentSize.height) > 0.5 else {
12361257
return

‎apps/mobile/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"react-native-pdf-jsi": "5.0.0",
135135
"react-native-reanimated": "4.7.1",
136136
"react-native-safe-area-context": "~5.10.1",
137-
"react-native-screens": "file:deps/react-native-screens-5.0.0-t3.29.tgz",
137+
"react-native-screens": "file:deps/react-native-screens-5.0.0-t3.30.tgz",
138138
"react-native-shiki-engine": "^0.3.12",
139139
"react-native-svg": "15.16.0",
140140
"react-native-webview": "14.0.1",

‎apps/mobile/src/components/ComposerToolbar.tsx‎

Lines changed: 76 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
type ViewStyle,
1414
} from "react-native";
1515

16+
import Animated, { FadeIn, LinearTransition } from "react-native-reanimated";
17+
1618
import { cn } from "../lib/cn";
1719
import { AppText as Text } from "./ui/AppText";
1820
import { SymbolView } from "./ui/AppSymbol";
@@ -21,6 +23,10 @@ import { useAndroidControlSizing } from "./ui/useAndroidControlSizing";
2123
const COMPOSER_TOOLBAR_GAP = 8;
2224
const COMPOSER_TOOLBAR_FADE_WIDTH = 18;
2325
const COMPOSER_TOOLBAR_SCROLL_EPSILON = 4;
26+
const INLINE_CONTROL_LABEL_ENTERING = FadeIn.duration(160);
27+
// Android runs no composer layout transitions, so the toolbar never trails the dock.
28+
const INLINE_CONTROL_WIDTH_TRANSITION =
29+
Platform.OS === "android" ? undefined : LinearTransition.duration(180);
2430

2531
export function ComposerInlineControl(props: {
2632
readonly accessibilityHint?: string;
@@ -30,6 +36,8 @@ export function ComposerInlineControl(props: {
3036
readonly icon?: ComponentProps<typeof SymbolView>["name"];
3137
readonly renderIcon?: (size: number) => ReactNode;
3238
readonly label: string;
39+
/** Show only the icon and chevron; the label still names the control for accessibility. */
40+
readonly iconOnly?: boolean;
3341
readonly maxWidth?: ViewStyle["maxWidth"];
3442
readonly onPress?: () => void;
3543
readonly selected?: boolean;
@@ -38,56 +46,77 @@ export function ComposerInlineControl(props: {
3846
readonly showChevron?: boolean;
3947
}) {
4048
const { scale, smallIconSize } = useAndroidControlSizing();
49+
// The label fades in as the control widens, and leaves at once: an exiting view keeps
50+
// drawing at its old place while the chevron moves into it. The clip keeps content laid out
51+
// at the final width inside the frame while it eases there.
52+
const animatesLabel = props.iconOnly !== undefined;
4153
return (
42-
<Pressable
43-
accessibilityLabel={props.accessibilityLabel ?? props.label}
44-
accessibilityHint={props.accessibilityHint}
45-
accessibilityRole={props.static ? undefined : "button"}
46-
accessibilityState={
47-
props.static ? undefined : { disabled: props.disabled, selected: props.selected }
48-
}
49-
className="h-11 flex-row items-center gap-2 rounded-xl px-2 active:bg-subtle"
50-
disabled={props.disabled || props.static}
51-
onPress={props.onPress}
52-
style={{ maxWidth: props.maxWidth ?? 190, opacity: props.disabled ? 0.45 : 1 }}
54+
<Animated.View
55+
layout={animatesLabel ? INLINE_CONTROL_WIDTH_TRANSITION : undefined}
56+
style={{
57+
maxWidth: props.maxWidth ?? 190,
58+
overflow: animatesLabel ? "hidden" : undefined,
59+
}}
5360
>
54-
{props.renderIcon ? (
55-
<View
56-
className="size-4 shrink-0 items-center justify-center"
57-
style={Platform.OS === "android" ? { width: 14 * scale, height: 14 * scale } : undefined}
58-
>
59-
{props.renderIcon(smallIconSize)}
60-
</View>
61-
) : props.icon ? (
62-
<SymbolView
63-
name={props.icon}
64-
size={smallIconSize}
65-
tintColorClassName={
66-
props.emphasized || props.selected ? "accent-icon" : "accent-icon-muted"
67-
}
68-
type="monochrome"
69-
/>
70-
) : null}
71-
<Text
72-
className={cn(
73-
"shrink text-sm font-t3-medium",
74-
props.emphasized || props.selected ? "text-foreground" : "text-foreground-muted",
75-
)}
76-
numberOfLines={1}
61+
<Pressable
62+
accessibilityLabel={props.accessibilityLabel ?? props.label}
63+
accessibilityHint={props.accessibilityHint}
64+
accessibilityRole={props.static ? undefined : "button"}
65+
accessibilityState={
66+
props.static ? undefined : { disabled: props.disabled, selected: props.selected }
67+
}
68+
className="h-11 flex-row items-center gap-2 rounded-xl px-2 active:bg-subtle"
69+
disabled={props.disabled || props.static}
70+
onPress={props.onPress}
71+
style={{ opacity: props.disabled ? 0.45 : 1 }}
7772
>
78-
{props.label}
79-
</Text>
80-
{props.showChevron === false ? null : (
81-
<SymbolView
82-
name={props.chevronDirection === "right" ? "chevron.right" : "chevron.down"}
83-
size={Math.round(10 * scale)}
84-
tintColorClassName={
85-
props.emphasized || props.selected ? "accent-icon" : "accent-icon-muted"
86-
}
87-
type="monochrome"
88-
/>
89-
)}
90-
</Pressable>
73+
{props.renderIcon ? (
74+
<View
75+
className="size-4 shrink-0 items-center justify-center"
76+
style={
77+
Platform.OS === "android" ? { width: 14 * scale, height: 14 * scale } : undefined
78+
}
79+
>
80+
{props.renderIcon(smallIconSize)}
81+
</View>
82+
) : props.icon ? (
83+
<SymbolView
84+
name={props.icon}
85+
size={smallIconSize}
86+
tintColorClassName={
87+
props.emphasized || props.selected ? "accent-icon" : "accent-icon-muted"
88+
}
89+
type="monochrome"
90+
/>
91+
) : null}
92+
{props.iconOnly ? null : (
93+
<Animated.View
94+
className="shrink"
95+
entering={animatesLabel ? INLINE_CONTROL_LABEL_ENTERING : undefined}
96+
>
97+
<Text
98+
className={cn(
99+
"text-sm font-t3-medium",
100+
props.emphasized || props.selected ? "text-foreground" : "text-foreground-muted",
101+
)}
102+
numberOfLines={1}
103+
>
104+
{props.label}
105+
</Text>
106+
</Animated.View>
107+
)}
108+
{props.showChevron === false ? null : (
109+
<SymbolView
110+
name={props.chevronDirection === "right" ? "chevron.right" : "chevron.down"}
111+
size={Math.round(10 * scale)}
112+
tintColorClassName={
113+
props.emphasized || props.selected ? "accent-icon" : "accent-icon-muted"
114+
}
115+
type="monochrome"
116+
/>
117+
)}
118+
</Pressable>
119+
</Animated.View>
91120
);
92121
}
93122

‎apps/mobile/src/components/ui/AndroidScreenHeader.tsx‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AppActivityIndicator } from "./AppActivityIndicator";
2-
import { Column, Text as NativeText, RNHostView } from "@expo/ui/jetpack-compose";
2+
import { Column, Row, Text as NativeText, RNHostView } from "@expo/ui/jetpack-compose";
3+
import { weight } from "@expo/ui/jetpack-compose/modifiers";
34
import { useState, type ReactNode } from "react";
45
import { View } from "react-native";
56

@@ -43,6 +44,8 @@ export function AndroidScreenHeader(props: {
4344
readonly onBack?: () => void;
4445
readonly embedded?: boolean;
4546
readonly hideBottomBorder?: boolean;
47+
/** One row with the subtitle after the title, for screens short on height. */
48+
readonly compact?: boolean;
4649
}) {
4750
const { colors } = useControlTheme();
4851
const titleTypography = useScaledTextRole("title");
@@ -65,6 +68,7 @@ export function AndroidScreenHeader(props: {
6568
}}
6669
>
6770
<NativeAppBar
71+
singleLine={props.compact}
6872
navigationIcon={
6973
props.onBack || props.leading ? (
7074
<View collapsable={false} className="flex-row items-center">
@@ -95,6 +99,26 @@ export function AndroidScreenHeader(props: {
9599
>
96100
{props.title}
97101
</NativeText>
102+
) : props.compact ? (
103+
<Row verticalAlignment="center" horizontalArrangement={{ spacedBy: 8 }}>
104+
<NativeText
105+
color={colors["--color-header-foreground"]}
106+
maxLines={1}
107+
overflow="ellipsis"
108+
style={titleTypography}
109+
>
110+
{props.title}
111+
</NativeText>
112+
<NativeText
113+
color={colors["--color-foreground-muted"]}
114+
maxLines={1}
115+
overflow="ellipsis"
116+
style={subtitleTypography}
117+
modifiers={[weight(1)]}
118+
>
119+
{props.subtitle}
120+
</NativeText>
121+
</Row>
98122
) : (
99123
<Column>
100124
<NativeText

‎apps/mobile/src/components/ui/AppBar.android.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export function AppBar(props: AppBarProps) {
158158
onBack={props.onBack}
159159
leading={props.sidebar !== false ? <AndroidWorkspaceSidebarButton /> : undefined}
160160
hideBottomBorder={props.hideBottomBorder}
161+
compact={props.compact}
161162
actions={
162163
search
163164
? [

‎apps/mobile/src/components/ui/AppBar.types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export interface AppBarProps {
6868
readonly onPress?: () => void;
6969
};
7070
readonly hideBottomBorder?: boolean;
71+
/** Android: one title row with the subtitle inline. iOS ignores it. */
72+
readonly compact?: boolean;
7173
readonly trailing?: ReactNode;
7274
readonly matchSearchSurface?: boolean;
7375
readonly options?: AppNativeStackNavigationOptions;

‎apps/mobile/src/components/ui/NativeAppBar.android.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ export function NativeAppBar(props: {
1010
readonly title: ReactElement;
1111
readonly navigationIcon?: ReactElement;
1212
readonly actions?: ReactElement;
13+
/** Shorter bar for a one-row title. */
14+
readonly singleLine?: boolean;
1315
}) {
1416
const { colors } = useControlTheme();
15-
const layout = useToolbarLayout();
17+
const layout = useToolbarLayout(false, props.singleLine);
1618
return (
1719
// The bar's height is fixed, so React Native lays out the screen below it from the first frame
1820
// instead of at zero height until Compose has measured and reported the bar.

0 commit comments

Comments
 (0)