Skip to content

Commit

Permalink
Merge pull request Expensify#52659 from bernhardoj/fix/52382-caret-is…
Browse files Browse the repository at this point in the history
…-shown-at-right-side-for-a-moment-2

Hide search input caret while search modal is animating
  • Loading branch information
pecanoro authored Nov 19, 2024
2 parents 445fc42 + e86493a commit 5824bc0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/components/Search/SearchRouter/SearchRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useNavigationState} from '@react-navigation/native';
import {Str} from 'expensify-common';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import type {TextInputProps} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand Down Expand Up @@ -46,9 +47,10 @@ import type {AutocompleteItemData} from './SearchRouterList';

type SearchRouterProps = {
onRouterClose: () => void;
shouldHideInputCaret?: TextInputProps['caretHidden'];
};

function SearchRouter({onRouterClose}: SearchRouterProps) {
function SearchRouter({onRouterClose, shouldHideInputCaret}: SearchRouterProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [betas] = useOnyx(ONYXKEYS.BETAS);
Expand Down Expand Up @@ -396,6 +398,7 @@ function SearchRouter({onRouterClose}: SearchRouterProps) {
onSubmit={() => {
onSearchSubmit(textInputValue);
}}
caretHidden={shouldHideInputCaret}
routerListRef={listRef}
shouldShowOfflineMessage
wrapperStyle={[styles.border, styles.alignItemsCenter]}
Expand Down
9 changes: 4 additions & 5 deletions src/components/Search/SearchRouter/SearchRouterInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ReactNode, RefObject} from 'react';
import React, {useState} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import type {StyleProp, TextInputProps, ViewStyle} from 'react-native';
import {View} from 'react-native';
import FormHelpMessage from '@components/FormHelpMessage';
import type {SelectionListHandle} from '@components/SelectionList/types';
Expand Down Expand Up @@ -34,9 +34,6 @@ type SearchRouterInputProps = {
/** Whether the offline message should be shown */
shouldShowOfflineMessage?: boolean;

/** Whether the input should be focused */
autoFocus?: boolean;

/** Any additional styles to apply */
wrapperStyle?: StyleProp<ViewStyle>;

Expand All @@ -51,7 +48,7 @@ type SearchRouterInputProps = {

/** Whether the search reports API call is running */
isSearchingForReports?: boolean;
};
} & Pick<TextInputProps, 'caretHidden' | 'autoFocus'>;

function SearchRouterInput({
value,
Expand All @@ -62,6 +59,7 @@ function SearchRouterInput({
disabled = false,
shouldShowOfflineMessage = false,
autoFocus = true,
caretHidden = false,
wrapperStyle,
wrapperFocusedStyle,
outerWrapperStyle,
Expand All @@ -86,6 +84,7 @@ function SearchRouterInput({
onChangeText={updateSearch}
autoFocus={autoFocus}
shouldDelayFocus={shouldDelayFocus}
caretHidden={caretHidden}
loadingSpinnerStyle={[styles.mt0, styles.mr2]}
role={CONST.ROLE.PRESENTATION}
placeholder={translate('search.searchPlaceholder')}
Expand Down
14 changes: 12 additions & 2 deletions src/components/Search/SearchRouter/SearchRouterModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useState} from 'react';
import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal';
import Modal from '@components/Modal';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand All @@ -7,10 +7,15 @@ import CONST from '@src/CONST';
import SearchRouter from './SearchRouter';
import {useSearchRouterContext} from './SearchRouterContext';

const isMobileSafari = Browser.isMobileSafari();

function SearchRouterModal() {
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {isSearchRouterDisplayed, closeSearchRouter} = useSearchRouterContext();

// On mWeb Safari, the input caret stuck for a moment while the modal is animating. So, we hide the caret until the animation is done.
const [shouldHideInputCaret, setShouldHideInputCaret] = useState(isMobileSafari);

const modalType = shouldUseNarrowLayout ? CONST.MODAL.MODAL_TYPE.CENTERED_SWIPABLE_TO_RIGHT : CONST.MODAL.MODAL_TYPE.POPOVER;

return (
Expand All @@ -22,10 +27,15 @@ function SearchRouterModal() {
propagateSwipe
shouldHandleNavigationBack={Browser.isMobileChrome()}
onClose={closeSearchRouter}
onModalHide={() => setShouldHideInputCaret(isMobileSafari)}
onModalShow={() => setShouldHideInputCaret(false)}
>
{isSearchRouterDisplayed && (
<FocusTrapForModal active={isSearchRouterDisplayed}>
<SearchRouter onRouterClose={closeSearchRouter} />
<SearchRouter
onRouterClose={closeSearchRouter}
shouldHideInputCaret={shouldHideInputCaret}
/>
</FocusTrapForModal>
)}
</Modal>
Expand Down

0 comments on commit 5824bc0

Please sign in to comment.