Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
019954b
fix: enforce composer layout reset upon sending a message
Kureev Nov 11, 2025
9f17e7e
Merge branch 'main' into kureev/64302
Kureev Dec 9, 2025
b24156c
fix: remove magic constant
Kureev Dec 9, 2025
4c63d3b
Merge branch 'main' into kureev/64302
Kureev Jan 14, 2026
7c04bf2
Merge branch 'main' into kureev/64302
chrispader Feb 2, 2026
55f072e
Merge branch 'main' into kureev/64302
chrispader Feb 3, 2026
b8bccac
refactor: rename `reset` callback
chrispader Feb 3, 2026
b1383fc
fix: unnecessary array wrapped style
chrispader Feb 3, 2026
6f34303
refactor: rename event property
chrispader Feb 4, 2026
ed3c905
fix: rename props
chrispader Feb 4, 2026
8ee1d07
Merge branch 'main' into kureev/64302
chrispader Feb 4, 2026
f1a8be7
fix: missing props
chrispader Feb 4, 2026
9643987
fix: send message in new macrotask
chrispader Feb 4, 2026
02832f3
fix: remove unnecessary "worklet" directive
chrispader Feb 4, 2026
c9fe00b
refactor: update onLayout prop
chrispader Feb 4, 2026
e8ef799
rename props
chrispader Feb 4, 2026
d184a52
chore: add comments
chrispader Feb 4, 2026
fe716f5
refactor: rename clear worklet prop
chrispader Feb 4, 2026
6462fea
fix: height reset on send
chrispader Feb 4, 2026
6734dcb
fix: spell check
chrispader Feb 4, 2026
cab19fa
refactor: remove property alias
chrispader Feb 4, 2026
38d7731
fix: failing test
chrispader Feb 4, 2026
6369b4a
revert: Mobile-Expensify change
chrispader Feb 4, 2026
55027e2
fix: failing tests
chrispader Feb 4, 2026
4855c2c
fix: vertical/horizontal alignment of composer
chrispader Feb 5, 2026
c4abcda
fix: clear composer when text is inputted
chrispader Feb 5, 2026
cb7f151
fix: failing test due to added `setTimeout`
chrispader Feb 5, 2026
827ddc5
fix: tests
chrispader Feb 6, 2026
f45283f
Merge branch 'main' into kureev/64302
chrispader Feb 6, 2026
4e3daec
chroe: add comments
chrispader Feb 6, 2026
ae9b154
fix: alignment on all platforms
chrispader Feb 6, 2026
fb2ac0e
fix: remove manual `setTimeout`
chrispader Feb 6, 2026
3fc77cc
revert: unrelated change
chrispader Feb 6, 2026
f15fdff
revert test changes
chrispader Feb 6, 2026
d2c83db
docs: add missing JSDoc
chrispader Feb 6, 2026
cd032b2
refactor: variables and callbacks in `ComposerWithSuggestions`
chrispader Feb 6, 2026
be44f89
refactor: simplify (shared) ref to composer
chrispader Feb 6, 2026
b69fc29
test: add act to wait for `setTimeout`
chrispader Feb 6, 2026
0faa700
Merge branch 'main' into kureev/64302
chrispader Feb 6, 2026
07cc25d
fix: tests
chrispader Feb 6, 2026
4608dde
Merge branch 'main' into kureev/64302
chrispader Feb 10, 2026
6085a1d
fix: failing tests
chrispader Feb 10, 2026
de6c791
Merge branch 'main' into kureev/64302
chrispader Feb 10, 2026
5a9e88e
refactor: move back shared ref usage
chrispader Feb 10, 2026
71d1a02
revert: test changes
chrispader Feb 10, 2026
92c335d
refactor: update ref type
chrispader Feb 10, 2026
f82db7a
refactor: rename state
chrispader Feb 10, 2026
331c0d5
refactor: `addAttachment` callback
chrispader Feb 10, 2026
9ffcb74
refactor: improve ref type
chrispader Feb 10, 2026
589d991
fix: ref type
chrispader Feb 10, 2026
c6c0e61
refactor: order of functions
chrispader Feb 10, 2026
9d91f16
refactor: hook deps
chrispader Feb 10, 2026
df874bb
refactor: worklets
chrispader Feb 10, 2026
60ce20d
fix: failing test
chrispader Feb 10, 2026
1c37b54
fix: remove unused style
chrispader Feb 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useIsFocused, useNavigation, useRoute} from '@react-navigation/native';
import lodashDebounce from 'lodash/debounce';
import type {ForwardedRef, RefObject} from 'react';
import type {Ref, RefObject} from 'react';
import React, {memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import type {BlurEvent, LayoutChangeEvent, MeasureInWindowOnSuccessCallback, TextInput, TextInputContentSizeChangeEvent, TextInputKeyPressEvent, TextInputScrollEvent} from 'react-native';
import {DeviceEventEmitter, InteractionManager, NativeModules, StyleSheet, View} from 'react-native';
Expand Down Expand Up @@ -82,7 +82,7 @@ type ComposerWithSuggestionsProps = Partial<ChildrenProps> &
onValueChange: (value: string) => void;

/** Callback when the composer got cleared on the UI thread */
onCleared?: (text: string) => void;
onClear?: (text: string) => void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename property to match event/callback best practices


/** Whether the composer is full size */
isComposerFullSize: boolean;
Expand All @@ -106,7 +106,7 @@ type ComposerWithSuggestionsProps = Partial<ChildrenProps> &
setIsCommentEmpty: (isCommentEmpty: boolean) => void;

/** Function to handle sending a message */
handleSendMessage: () => void;
onEnterKeyPress: () => void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename property to make component more "dumb" and make clearer for what this event is actually triggered.


/** Whether the compose input should show */
shouldShowComposeInput: OnyxEntry<boolean>;
Expand Down Expand Up @@ -142,7 +142,7 @@ type ComposerWithSuggestionsProps = Partial<ChildrenProps> &
didHideComposerInput?: boolean;

/** Reference to the outer element */
ref?: ForwardedRef<ComposerRef>;
ref?: Ref<ComposerRef | null>;
};

type SwitchToCurrentReportProps = {
Expand All @@ -157,11 +157,17 @@ type ComposerRef = {
replaceSelectionWithText: OnEmojiSelected;
getCurrentText: () => string;
isFocused: () => boolean;

/**
* Calling clear will immediately clear the input on the UI thread (its a worklet).
* Once the composer ahs cleared onCleared will be called with the value that was cleared.
*/
clear: () => void;
clearWorklet: () => void;

/**
* Reset the height of the composer.
*/
resetHeight: () => void;
};

const {RNTextInputReset} = NativeModules;
Expand Down Expand Up @@ -215,13 +221,13 @@ function ComposerWithSuggestions({
onPasteFile,
disabled,
setIsCommentEmpty,
handleSendMessage,
onEnterKeyPress,
shouldShowComposeInput,
measureParentContainer = () => {},
isScrollLikelyLayoutTriggered,
raiseIsScrollLikelyLayoutTriggered,
onCleared = () => {},
onLayout: onLayoutProps,
onClear: onClearProp = () => {},
onLayout,

// Refs
suggestionsRef,
Expand Down Expand Up @@ -282,7 +288,8 @@ function ComposerWithSuggestions({

const [selection, setSelection] = useState<TextSelection>(() => ({start: value.length, end: value.length, positionX: 0, positionY: 0}));

const [composerHeight, setComposerHeight] = useState(0);
const [composerHeightAfterClear, setDefaultComposerHeight] = useState<number | null>(null);
const emptyComposerHeightRef = useRef<number | null>(null);

const textInputRef = useRef<TextInput | null>(null);

Expand Down Expand Up @@ -511,7 +518,7 @@ function ComposerWithSuggestions({
// Submit the form when Enter is pressed
if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey && !webEvent.shiftKey) {
webEvent.preventDefault();
handleSendMessage();
onEnterKeyPress();
}

// Trigger the edit box for last sent message if ArrowUp is pressed and the comment is empty and Chronos is not in the participants
Expand Down Expand Up @@ -554,11 +561,26 @@ function ComposerWithSuggestions({
}
}
},
[shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, selection.start, includeChronos, handleSendMessage, lastReportAction, reportID, updateComment, selection.end],
[shouldUseNarrowLayout, isKeyboardShown, suggestionsRef, selection.start, includeChronos, onEnterKeyPress, lastReportAction, reportID, updateComment, selection.end],
);

/**
* Once we cleared the input and the composer finished rendering, we need to reset the manual height value.
* After that, the composer will adjust it's height based on it's parent flex layout.
*/
const clearComposerHeight = useCallback(() => {
if (composerHeightAfterClear == null) {
return;
}
setDefaultComposerHeight(null);
}, [composerHeightAfterClear]);

const onChangeText = useCallback(
(commentValue: string) => {
// When we clear the input, we set the composer height to a specific value.
// Upon text change, we can reset the height to allow flex layout to adjust the height.
clearComposerHeight();

updateComment(commentValue, true);

if (isIOSNative && syncSelectionWithOnChangeTextRef.current) {
Expand All @@ -574,7 +596,7 @@ function ComposerWithSuggestions({
});
}
},
[updateComment],
[clearComposerHeight, updateComment],
);

const onSelectionChange = useCallback(
Expand Down Expand Up @@ -676,12 +698,19 @@ function ComposerWithSuggestions({
textInputRef.current.blur();
}, []);

const clear = useCallback(() => {
const clearWorklet = useCallback(() => {
'worklet';

forceClearInput(animatedRef);
}, [animatedRef]);

const resetHeight = useCallback(() => {
if (!emptyComposerHeightRef.current) {
return;
}
setDefaultComposerHeight(emptyComposerHeightRef.current);
}, []);

const getCurrentText = useCallback(() => {
return commentRef.current;
}, []);
Expand Down Expand Up @@ -755,36 +784,25 @@ function ComposerWithSuggestions({
focus,
replaceSelectionWithText,
isFocused: () => !!textInputRef.current?.isFocused(),
clear,
getCurrentText,
clearWorklet,
resetHeight,
}),
[blur, clear, focus, replaceSelectionWithText, getCurrentText],
[blur, focus, replaceSelectionWithText, clearWorklet, resetHeight, getCurrentText],
);

useEffect(() => {
onValueChange(value);
}, [onValueChange, value]);

const onLayout = useCallback(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore.

(e: LayoutChangeEvent) => {
onLayoutProps?.(e);
const composerLayoutHeight = e.nativeEvent.layout.height;
if (composerHeight === composerLayoutHeight) {
return;
}
setComposerHeight(composerLayoutHeight);
},
[composerHeight, onLayoutProps],
);

const onClear = useCallback(
(text: string) => {
mobileInputScrollPosition.current = 0;
// Note: use the value when the clear happened, not the current value which might have changed already
onCleared(text);
onClearProp(text);
updateComment('', true);
},
[onCleared, updateComment],
[onClearProp, updateComment],
);

useEffect(() => {
Expand Down Expand Up @@ -828,15 +846,25 @@ function ComposerWithSuggestions({
const isTouchEndedRef = useRef(false);
const containerComposeStyles = StyleSheet.flatten(StyleUtils.getContainerComposeStyles());

const updateIsFullComposerAvailable = useCallback(
const handleContentSizeChange = useCallback(
(e: TextInputContentSizeChangeEvent) => {
const paddingTopAndBottom = (containerComposeStyles.paddingVertical as number) * 2;
const inputHeight = e.nativeEvent.contentSize.height;
const totalHeight = inputHeight + paddingTopAndBottom;

// When we clear the input, we set the composer height to a specific value.
// Upon any content size change, we can reset the height to allow flex layout to adjust the height.
clearComposerHeight();

// Store the default collapsed composer height, so we can later reset the height when we clear the input.
if (emptyComposerHeightRef.current === null && inputHeight > 0 && !valueRef.current.includes('\n')) {
emptyComposerHeightRef.current = inputHeight;
}

const isFullComposerAvailable = totalHeight >= CONST.COMPOSER.FULL_COMPOSER_MIN_HEIGHT;
setIsFullComposerAvailable?.(isFullComposerAvailable);
},
[setIsFullComposerAvailable, containerComposeStyles],
[containerComposeStyles.paddingVertical, clearComposerHeight, setIsFullComposerAvailable],
);

const handleFocus = useCallback(() => {
Expand Down Expand Up @@ -878,7 +906,11 @@ function ComposerWithSuggestions({
onChangeText={onChangeText}
onKeyPress={handleKeyPress}
textAlignVertical="top"
style={[styles.textInputCompose, isComposerFullSize ? styles.textInputFullCompose : styles.textInputCollapseCompose]}
style={[
styles.textInputCompose,
isComposerFullSize ? styles.textInputFullCompose : styles.textInputCollapseCompose,
composerHeightAfterClear != null && {height: composerHeightAfterClear},
]}
maxLines={maxComposerLines}
onFocus={handleFocus}
onBlur={onBlur}
Expand All @@ -892,7 +924,7 @@ function ComposerWithSuggestions({
selection={selection}
onSelectionChange={onSelectionChange}
isComposerFullSize={isComposerFullSize}
onContentSizeChange={updateIsFullComposerAvailable}
onContentSizeChange={handleContentSizeChange}
value={value}
testID="composer"
shouldCalculateCaretPosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function ReportActionCompose({
const icons = useMemoizedLazyExpensifyIcons(['MessageInABottle']);

const suggestionsRef = useRef<SuggestionsRef>(null);
const composerRef = useRef<ComposerRef | undefined>(undefined);
const composerRef = useRef<ComposerRef | null>(null);
const reportParticipantIDs = useMemo(
() =>
Object.keys(report?.participants ?? {})
Expand Down Expand Up @@ -310,12 +310,14 @@ function ReportActionCompose({

const addAttachment = useCallback((file: FileObject | FileObject[]) => {
attachmentFileRef.current = file;
const clear = composerRef.current?.clear;
if (!clear) {
throw new Error('The composerRef.clear function is not set yet. This should never happen, and indicates a developer error.');

const clearWorklet = composerRef.current?.clearWorklet;

if (!clearWorklet) {
throw new Error('The composerRef.clearWorklet function is not set yet. This should never happen, and indicates a developer error.');
}

scheduleOnUI(clear);
scheduleOnUI(clearWorklet);
}, []);

/**
Expand Down Expand Up @@ -365,7 +367,18 @@ function ReportActionCompose({
onSubmit(newCommentTrimmed);
}
},
[isConciergeChat, kickoffWaitingIndicator, transactionThreadReport, report, reportID, ancestors, personalDetail.timezone, onSubmit, isInSidePanel],
[
isConciergeChat,
kickoffWaitingIndicator,
transactionThreadReport,
report,
reportID,
ancestors,
currentUserPersonalDetails.accountID,
personalDetail.timezone,
isInSidePanel,
onSubmit,
],
);

const onTriggerAttachmentPicker = useCallback(() => {
Expand Down Expand Up @@ -443,28 +456,28 @@ function ReportActionCompose({

// Note: using JS refs is not well supported in reanimated, thus we need to store the function in a shared value
// useSharedValue on web doesn't support functions, so we need to wrap it in an object.
const composerRefShared = useSharedValue<{
clear: (() => void) | undefined;
}>({clear: undefined});
const composerRefShared = useSharedValue<Partial<ComposerRef>>({});

const handleSendMessage = useCallback(() => {
if (isSendDisabled || !debouncedValidate.flush()) {
return;
}

scheduleOnUI(() => {
'worklet';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be this...

composerRef.current?.resetHeight();
if (isComposerFullSize) {
setIsComposerFullSize(reportID, false);
}

const {clear: clearComposer} = composerRefShared.get();
scheduleOnUI(() => {
const {clearWorklet} = composerRefShared.get();

if (!clearComposer) {
throw new Error('The composerRefShared.clear function is not set yet. This should never happen, and indicates a developer error.');
if (!clearWorklet) {
throw new Error('The composerRef.clearWorklet function is not set yet. This should never happen, and indicates a developer error.');
}

// This will cause onCleared to be triggered where we actually send the message
clearComposer?.();
clearWorklet?.();
});
}, [isSendDisabled, debouncedValidate, composerRefShared]);
}, [isSendDisabled, debouncedValidate, isComposerFullSize, reportID, composerRefShared]);

onSubmitAction = handleSendMessage;

Expand Down Expand Up @@ -575,9 +588,9 @@ function ReportActionCompose({
/>
<ComposerWithSuggestions
ref={(ref) => {
composerRef.current = ref ?? undefined;
composerRef.current = ref;
composerRefShared.set({
clear: ref?.clear,
clearWorklet: ref?.clearWorklet,
});
}}
suggestionsRef={suggestionsRef}
Expand All @@ -594,10 +607,10 @@ function ReportActionCompose({
isComposerFullSize={isComposerFullSize}
setIsFullComposerAvailable={setIsFullComposerAvailable}
onPasteFile={(files) => validateAttachments({files})}
onCleared={submitForm}
onClear={submitForm}
disabled={isBlockedFromConcierge || isEmojiPickerVisible()}
setIsCommentEmpty={setIsCommentEmpty}
handleSendMessage={handleSendMessage}
onEnterKeyPress={handleSendMessage}
shouldShowComposeInput={shouldShowComposeInput}
onFocus={onFocus}
onBlur={onBlur}
Expand Down
1 change: 0 additions & 1 deletion src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,6 @@ const staticStyles = (theme: ThemeColors) =>
...(Platform.OS === 'android' && {
height: undefined,
lineHeight: undefined,
alignSelf: 'stretch',
flexGrow: 1,
flexShrink: 1,
}),
Expand Down
Loading