Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 17 additions & 5 deletions apps/mobile/src/features/threads/ThreadComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const COMPOSER_COLLAPSED_CHROME = 60;
* Used by the parent to compute the larger feed bottom inset when the composer is focused.
*/
export const COMPOSER_EXPANDED_CHROME = 156;
export const COMPOSER_DICTATION_REVIEW_CHROME = COMPOSER_EXPANDED_CHROME + 160 - 72;

export interface ThreadComposerProps {
readonly draftMessage: string;
Expand All @@ -140,6 +141,8 @@ export interface ThreadComposerProps {
readonly sendBlockedReason?: string | null;
readonly editorRef?: RefObject<ComposerEditorHandle | null>;
readonly onChangeDraftMessage: (value: string) => void;
readonly isReviewingDictation: boolean;
readonly onDictationComplete: () => void;
readonly onPickDraftMedia: () => Promise<void>;
readonly onPickDraftFiles: () => Promise<void>;
readonly onNativePasteImages: (uris: ReadonlyArray<string>) => Promise<void>;
Expand Down Expand Up @@ -394,7 +397,10 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
ownerKey: composerOwnerKey,
draftMessage: props.draftMessage,
selection: composerMenu.selection,
onChangeDraftMessage: props.onChangeDraftMessage,
onChangeDraftMessage: (message) => {
props.onChangeDraftMessage(message);
props.onDictationComplete();
},
onChangeSelection: composerMenu.onSelectionChange,
});
const voicePresentation = resolveVoiceComposerPresentation(
Expand All @@ -403,7 +409,8 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
);
const isVoiceInputPresented = voicePresentation.statusLabel !== null;
// An open draft stays visible; only a collapsed composer becomes a voice strip.
const isExpanded = isFocused || settingsSheetPresentation.keepsComposerExpanded;
const isExpanded =
isFocused || props.isReviewingDictation || settingsSheetPresentation.keepsComposerExpanded;
const showsCompactDictation = isVoiceInputPresented && !isExpanded;
const isToolbarVisible = isExpanded || isVoiceInputPresented;
const attachmentBlockReason = composerAttachmentUploadBlockReason({
Expand Down Expand Up @@ -467,11 +474,16 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer

const handleBlur = useCallback(() => {
setIsFocused(false);
if (!settingsSheetPresentation.keepsComposerExpanded) {
if (!props.isReviewingDictation && !settingsSheetPresentation.keepsComposerExpanded) {
onExpandedChange?.(false);
}
onEditorFocusChange?.(false);
}, [onEditorFocusChange, onExpandedChange, settingsSheetPresentation.keepsComposerExpanded]);
}, [
onEditorFocusChange,
onExpandedChange,
props.isReviewingDictation,
settingsSheetPresentation.keepsComposerExpanded,
]);
const handleSend = useCallback(async () => {
if (voiceInput.blocksSubmission || pendingPastedTextAttachmentCountRef.current > 0) return;
// Typed out in full rather than picked from the menu. Attachments mean the
Expand Down Expand Up @@ -827,7 +839,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
style={
isExpanded
? {
minHeight: 72,
minHeight: props.isReviewingDictation ? 160 : 72,
maxHeight: 160,
paddingVertical: 4,
}
Expand Down
25 changes: 20 additions & 5 deletions apps/mobile/src/features/threads/ThreadDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import {
import {
COMPOSER_COLLAPSED_CHROME,
COMPOSER_EXPANDED_CHROME,
COMPOSER_DICTATION_REVIEW_CHROME,
COMPOSER_LAYOUT_TRANSITION,
COMPOSER_TRANSITION_DURATION_MS,
ThreadComposer,
Expand Down Expand Up @@ -326,8 +327,17 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
const lastScrolledSubmittedMessageIdRef = useRef<MessageId | null>(null);
const [composerExpanded, setComposerExpanded] = useState(false);
const [composerFocused, setComposerFocused] = useState(false);
const [dictationReviewThreadKey, setDictationReviewThreadKey] = useState<string | null>(null);
const isReviewingDictation =
dictationReviewThreadKey === selectedThreadKey &&
props.draftMessage.trim().length > 0 &&
!composerFocused;
const handleDictationComplete = useCallback(() => {
setDictationReviewThreadKey(selectedThreadKey);
}, [selectedThreadKey]);
const handleComposerFocusChange = useCallback(
(focused: boolean) => {
if (focused) setDictationReviewThreadKey(null);
setComposerFocused(focused);
handleOwnedInputFocusChange(focused);
},
Expand All @@ -343,10 +353,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
// animation, so the composer would ride down flush to the screen edge and
// then snap up into the inset. On iOS blur precedes the hide, so the
// focus-keyed inset is already in place while the composer rides down.
// Dictation keeps that focus while the composer switches to its compact pill.
const composerBottomInset = (
Platform.OS === "android" ? isKeyboardVisible : composerExpanded || composerFocused
)
const composerBottomInset = (Platform.OS === "android" ? isKeyboardVisible : composerFocused)
? 0
: Math.max(insets.bottom, 12);
const contentPresentationKind = props.contentPresentation.kind;
Expand Down Expand Up @@ -425,7 +432,11 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
entry.message.text.trim().toLowerCase() !== "/compact"),
) ||
(Boolean(props.loadEarlier) && props.selectedThread.latestUserMessageAt !== null);
const composerChrome = composerExpanded ? COMPOSER_EXPANDED_CHROME : COMPOSER_COLLAPSED_CHROME;
const composerChrome = isReviewingDictation
? COMPOSER_DICTATION_REVIEW_CHROME
: composerExpanded
? COMPOSER_EXPANDED_CHROME
: COMPOSER_COLLAPSED_CHROME;
const composerOverlapHeight = composerChrome + composerBottomInset;
// While a user-input request is pending, the questionnaire owns the
// composer slot outright: expanded it is the full card, collapsed it is a
Expand Down Expand Up @@ -774,6 +785,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread

// A sent message makes the snapshot stale; a refused send leaves it in place.
clearUsageLimitsFor(targetThreadKey);
setDictationReviewThreadKey(null);

setSubmittedMessageId(messageId);
setAnchorMessageId(
Expand Down Expand Up @@ -814,6 +826,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
}, []);

const collapseComposer = useCallback(() => {
setDictationReviewThreadKey(null);
composerEditorRef.current?.blur();
}, []);

Expand Down Expand Up @@ -1074,6 +1087,8 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
}
bottomInset={composerBottomInset}
onChangeDraftMessage={props.onChangeDraftMessage}
isReviewingDictation={isReviewingDictation}
onDictationComplete={handleDictationComplete}
onPickDraftMedia={props.onPickDraftMedia}
onPickDraftFiles={props.onPickDraftFiles}
onNativePasteImages={props.onNativePasteImages}
Expand Down
Loading