Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert pull 51172 #54633

Closed
wants to merge 3 commits into from
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
17 changes: 1 addition & 16 deletions src/components/Composer/implementation/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type {MarkdownStyle} from '@expensify/react-native-live-markdown';
import mimeDb from 'mime-db';
import type {ForwardedRef} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
import type {NativeSyntheticEvent, TextInput, TextInputChangeEventData, TextInputPasteEventData} from 'react-native';
import {StyleSheet} from 'react-native';
import type {FileObject} from '@components/AttachmentModal';
import type {ComposerProps} from '@components/Composer/types';
import type {AnimatedMarkdownTextInputRef} from '@components/RNMarkdownTextInput';
import RNMarkdownTextInput from '@components/RNMarkdownTextInput';
import useAutoFocusInput from '@hooks/useAutoFocusInput';
import useKeyboardState from '@hooks/useKeyboardState';
import useMarkdownStyle from '@hooks/useMarkdownStyle';
import useResetComposerFocus from '@hooks/useResetComposerFocus';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down Expand Up @@ -38,7 +37,6 @@ function Composer(
selection,
value,
isGroupPolicyReport = false,
showSoftInputOnFocus = true,
...props
}: ComposerProps,
ref: ForwardedRef<TextInput>,
Expand All @@ -51,11 +49,7 @@ function Composer(
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

const [contextMenuHidden, setContextMenuHidden] = useState(true);

const {inputCallbackRef, inputRef: autoFocusInputRef} = useAutoFocusInput();
const keyboardState = useKeyboardState();
const isKeyboardShown = keyboardState?.isKeyboardShown ?? false;

useEffect(() => {
if (autoFocus === !!autoFocusInputRef.current) {
Expand All @@ -64,13 +58,6 @@ function Composer(
inputCallbackRef(autoFocus ? textInput.current : null);
}, [autoFocus, inputCallbackRef, autoFocusInputRef]);

useEffect(() => {
if (!showSoftInputOnFocus || !isKeyboardShown) {
return;
}
setContextMenuHidden(false);
}, [showSoftInputOnFocus, isKeyboardShown]);

useEffect(() => {
if (!textInput.current || !textInput.current.setSelection || !selection || isComposerFullSize) {
return;
Expand Down Expand Up @@ -171,8 +158,6 @@ function Composer(
props?.onBlur?.(e);
}}
onClear={onClear}
showSoftInputOnFocus={showSoftInputOnFocus}
contextMenuHidden={contextMenuHidden}
/>
);
}
Expand Down
20 changes: 2 additions & 18 deletions src/components/Composer/implementation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {BaseSyntheticEvent, ForwardedRef} from 'react';
import React, {useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {NativeSyntheticEvent, TextInput, TextInputKeyPressEventData, TextInputSelectionChangeEventData} from 'react-native';
import {DeviceEventEmitter, InteractionManager, StyleSheet} from 'react-native';
import {DeviceEventEmitter, StyleSheet} from 'react-native';
import type {ComposerProps} from '@components/Composer/types';
import type {AnimatedMarkdownTextInputRef} from '@components/RNMarkdownTextInput';
import RNMarkdownTextInput from '@components/RNMarkdownTextInput';
Expand Down Expand Up @@ -50,7 +50,6 @@ function Composer(
isComposerFullSize = false,
shouldContainScroll = true,
isGroupPolicyReport = false,
showSoftInputOnFocus = true,
...props
}: ComposerProps,
ref: ForwardedRef<TextInput | HTMLInputElement>,
Expand All @@ -75,11 +74,6 @@ function Composer(
});
const [hasMultipleLines, setHasMultipleLines] = useState(false);
const [isRendered, setIsRendered] = useState(false);

// On mobile safari, the cursor will move from right to left with inputMode set to none during report transition
// To avoid that we should hide the cursor util the transition is finished
const [shouldTransparentCursor, setShouldTransparentCursor] = useState(!showSoftInputOnFocus && Browser.isMobileSafari());

const isScrollBarVisible = useIsScrollBarVisible(textInput, value ?? '');
const [prevScroll, setPrevScroll] = useState<number | undefined>();
const [prevHeight, setPrevHeight] = useState<number | undefined>();
Expand Down Expand Up @@ -266,15 +260,6 @@ function Composer(
setIsRendered(true);
}, []);

useEffect(() => {
if (!shouldTransparentCursor) {
return;
}
InteractionManager.runAfterInteractions(() => {
setShouldTransparentCursor(false);
});
}, [shouldTransparentCursor]);

const clear = useCallback(() => {
if (!textInput.current) {
return;
Expand Down Expand Up @@ -362,12 +347,11 @@ function Composer(
placeholderTextColor={theme.placeholderText}
ref={(el) => (textInput.current = el)}
selection={selection}
style={[inputStyleMemo, shouldTransparentCursor ? {caretColor: 'transparent'} : undefined]}
style={[inputStyleMemo]}
markdownStyle={markdownStyle}
value={value}
defaultValue={defaultValue}
autoFocus={autoFocus}
inputMode={showSoftInputOnFocus ? 'text' : 'none'}
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...props}
onSelectionChange={addCursorPositionToSelectionChange}
Expand Down
3 changes: 0 additions & 3 deletions src/components/Composer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ type ComposerProps = Omit<TextInputProps, 'onClear'> & {

/** Indicates whether the composer is in a group policy report. Used for disabling report mentioning style in markdown input */
isGroupPolicyReport?: boolean;

/** Whether to show the keyboard on focus */
showSoftInputOnFocus?: boolean;
};

export type {TextSelection, ComposerProps, CustomSelectionChangeEvent};
4 changes: 2 additions & 2 deletions src/libs/actions/EmojiPickerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ function hideEmojiPicker(isNavigating?: boolean) {
/**
* Whether Emoji Picker is active for the given id.
*/
function isActive(id?: string): boolean {
if (!emojiPickerRef.current || !id) {
function isActive(id: string): boolean {
if (!emojiPickerRef.current) {
return false;
}

Expand Down
7 changes: 3 additions & 4 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro

const {reportPendingAction, reportErrors} = ReportUtils.getReportOfflinePendingActionAndErrors(report);
const screenWrapperStyle: ViewStyle[] = [styles.appContent, styles.flex1, {marginTop: viewportOffsetTop}];
const isEmptyChat = useMemo(() => ReportUtils.isEmptyReport(report), [report]);
const isOptimisticDelete = report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED;
const indexOfLinkedMessage = useMemo(
(): number => reportActions.findIndex((obj) => String(obj.reportActionID) === String(reportActionIDFromRoute)),
Expand Down Expand Up @@ -279,7 +280,6 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '-1'}`];
const isTopMostReportId = currentReportID === reportIDFromRoute;
const didSubscribeToReportLeavingEvents = useRef(false);
const [showSoftInputOnFocus, setShowSoftInputOnFocus] = useState(false);

useEffect(() => {
if (!report?.reportID || shouldHideReport) {
Expand Down Expand Up @@ -757,7 +757,7 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
<ScreenWrapper
navigation={navigation}
style={screenWrapperStyle}
shouldEnableKeyboardAvoidingView={(isTopMostReportId || isInNarrowPaneModal) && (!isComposerFocus || showSoftInputOnFocus)}
shouldEnableKeyboardAvoidingView={isTopMostReportId || isInNarrowPaneModal}
testID={`report-screen-${reportID ?? ''}`}
>
<FullPageNotFoundView
Expand Down Expand Up @@ -854,9 +854,8 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
policy={policy}
pendingAction={reportPendingAction}
isComposerFullSize={!!isComposerFullSize}
isEmptyChat={isEmptyChat}
lastReportAction={lastReportAction}
showSoftInputOnFocus={showSoftInputOnFocus}
setShowSoftInputOnFocus={setShowSoftInputOnFocus}
/>
) : null}
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import * as KeyDownListener from '@libs/KeyboardShortcut/KeyDownPressListener';
import Parser from '@libs/Parser';
import ReportActionComposeFocusManager from '@libs/ReportActionComposeFocusManager';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import updateMultilineInputRange from '@libs/updateMultilineInputRange';
import willBlurTextInputOnTapOutsideFunc from '@libs/willBlurTextInputOnTapOutside';
Expand Down Expand Up @@ -125,26 +126,27 @@
/** The ref to the next modal will open */
isNextModalWillOpenRef: MutableRefObject<boolean | null>;

/** Wheater chat is empty */
isEmptyChat?: boolean;

/** The last report action */
lastReportAction?: OnyxEntry<OnyxTypes.ReportAction>;

/** Whether to include chronos */
includeChronos?: boolean;

/** The parent report action ID */
parentReportActionID?: string;

/** The parent report ID */
// eslint-disable-next-line react/no-unused-prop-types -- its used in the withOnyx HOC
parentReportID: string | undefined;

/** Whether report is from group policy */
isGroupPolicyReport: boolean;

/** policy ID of the report */
policyID?: string;

/** 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;
policyID: string;
};

type SwitchToCurrentReportProps = {
Expand Down Expand Up @@ -185,6 +187,10 @@

const willBlurTextInputOnTapOutside = willBlurTextInputOnTapOutsideFunc();

// 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();

/**
* This component holds the value and selection state.
* If a component really needs access to these state values it should be put here.
Expand All @@ -195,8 +201,11 @@
{
// Props: Report
reportID,
parentReportID,
includeChronos,
isEmptyChat,
lastReportAction,
parentReportActionID,
isGroupPolicyReport,
policyID,

Expand Down Expand Up @@ -227,9 +236,6 @@

// For testing
children,
showSoftInputOnFocus,
setShowSoftInputOnFocus,
didHideComposerInput,
}: ComposerWithSuggestionsProps,
ref: ForwardedRef<ComposerRef>,
) {
Expand All @@ -251,12 +257,14 @@
}
return draftComment;
});

const commentRef = useRef(value);

const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [modal] = useOnyx(ONYXKEYS.MODAL);
const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {selector: EmojiUtils.getPreferredSkinToneIndex});
const [editFocused] = useOnyx(ONYXKEYS.INPUT_FOCUSED);
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID || '-1'}`, {canEvict: false, initWithStoredValues: false});

Check failure on line 267 in src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check


const lastTextRef = useRef(value);
useEffect(() => {
Expand All @@ -266,7 +274,13 @@
const {shouldUseNarrowLayout} = useResponsiveLayout();
const maxComposerLines = shouldUseNarrowLayout ? CONST.COMPOSER.MAX_LINES_SMALL_SCREEN : CONST.COMPOSER.MAX_LINES;

const shouldAutoFocus = !modal?.isVisible && shouldShowComposeInput && Modal.areAllModalsHidden() && isFocused && !didHideComposerInput;
const parentReportAction = useMemo(() => parentReportActions?.[parentReportActionID ?? '-1'], [parentReportActionID, parentReportActions]);

Check failure on line 277 in src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const shouldAutoFocus =
!modal?.isVisible &&
Modal.areAllModalsHidden() &&
isFocused &&
(shouldFocusInputOnScreenFocus || (isEmptyChat && !ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportUtils.isTaskReport(report))) &&
shouldShowComposeInput;

const valueRef = useRef(value);
valueRef.current = value;
Expand Down Expand Up @@ -629,15 +643,7 @@
// We want to focus or refocus the input when a modal has been closed or the underlying screen is refocused.
// We avoid doing this on native platforms since the software keyboard popping
// open creates a jarring and broken UX.
if (
!(
(willBlurTextInputOnTapOutside || (shouldAutoFocus && canFocusInputOnScreenFocus())) &&
!isNextModalWillOpenRef.current &&
!modal?.isVisible &&
isFocused &&
(!!prevIsModalVisible || !prevIsFocused)
)
) {
if (!((willBlurTextInputOnTapOutside || shouldAutoFocus) && !isNextModalWillOpenRef.current && !modal?.isVisible && isFocused && (!!prevIsModalVisible || !prevIsFocused))) {
return;
}

Expand Down Expand Up @@ -769,19 +775,6 @@
onScroll={hideSuggestionMenu}
shouldContainScroll={Browser.isMobileSafari()}
isGroupPolicyReport={isGroupPolicyReport}
showSoftInputOnFocus={showSoftInputOnFocus}
onTouchStart={() => {
if (showSoftInputOnFocus) {
return;
}
if (Browser.isMobileSafari()) {
setTimeout(() => {
setShowSoftInputOnFocus(true);
}, CONST.ANIMATED_TRANSITION);
return;
}
setShowSoftInputOnFocus(true);
}}
/>
</View>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
getIsSuggestionsMenuVisible: () => boolean;
};

type ReportActionComposeProps = Pick<ComposerWithSuggestionsProps, 'reportID' | 'isComposerFullSize' | 'lastReportAction'> & {
type ReportActionComposeProps = Pick<ComposerWithSuggestionsProps, 'reportID' | 'isEmptyChat' | 'isComposerFullSize' | 'lastReportAction'> & {
/** A method to call when the form is submitted */
onSubmit: (newComment: string) => void;

Expand All @@ -88,15 +88,6 @@

/** 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
Expand All @@ -116,13 +107,11 @@
report,
reportID,
isReportReadyForDisplay = true,
isEmptyChat,
lastReportAction,
shouldShowEducationalTooltip,
showSoftInputOnFocus,
onComposerFocus,
onComposerBlur,
setShowSoftInputOnFocus,
didHideComposerInput,
}: ReportActionComposeProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
Expand Down Expand Up @@ -335,7 +324,7 @@
// We are returning a callback here as we want to incoke the method on unmount only
useEffect(
() => () => {
if (!EmojiPickerActions.isActive(report?.reportID)) {
if (!EmojiPickerActions.isActive(report?.reportID ?? '-1')) {

Check failure on line 327 in src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

return;
}
EmojiPickerActions.hideEmojiPicker();
Expand Down Expand Up @@ -498,9 +487,12 @@
isScrollLikelyLayoutTriggered={isScrollLikelyLayoutTriggered}
raiseIsScrollLikelyLayoutTriggered={raiseIsScrollLikelyLayoutTriggered}
reportID={reportID}
policyID={report?.policyID}
policyID={report?.policyID ?? '-1'}

Check failure on line 490 in src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

parentReportID={report?.parentReportID}
parentReportActionID={report?.parentReportActionID}
includeChronos={ReportUtils.chatIncludesChronos(report)}
isGroupPolicyReport={isGroupPolicyReport}
isEmptyChat={isEmptyChat}
lastReportAction={lastReportAction}
isMenuVisible={isMenuVisible}
inputPlaceholder={inputPlaceholder}
Expand All @@ -515,10 +507,7 @@
onFocus={onFocus}
onBlur={onBlur}
measureParentContainer={measureContainer}
showSoftInputOnFocus={showSoftInputOnFocus}
setShowSoftInputOnFocus={setShowSoftInputOnFocus}
onValueChange={onValueChange}
didHideComposerInput={didHideComposerInput}
/>
<ReportDropUI
onDrop={(event: DragEvent) => {
Expand Down
Loading
Loading