-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ReportActionCompose.tsx
596 lines (535 loc) · 29.1 KB
/
ReportActionCompose.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
import {useNavigation} from '@react-navigation/native';
import lodashDebounce from 'lodash/debounce';
import noop from 'lodash/noop';
import React, {memo, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {MeasureInWindowOnSuccessCallback, NativeSyntheticEvent, TextInputFocusEventData, TextInputSelectionChangeEventData} from 'react-native';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import {runOnUI, useSharedValue} from 'react-native-reanimated';
import type {Emoji} from '@assets/emojis/types';
import type {FileObject} from '@components/AttachmentModal';
import AttachmentModal from '@components/AttachmentModal';
import EmojiPickerButton from '@components/EmojiPicker/EmojiPickerButton';
import ExceededCommentLength from '@components/ExceededCommentLength';
import ImportedStateIndicator from '@components/ImportedStateIndicator';
import type {Mention} from '@components/MentionSuggestions';
import OfflineIndicator from '@components/OfflineIndicator';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {usePersonalDetails} from '@components/OnyxProvider';
import {useProductTrainingContext} from '@components/ProductTrainingContext';
import EducationalTooltip from '@components/Tooltip/EducationalTooltip';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDebounce from '@hooks/useDebounce';
import useHandleExceedMaxCommentLength from '@hooks/useHandleExceedMaxCommentLength';
import useHandleExceedMaxTaskTitleLength from '@hooks/useHandleExceedMaxTaskTitleLength';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useViewportOffsetTop from '@hooks/useViewportOffsetTop';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import DomUtils from '@libs/DomUtils';
import {getDraftComment} from '@libs/DraftCommentUtils';
import getModalState from '@libs/getModalState';
import Performance from '@libs/Performance';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import willBlurTextInputOnTapOutsideFunc from '@libs/willBlurTextInputOnTapOutside';
import ParticipantLocalTime from '@pages/home/report/ParticipantLocalTime';
import ReportDropUI from '@pages/home/report/ReportDropUI';
import ReportTypingIndicator from '@pages/home/report/ReportTypingIndicator';
import variables from '@styles/variables';
import * as EmojiPickerActions from '@userActions/EmojiPickerAction';
import * as Report from '@userActions/Report';
import Timing from '@userActions/Timing';
import * as User from '@userActions/User';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import AttachmentPickerWithMenuItems from './AttachmentPickerWithMenuItems';
import ComposerWithSuggestions from './ComposerWithSuggestions';
import type {ComposerRef, ComposerWithSuggestionsProps} from './ComposerWithSuggestions/ComposerWithSuggestions';
import SendButton from './SendButton';
type SuggestionsRef = {
resetSuggestions: () => void;
onSelectionChange?: (event: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => void;
triggerHotkeyActions: (event: KeyboardEvent) => boolean | undefined;
updateShouldShowSuggestionMenuToFalse: (shouldShowSuggestionMenu?: boolean) => void;
setShouldBlockSuggestionCalc: (shouldBlock: boolean) => void;
getSuggestions: () => Mention[] | Emoji[];
getIsSuggestionsMenuVisible: () => boolean;
};
type ReportActionComposeProps = Pick<ComposerWithSuggestionsProps, 'reportID' | 'isComposerFullSize' | 'lastReportAction'> & {
/** A method to call when the form is submitted */
onSubmit: (newComment: string) => void;
/** The report currently being looked at */
report: OnyxEntry<OnyxTypes.Report>;
/** The type of action that's pending */
pendingAction?: OnyxCommon.PendingAction;
/** Whether the report is ready for display */
isReportReadyForDisplay?: boolean;
/** A method to call when the input is focus */
onComposerFocus?: () => void;
/** A method to call when the input is blur */
onComposerBlur?: () => void;
/** Should the input be disabled */
disabled?: boolean;
/** Should show educational tooltip */
shouldShowEducationalTooltip?: boolean;
/** Whether to show the keyboard on focus */
showSoftInputOnFocus: boolean;
/** A method to update showSoftInputOnFocus */
setShowSoftInputOnFocus: (value: boolean) => void;
/** Whether the main composer was hidden */
didHideComposerInput?: boolean;
};
// We want consistent auto focus behavior on input between native and mWeb so we have some auto focus management code that will
// prevent auto focus on existing chat for mobile device
const shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus();
const willBlurTextInputOnTapOutside = willBlurTextInputOnTapOutsideFunc();
// eslint-disable-next-line import/no-mutable-exports
let onSubmitAction = noop;
function ReportActionCompose({
disabled = false,
isComposerFullSize = false,
onSubmit,
pendingAction,
report,
reportID,
isReportReadyForDisplay = true,
lastReportAction,
shouldShowEducationalTooltip,
showSoftInputOnFocus,
onComposerFocus,
onComposerBlur,
setShowSoftInputOnFocus,
didHideComposerInput,
}: ReportActionComposeProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth, isMediumScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const offsetTop = useViewportOffsetTop();
const {isOffline} = useNetwork();
const actionButtonRef = useRef<View | HTMLDivElement | null>(null);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const personalDetails = usePersonalDetails();
const navigation = useNavigation();
const [blockedFromConcierge] = useOnyx(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE);
const [shouldShowComposeInput = true] = useOnyx(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT);
const {renderProductTrainingTooltip, hideProductTrainingTooltip, shouldShowProductTrainingTooltip} = useProductTrainingContext(
CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.WORKSAPCE_CHAT_CREATE,
shouldShowEducationalTooltip,
);
/**
* Updates the Highlight state of the composer
*/
const [isFocused, setIsFocused] = useState(() => {
const initialModalState = getModalState();
return shouldFocusInputOnScreenFocus && shouldShowComposeInput && !initialModalState?.isVisible && !initialModalState?.willAlertModalBecomeVisible;
});
const [shouldHideEducationalTooltip, setShouldHideEducationalTooltip] = useState(false);
// A flag to indicate whether the onScroll callback is likely triggered by a layout change (caused by text change) or not
const isScrollLikelyLayoutTriggered = useRef(false);
/**
* Reset isScrollLikelyLayoutTriggered to false.
*
* The function is debounced with a handpicked wait time to address 2 issues:
* 1. There is a slight delay between onChangeText and onScroll
* 2. Layout change will trigger onScroll multiple times
*/
const debouncedLowerIsScrollLikelyLayoutTriggered = useDebounce(
useCallback(() => (isScrollLikelyLayoutTriggered.current = false), []),
500,
);
const raiseIsScrollLikelyLayoutTriggered = useCallback(() => {
isScrollLikelyLayoutTriggered.current = true;
debouncedLowerIsScrollLikelyLayoutTriggered();
}, [debouncedLowerIsScrollLikelyLayoutTriggered]);
const [isCommentEmpty, setIsCommentEmpty] = useState(() => {
const draftComment = getDraftComment(reportID);
return !draftComment || !!draftComment.match(CONST.REGEX.EMPTY_COMMENT);
});
/**
* Updates the visibility state of the menu
*/
const [isMenuVisible, setMenuVisibility] = useState(false);
const [isAttachmentPreviewActive, setIsAttachmentPreviewActive] = useState(false);
/**
* Updates the composer when the comment length is exceeded
* Shows red borders and prevents the comment from being sent
*/
const {hasExceededMaxCommentLength, validateCommentMaxLength, setHasExceededMaxCommentLength} = useHandleExceedMaxCommentLength();
const {hasExceededMaxTaskTitleLength, validateTaskTitleMaxLength, setHasExceededMaxTitleLength} = useHandleExceedMaxTaskTitleLength();
const [exceededMaxLength, setExceededMaxLength] = useState<number | null>(null);
const suggestionsRef = useRef<SuggestionsRef>(null);
const composerRef = useRef<ComposerRef>();
const reportParticipantIDs = useMemo(
() =>
Object.keys(report?.participants ?? {})
.map(Number)
.filter((accountID) => accountID !== currentUserPersonalDetails.accountID),
[currentUserPersonalDetails.accountID, report?.participants],
);
const shouldShowReportRecipientLocalTime = useMemo(
() => ReportUtils.canShowReportRecipientLocalTime(personalDetails, report, currentUserPersonalDetails.accountID) && !isComposerFullSize,
[personalDetails, report, currentUserPersonalDetails.accountID, isComposerFullSize],
);
const includesConcierge = useMemo(() => ReportUtils.chatIncludesConcierge({participants: report?.participants}), [report?.participants]);
const userBlockedFromConcierge = useMemo(() => User.isBlockedFromConcierge(blockedFromConcierge), [blockedFromConcierge]);
const isBlockedFromConcierge = useMemo(() => includesConcierge && userBlockedFromConcierge, [includesConcierge, userBlockedFromConcierge]);
// Placeholder to display in the chat input.
const inputPlaceholder = useMemo(() => {
if (includesConcierge && userBlockedFromConcierge) {
return translate('reportActionCompose.blockedFromConcierge');
}
return translate('reportActionCompose.writeSomething');
}, [includesConcierge, translate, userBlockedFromConcierge]);
const focus = () => {
if (composerRef.current === null) {
return;
}
composerRef.current?.focus(true);
};
const isKeyboardVisibleWhenShowingModalRef = useRef(false);
const isNextModalWillOpenRef = useRef(false);
const containerRef = useRef<View>(null);
const measureContainer = useCallback(
(callback: MeasureInWindowOnSuccessCallback) => {
if (!containerRef.current) {
return;
}
containerRef.current.measureInWindow(callback);
},
// We added isComposerFullSize in dependencies so that when this value changes, we recalculate the position of the popup
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[isComposerFullSize],
);
const onAddActionPressed = useCallback(() => {
if (!willBlurTextInputOnTapOutside) {
isKeyboardVisibleWhenShowingModalRef.current = !!composerRef.current?.isFocused();
}
composerRef.current?.blur();
}, []);
const onItemSelected = useCallback(() => {
isKeyboardVisibleWhenShowingModalRef.current = false;
}, []);
const updateShouldShowSuggestionMenuToFalse = useCallback(() => {
if (!suggestionsRef.current) {
return;
}
suggestionsRef.current.updateShouldShowSuggestionMenuToFalse(false);
}, []);
const attachmentFileRef = useRef<FileObject | null>(null);
const addAttachment = useCallback((file: 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.');
}
runOnUI(clear)();
}, []);
/**
* Event handler to update the state after the attachment preview is closed.
*/
const onAttachmentPreviewClose = useCallback(() => {
updateShouldShowSuggestionMenuToFalse();
setIsAttachmentPreviewActive(false);
}, [updateShouldShowSuggestionMenuToFalse]);
/**
* Add a new comment to this chat
*/
const submitForm = useCallback(
(newComment: string) => {
playSound(SOUNDS.DONE);
const newCommentTrimmed = newComment.trim();
if (attachmentFileRef.current) {
Report.addAttachment(reportID, attachmentFileRef.current, newCommentTrimmed);
attachmentFileRef.current = null;
} else {
Performance.markStart(CONST.TIMING.SEND_MESSAGE, {message: newCommentTrimmed});
Timing.start(CONST.TIMING.SEND_MESSAGE);
onSubmit(newCommentTrimmed);
}
},
[onSubmit, reportID],
);
const onTriggerAttachmentPicker = useCallback(() => {
isNextModalWillOpenRef.current = true;
isKeyboardVisibleWhenShowingModalRef.current = true;
}, []);
const onBlur = useCallback(
(event: NativeSyntheticEvent<TextInputFocusEventData>) => {
const webEvent = event as unknown as FocusEvent;
setIsFocused(false);
onComposerBlur?.();
if (suggestionsRef.current) {
suggestionsRef.current.resetSuggestions();
}
if (webEvent.relatedTarget && webEvent.relatedTarget === actionButtonRef.current) {
isKeyboardVisibleWhenShowingModalRef.current = true;
}
},
[onComposerBlur],
);
const onFocus = useCallback(() => {
setIsFocused(true);
onComposerFocus?.();
}, [onComposerFocus]);
useEffect(() => {
if (hasExceededMaxTaskTitleLength) {
setExceededMaxLength(CONST.TITLE_CHARACTER_LIMIT);
} else if (hasExceededMaxCommentLength) {
setExceededMaxLength(CONST.MAX_COMMENT_LENGTH);
} else {
setExceededMaxLength(null);
}
}, [hasExceededMaxTaskTitleLength, hasExceededMaxCommentLength]);
// We are returning a callback here as we want to incoke the method on unmount only
useEffect(
() => () => {
if (!EmojiPickerActions.isActive(report?.reportID)) {
return;
}
EmojiPickerActions.hideEmojiPicker();
},
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[],
);
useEffect(() => {
const unsubscribe = navigation.addListener('blur', () => {
setShouldHideEducationalTooltip(true);
});
return unsubscribe;
}, [navigation]);
// When we invite someone to a room they don't have the policy object, but we still want them to be able to mention other reports they are members of, so we only check if the policyID in the report is from a workspace
const isGroupPolicyReport = useMemo(() => !!report?.policyID && report.policyID !== CONST.POLICY.ID_FAKE, [report]);
const reportRecipientAcountIDs = ReportUtils.getReportRecipientAccountIDs(report, currentUserPersonalDetails.accountID);
const reportRecipient = personalDetails?.[reportRecipientAcountIDs[0]];
const shouldUseFocusedColor = !isBlockedFromConcierge && !disabled && isFocused;
const hasReportRecipient = !isEmptyObject(reportRecipient);
const isSendDisabled = isCommentEmpty || isBlockedFromConcierge || !!disabled || !!exceededMaxLength;
// 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 handleSendMessage = useCallback(() => {
'worklet';
const clearComposer = composerRefShared.get().clear;
if (!clearComposer) {
throw new Error('The composerRefShared.clear function is not set yet. This should never happen, and indicates a developer error.');
}
if (isSendDisabled || !isReportReadyForDisplay) {
return;
}
// This will cause onCleared to be triggered where we actually send the message
clearComposer();
}, [isSendDisabled, isReportReadyForDisplay, composerRefShared]);
// eslint-disable-next-line react-compiler/react-compiler
onSubmitAction = handleSendMessage;
const emojiShiftVertical = useMemo(() => {
const chatItemComposeSecondaryRowHeight = styles.chatItemComposeSecondaryRow.height + styles.chatItemComposeSecondaryRow.marginTop + styles.chatItemComposeSecondaryRow.marginBottom;
const reportActionComposeHeight = styles.chatItemComposeBox.minHeight + chatItemComposeSecondaryRowHeight;
const emojiOffsetWithComposeBox = (styles.chatItemComposeBox.minHeight - styles.chatItemEmojiButton.height) / 2;
return reportActionComposeHeight - emojiOffsetWithComposeBox - CONST.MENU_POSITION_REPORT_ACTION_COMPOSE_BOTTOM;
}, [styles]);
const validateMaxLength = useCallback(
(value: string) => {
const taskCommentMatch = value?.match(CONST.REGEX.TASK_TITLE_WITH_OPTONAL_SHORT_MENTION);
if (taskCommentMatch) {
const title = taskCommentMatch?.[3] ? taskCommentMatch[3].trim().replace(/\n/g, ' ') : '';
setHasExceededMaxCommentLength(false);
validateTaskTitleMaxLength(title);
} else {
setHasExceededMaxTitleLength(false);
validateCommentMaxLength(value, {reportID});
}
},
[setHasExceededMaxCommentLength, setHasExceededMaxTitleLength, validateTaskTitleMaxLength, validateCommentMaxLength, reportID],
);
const debouncedValidate = useMemo(() => lodashDebounce(validateMaxLength, CONST.TIMING.COMMENT_LENGTH_DEBOUNCE_TIME, {leading: true}), [validateMaxLength]);
const onValueChange = useCallback(
(value: string) => {
if (value.length === 0 && isComposerFullSize) {
Report.setIsComposerFullSize(reportID, false);
}
debouncedValidate(value);
},
[isComposerFullSize, reportID, debouncedValidate],
);
return (
<View style={[shouldShowReportRecipientLocalTime && !isOffline && styles.chatItemComposeWithFirstRow, isComposerFullSize && styles.chatItemFullComposeRow]}>
<OfflineWithFeedback pendingAction={pendingAction}>
{shouldShowReportRecipientLocalTime && hasReportRecipient && <ParticipantLocalTime participant={reportRecipient} />}
</OfflineWithFeedback>
<View style={isComposerFullSize ? styles.flex1 : {}}>
<OfflineWithFeedback
shouldDisableOpacity
pendingAction={pendingAction}
style={isComposerFullSize ? styles.chatItemFullComposeRow : {}}
contentContainerStyle={isComposerFullSize ? styles.flex1 : {}}
>
<EducationalTooltip
shouldRender={!shouldHideEducationalTooltip && shouldShowProductTrainingTooltip}
renderTooltipContent={renderProductTrainingTooltip}
shouldUseOverlay
onHideTooltip={hideProductTrainingTooltip}
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
wrapperStyle={styles.reportActionComposeTooltipWrapper}
shiftHorizontal={variables.composerTooltipShiftHorizontal}
shiftVertical={variables.composerTooltipShiftVertical + offsetTop}
>
<View
ref={containerRef}
style={[
shouldUseFocusedColor ? styles.chatItemComposeBoxFocusedColor : styles.chatItemComposeBoxColor,
styles.flexRow,
styles.chatItemComposeBox,
isComposerFullSize && styles.chatItemFullComposeBox,
!!exceededMaxLength && styles.borderColorDanger,
]}
>
<AttachmentModal
headerTitle={translate('reportActionCompose.sendAttachment')}
onConfirm={addAttachment}
onModalShow={() => setIsAttachmentPreviewActive(true)}
onModalHide={onAttachmentPreviewClose}
shouldDisableSendButton={!!exceededMaxLength}
>
{({displayFileInModal}) => (
<>
<AttachmentPickerWithMenuItems
displayFileInModal={displayFileInModal}
reportID={reportID}
report={report}
reportParticipantIDs={reportParticipantIDs}
isComposerFullSize={isComposerFullSize}
isBlockedFromConcierge={isBlockedFromConcierge}
disabled={!!disabled}
setMenuVisibility={setMenuVisibility}
isMenuVisible={isMenuVisible}
onTriggerAttachmentPicker={onTriggerAttachmentPicker}
raiseIsScrollLikelyLayoutTriggered={raiseIsScrollLikelyLayoutTriggered}
onAddActionPressed={onAddActionPressed}
onItemSelected={onItemSelected}
onCanceledAttachmentPicker={() => {
if (!shouldFocusInputOnScreenFocus) {
return;
}
focus();
}}
actionButtonRef={actionButtonRef}
shouldDisableAttachmentItem={!!exceededMaxLength}
/>
<ComposerWithSuggestions
ref={(ref) => {
composerRef.current = ref ?? undefined;
composerRefShared.set({
clear: ref?.clear,
});
}}
suggestionsRef={suggestionsRef}
isNextModalWillOpenRef={isNextModalWillOpenRef}
isScrollLikelyLayoutTriggered={isScrollLikelyLayoutTriggered}
raiseIsScrollLikelyLayoutTriggered={raiseIsScrollLikelyLayoutTriggered}
reportID={reportID}
policyID={report?.policyID}
includeChronos={ReportUtils.chatIncludesChronos(report)}
isGroupPolicyReport={isGroupPolicyReport}
lastReportAction={lastReportAction}
isMenuVisible={isMenuVisible}
inputPlaceholder={inputPlaceholder}
isComposerFullSize={isComposerFullSize}
displayFileInModal={displayFileInModal}
onCleared={submitForm}
isBlockedFromConcierge={isBlockedFromConcierge}
disabled={!!disabled}
setIsCommentEmpty={setIsCommentEmpty}
handleSendMessage={handleSendMessage}
shouldShowComposeInput={shouldShowComposeInput}
onFocus={onFocus}
onBlur={onBlur}
measureParentContainer={measureContainer}
showSoftInputOnFocus={showSoftInputOnFocus}
setShowSoftInputOnFocus={setShowSoftInputOnFocus}
onValueChange={onValueChange}
didHideComposerInput={didHideComposerInput}
/>
<ReportDropUI
onDrop={(event: DragEvent) => {
if (isAttachmentPreviewActive) {
return;
}
const data = event.dataTransfer?.files[0];
if (data) {
data.uri = URL.createObjectURL(data);
displayFileInModal(data);
}
}}
/>
</>
)}
</AttachmentModal>
{DeviceCapabilities.canUseTouchScreen() && isMediumScreenWidth ? null : (
<EmojiPickerButton
isDisabled={isBlockedFromConcierge || disabled}
onModalHide={(isNavigating) => {
if (isNavigating) {
return;
}
const activeElementId = DomUtils.getActiveElement()?.id;
if (activeElementId === CONST.COMPOSER.NATIVE_ID || activeElementId === CONST.EMOJI_PICKER_BUTTON_NATIVE_ID) {
return;
}
focus();
}}
onEmojiSelected={(...args) => composerRef.current?.replaceSelectionWithText(...args)}
emojiPickerID={report?.reportID}
shiftVertical={emojiShiftVertical}
/>
)}
<SendButton
isDisabled={isSendDisabled}
handleSendMessage={handleSendMessage}
/>
</View>
</EducationalTooltip>
<View
style={[
styles.flexRow,
styles.justifyContentBetween,
styles.alignItemsCenter,
(!isSmallScreenWidth || (isSmallScreenWidth && !isOffline)) && styles.chatItemComposeSecondaryRow,
]}
>
{!shouldUseNarrowLayout && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />}
<ReportTypingIndicator reportID={reportID} />
{!!exceededMaxLength && (
<ExceededCommentLength
maxCommentLength={exceededMaxLength}
isTaskTitle={hasExceededMaxTaskTitleLength}
/>
)}
</View>
</OfflineWithFeedback>
{!isSmallScreenWidth && (
<View style={[styles.mln5, styles.mrn5]}>
<ImportedStateIndicator />
</View>
)}
</View>
</View>
);
}
ReportActionCompose.displayName = 'ReportActionCompose';
export default memo(ReportActionCompose);
export {onSubmitAction};
export type {SuggestionsRef, ComposerRef};