@@ -13,6 +13,8 @@ import {
1313 type ViewStyle ,
1414} from "react-native" ;
1515
16+ import Animated , { FadeIn , LinearTransition } from "react-native-reanimated" ;
17+
1618import { cn } from "../lib/cn" ;
1719import { AppText as Text } from "./ui/AppText" ;
1820import { SymbolView } from "./ui/AppSymbol" ;
@@ -21,6 +23,10 @@ import { useAndroidControlSizing } from "./ui/useAndroidControlSizing";
2123const COMPOSER_TOOLBAR_GAP = 8 ;
2224const COMPOSER_TOOLBAR_FADE_WIDTH = 18 ;
2325const 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
2531export 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
0 commit comments