From f075187e57a0c1a267efc690f105452209b6ce40 Mon Sep 17 00:00:00 2001 From: DS Boyce <260543580+ds-boyce@users.noreply.github.com> Date: Tue, 16 Jun 2026 09:25:34 -0700 Subject: [PATCH] Reset textarea height after clear (#10911) --- src/components/Composer/index.tsx | 10 ++++++++++ src/components/forms/AutosizedTextarea.tsx | 23 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/components/Composer/index.tsx b/src/components/Composer/index.tsx index b7a67f3033..b587d19eae 100644 --- a/src/components/Composer/index.tsx +++ b/src/components/Composer/index.tsx @@ -34,6 +34,7 @@ import { } from '#/components/Autocomplete' import { AutosizedTextarea, + type AutosizedTextareaHeightApi, type AutosizedTextareaProps, } from '#/components/forms/AutosizedTextarea' import {Span, Text} from '#/components/Typography' @@ -150,6 +151,13 @@ export function Composer({ */ const inputScrollSharedValue = useSharedValue(0) + /* + * Imperative handle on the underlying textarea, used to reset its height when + * the input is cleared programmatically (Android doesn't fire + * `onContentSizeChange` in that case). + */ + const heightApiRef = useRef(null) + /* * Expose imperative internal API */ @@ -160,6 +168,7 @@ export function Composer({ clear: () => { tapper.inputProps.onChangeText('') inputScrollSharedValue.value = 0 + heightApiRef.current?.resetHeight() }, insert: tapper.insert, setAutocompleteAnchor: sift.refs.setAnchor, @@ -321,6 +330,7 @@ export function Composer({ )} void +} + export type AutosizedTextareaProps = Omit & { ref?: React.Ref + heightApiRef?: React.Ref label: string minRows?: number maxRows?: number @@ -20,6 +30,7 @@ export type AutosizedTextareaProps = Omit & { export function AutosizedTextarea({ ref, + heightApiRef, label, minRows = 1, maxRows, @@ -107,6 +118,16 @@ export function AutosizedTextarea({ * directly drive the `height`. */ const [nativeHeight, setNativeHeight] = useState(minInputHeight) + useImperativeHandle( + heightApiRef, + () => ({ + resetHeight: () => { + setNativeHeight(minInputHeight) + onUpdateHeight?.(minInputHeight) + }, + }), + [minInputHeight, onUpdateHeight], + ) const onContentSizeChange = (e: TextInputContentSizeChangeEvent) => { const contentSize = Math.ceil(e.nativeEvent.contentSize.height) // ios reports the content size without padding