Skip to content
Merged
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
11 changes: 9 additions & 2 deletions src/components/Share/ShareTabParticipantsSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {forwardRef} from 'react';
import {saveUnknownUserDetails} from '@libs/actions/Share';
import Navigation from '@libs/Navigation/Navigation';
import MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyRequestParticipantsSelector';
Expand All @@ -10,9 +10,14 @@ type ShareTabParticipantsSelectorProps = {
detailsPageRouteObject: typeof ROUTES.SHARE_SUBMIT_DETAILS | typeof ROUTES.SHARE_DETAILS;
};

export default function ShareTabParticipantsSelector({detailsPageRouteObject}: ShareTabParticipantsSelectorProps) {
type InputFocusRef = {
focus?: () => void;
};

function ShareTabParticipantsSelectorComponent({detailsPageRouteObject}: ShareTabParticipantsSelectorProps, ref: React.Ref<InputFocusRef>) {
return (
<MoneyRequestParticipantsSelector
ref={ref}
iouType={CONST.IOU.TYPE.SUBMIT}
onParticipantsAdded={(value) => {
const participant = value.at(0);
Expand All @@ -34,3 +39,5 @@ export default function ShareTabParticipantsSelector({detailsPageRouteObject}: S
/>
);
}

export default forwardRef<InputFocusRef, ShareTabParticipantsSelectorProps>(ShareTabParticipantsSelectorComponent);
26 changes: 23 additions & 3 deletions src/pages/Share/ShareRootPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {Alert, AppState, View} from 'react-native';
import {Alert, AppState, InteractionManager, View} from 'react-native';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import ScreenWrapper from '@components/ScreenWrapper';
import TabNavigatorSkeleton from '@components/Skeletons/TabNavigatorSkeleton';
import TabSelector from '@components/TabSelector/TabSelector';
Expand Down Expand Up @@ -122,6 +123,24 @@ function ShareRootPage() {
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);

const shareTabInputRef = useRef<AnimatedTextInputRef | null>(null);
const submitTabInputRef = useRef<AnimatedTextInputRef | null>(null);

// We're focusing the input using internal onPageSelected to fix input focus inconsistencies on native.
// More info: https://github.com/Expensify/App/issues/59388
const onTabSelectFocusHandler = ({index}: {index: number}) => {
// We runAfterInteractions since the function is called in the animate block on web-based
// implementation, this fixes an animation glitch and matches the native internal delay
InteractionManager.runAfterInteractions(() => {
// Chat tab (0) / Room tab (1) according to OnyxTabNavigator (see below)
if (index === 0) {
shareTabInputRef.current?.focus();
} else if (index === 1) {
submitTabInputRef.current?.focus();
}
});
};

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand All @@ -139,9 +158,10 @@ function ShareRootPage() {
<OnyxTabNavigator
id={CONST.TAB.SHARE.NAVIGATOR_ID}
tabBar={TabSelector}
onTabSelect={onTabSelectFocusHandler}
>
<TopTab.Screen name={CONST.TAB.SHARE.SHARE}>{() => <ShareTab />}</TopTab.Screen>
{isFileScannable && <TopTab.Screen name={CONST.TAB.SHARE.SUBMIT}>{() => <SubmitTab />}</TopTab.Screen>}
<TopTab.Screen name={CONST.TAB.SHARE.SHARE}>{() => <ShareTab ref={shareTabInputRef} />}</TopTab.Screen>
{isFileScannable && <TopTab.Screen name={CONST.TAB.SHARE.SUBMIT}>{() => <SubmitTab ref={submitTabInputRef} />}</TopTab.Screen>}
</OnyxTabNavigator>
) : (
<TabNavigatorSkeleton />
Expand Down
18 changes: 15 additions & 3 deletions src/pages/Share/ShareTab.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, {useEffect, useMemo} from 'react';
import React, {forwardRef, useEffect, useImperativeHandle, useMemo, useRef} from 'react';
import {useOptionsList} from '@components/OptionListContextProvider';
import SelectionList from '@components/SelectionList';
import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem';
import type {SelectionListHandle} from '@components/SelectionList/types';
import useDebouncedState from '@hooks/useDebouncedState';
import useFastSearchFromOptions from '@hooks/useFastSearchFromOptions';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -27,12 +28,21 @@ const defaultListOptions = {
categoryOptions: [],
};

function ShareTab() {
type ShareTabRef = {
focus?: () => void;
};

function ShareTab(_: unknown, ref: React.Ref<ShareTabRef>) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const [textInputValue, debouncedTextInputValue, setTextInputValue] = useDebouncedState('');
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const selectionListRef = useRef<SelectionListHandle | null>(null);

useImperativeHandle(ref, () => ({
focus: selectionListRef.current?.focusTextInput,
}));

const {options, areOptionsInitialized} = useOptionsList();
const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus();
Expand Down Expand Up @@ -115,8 +125,10 @@ function ShareTab() {
shouldSingleExecuteRowSelect
onSelectRow={onSelectRow}
isLoadingNewOptions={!!isSearchingForReports}
textInputAutoFocus={false}
ref={selectionListRef}
/>
);
}

export default ShareTab;
export default forwardRef(ShareTab);
16 changes: 13 additions & 3 deletions src/pages/Share/SubmitTab.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import React from 'react';
import React, {forwardRef} from 'react';
import ShareTabParticipantsSelector from '@components/Share/ShareTabParticipantsSelector';
import ROUTES from '@src/ROUTES';

function SubmitTab() {
return <ShareTabParticipantsSelector detailsPageRouteObject={ROUTES.SHARE_SUBMIT_DETAILS} />;
type InputFocusRef = {
focus?: () => void;
};

function SubmitTabComponent(_props: unknown, ref: React.Ref<InputFocusRef>) {
return (
<ShareTabParticipantsSelector
ref={ref}
detailsPageRouteObject={ROUTES.SHARE_SUBMIT_DETAILS}
/>
);
}

const SubmitTab = forwardRef(SubmitTabComponent);
export default SubmitTab;
52 changes: 39 additions & 13 deletions src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {deepEqual} from 'fast-equals';
import lodashPick from 'lodash/pick';
import lodashReject from 'lodash/reject';
import React, {memo, useCallback, useEffect, useMemo, useState} from 'react';
import React, {forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import type {Ref} from 'react';
import type {GestureResponderEvent} from 'react-native';
import {InteractionManager} from 'react-native';
import {RESULTS} from 'react-native-permissions';
Expand All @@ -17,6 +18,7 @@ import {useOptionsList} from '@components/OptionListContextProvider';
import ReferralProgramCTA from '@components/ReferralProgramCTA';
import SelectionList from '@components/SelectionList';
import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem';
import type {SelectionListHandle} from '@components/SelectionList/types';
import useDebouncedState from '@hooks/useDebouncedState';
import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -81,15 +83,22 @@ type MoneyRequestParticipantsSelectorProps = {
isPerDiemRequest?: boolean;
};

function MoneyRequestParticipantsSelector({
participants = CONST.EMPTY_ARRAY,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onFinish = (_value?: string) => {},
onParticipantsAdded,
iouType,
action,
isPerDiemRequest = false,
}: MoneyRequestParticipantsSelectorProps) {
type InputFocusRef = {
focus?: () => void;
};

function MoneyRequestParticipantsSelector(
{
participants = CONST.EMPTY_ARRAY,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onFinish = (_value?: string) => {},
onParticipantsAdded,
iouType,
action,
isPerDiemRequest = false,
}: MoneyRequestParticipantsSelectorProps,
ref: Ref<InputFocusRef>,
) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
Expand All @@ -112,6 +121,7 @@ function MoneyRequestParticipantsSelector({
});
const [contacts, setContacts] = useState<Array<SearchOption<PersonalDetails>>>([]);
const [textInputAutoFocus, setTextInputAutoFocus] = useState<boolean>(!isNative);
const selectionListRef = useRef<SelectionListHandle | null>(null);
const cleanSearchTerm = useMemo(() => debouncedSearchTerm.trim().toLowerCase(), [debouncedSearchTerm]);
const offlineMessage: string = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : '';

Expand Down Expand Up @@ -575,12 +585,24 @@ function MoneyRequestParticipantsSelector({
);
}, [iouType, ClickableImportContactTextComponent]);

useImperativeHandle(ref, () => ({
focus: () => {
if (!textInputAutoFocus) {
return;
}
selectionListRef.current?.focusTextInput?.();
},
}));

return (
<>
<ContactPermissionModal
onGrant={initiateContactImportAndSetState}
onDeny={setContactPermissionState}
onFocusTextInput={() => setTextInputAutoFocus(true)}
onFocusTextInput={() => {
setTextInputAutoFocus(true);
selectionListRef.current?.focusTextInput?.();
}}
Comment on lines +602 to +605

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.

This line causes: #70626

More details:
#70626 (comment)

/>
<SelectionList
onConfirm={handleConfirmSelection}
Expand Down Expand Up @@ -608,12 +630,16 @@ function MoneyRequestParticipantsSelector({
canSelectMultiple={isIOUSplit && isAllowedToSplit}
isLoadingNewOptions={!!isSearchingForReports}
shouldShowListEmptyContent={shouldShowListEmptyContent}
textInputAutoFocus={textInputAutoFocus}
textInputAutoFocus={!isNative}
ref={selectionListRef}
/>
</>
);
}

MoneyRequestParticipantsSelector.displayName = 'MoneyTemporaryForRefactorRequestParticipantsSelector';

export default memo(MoneyRequestParticipantsSelector, (prevProps, nextProps) => deepEqual(prevProps.participants, nextProps.participants) && prevProps.iouType === nextProps.iouType);
export default memo(
forwardRef(MoneyRequestParticipantsSelector),
(prevProps, nextProps) => deepEqual(prevProps.participants, nextProps.participants) && prevProps.iouType === nextProps.iouType,
);