Skip to content

Commit

Permalink
merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemorawski committed Apr 8, 2024
1 parent 64b8c8a commit 16eccc0
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 39 deletions.
28 changes: 17 additions & 11 deletions src/components/ScreenWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {useNavigation} from '@react-navigation/native';
import type {StackNavigationProp} from '@react-navigation/stack';
import type {ForwardedRef, ReactNode} from 'react';
import React, {forwardRef, useEffect, useRef, useState} from 'react';
import React, {createContext, forwardRef, useEffect, useMemo, useRef, useState} from 'react';
import type {DimensionValue, StyleProp, ViewStyle} from 'react-native';
import {Keyboard, PanResponder, View} from 'react-native';
import {PickerAvoidingView} from 'react-native-picker-select';
Expand Down Expand Up @@ -99,6 +99,8 @@ type ScreenWrapperProps = {
shouldShowOfflineIndicatorInWideScreen?: boolean;
};

const ScreenWrapperStatusContext = createContext({didScreenTransitionEnd: false});

function ScreenWrapper(
{
shouldEnableMaxHeight = false,
Expand Down Expand Up @@ -201,6 +203,7 @@ function ScreenWrapper(
}, []);

const isAvoidingViewportScroll = useTackInputFocus(shouldEnableMaxHeight && shouldAvoidScrollOnVirtualViewport && Browser.isMobileSafari());
const contextValue = useMemo(() => ({didScreenTransitionEnd}), [didScreenTransitionEnd]);

return (
<SafeAreaConsumer>
Expand Down Expand Up @@ -251,16 +254,18 @@ function ScreenWrapper(
<HeaderGap styles={headerGapStyles} />
<TestToolsModal />
{isDevelopment && <CustomDevMenu />}
{
// If props.children is a function, call it to provide the insets to the children.
typeof children === 'function'
? children({
insets,
safeAreaPaddingBottomStyle,
didScreenTransitionEnd,
})
: children
}
<ScreenWrapperStatusContext.Provider value={contextValue}>
{
// If props.children is a function, call it to provide the insets to the children.
typeof children === 'function'
? children({
insets,
safeAreaPaddingBottomStyle,
didScreenTransitionEnd,
})
: children
}
</ScreenWrapperStatusContext.Provider>
{isSmallScreenWidth && shouldShowOfflineIndicator && <OfflineIndicator style={offlineIndicatorStyle} />}
{!isSmallScreenWidth && shouldShowOfflineIndicatorInWideScreen && (
<OfflineIndicator
Expand All @@ -281,3 +286,4 @@ function ScreenWrapper(
ScreenWrapper.displayName = 'ScreenWrapper';

export default withNavigationFallback(forwardRef(ScreenWrapper));
export {ScreenWrapperStatusContext};
17 changes: 17 additions & 0 deletions src/hooks/useScreenWrapperTransitionStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {useContext} from 'react';
import {ScreenWrapperStatusContext} from '@components/ScreenWrapper';

/**
* Hook to get the transition status of a screen inside a ScreenWrapper.
* Use this hook if you can't get the transition status from the ScreenWrapper itself. Usually when ScreenWrapper is used inside TopTabNavigator.
* @returns `didScreenTransitionEnd` flag to indicate if navigation transition ended.
*/
export default function useScreenWrapperTranstionStatus() {
const value = useContext(ScreenWrapperStatusContext);

if (value === undefined) {
throw new Error("Couldn't find values for screen ScreenWrapper transition status. Are you inside a screen in ScreenWrapper?");
}

return value;
}
8 changes: 4 additions & 4 deletions src/pages/SearchPage/SearchPageFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import {View} from 'react-native';
import ReferralProgramCTA from '@components/ReferralProgramCTA';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
Expand All @@ -8,9 +7,10 @@ function SearchPageFooter() {
const themeStyles = useThemeStyles();

return (
<View style={[themeStyles.flexShrink0]}>
<ReferralProgramCTA referralContentType={CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND} />
</View>
<ReferralProgramCTA
referralContentType={CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND}
style={themeStyles.flexShrink0}
/>
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/pages/SearchPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import {useOptionsList} from '@components/OptionListContextProvider';
Expand All @@ -12,6 +11,7 @@ import useDebouncedState from '@hooks/useDebouncedState';
import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useThemeStyles from '@hooks/useThemeStyles';
import type {MaybePhraseKey} from '@libs/Localize';
import Navigation from '@libs/Navigation/Navigation';
import type {RootStackParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -78,7 +78,7 @@ function SearchPage({betas, isSearchingForReports, navigation}: SearchPageProps)
userToInvite,
headerMessage,
} = useMemo(() => {
if (!areOptionsInitialized) {
if (!areOptionsInitialized || !isScreenTransitionEnd) {
return {
recentReports: [],
personalDetails: [],
Expand All @@ -89,7 +89,7 @@ function SearchPage({betas, isSearchingForReports, navigation}: SearchPageProps)
const optionList = OptionsListUtils.getSearchOptions(options, debouncedSearchValue.trim(), betas ?? []);
const header = OptionsListUtils.getHeaderMessage(optionList.recentReports.length + optionList.personalDetails.length !== 0, Boolean(optionList.userToInvite), debouncedSearchValue);
return {...optionList, headerMessage: header};
}, [areOptionsInitialized, options, debouncedSearchValue, betas]);
}, [areOptionsInitialized, options, debouncedSearchValue, betas, isScreenTransitionEnd]);

const sections = useMemo((): SearchPageSectionList => {
const newSections: SearchPageSectionList = [];
Expand Down Expand Up @@ -160,7 +160,7 @@ function SearchPage({betas, isSearchingForReports, navigation}: SearchPageProps)
headerMessageStyle={headerMessage === translate('common.noResultsFound') ? [themeStyles.ph4, themeStyles.pb5] : undefined}
onLayout={setPerformanceTimersEnd}
onSelectRow={selectReport}
showLoadingPlaceholder={!areOptionsInitialized}
showLoadingPlaceholder={!areOptionsInitialized || !isScreenTransitionEnd}
footerContent={!isDismissed && SerachPageFooterInstance}
isLoadingNewOptions={isSearchingForReports ?? undefined}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus';
import useThemeStyles from '@hooks/useThemeStyles';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as OptionsListUtils from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -50,18 +51,14 @@ const propTypes = {

/** The request type, ie. manual, scan, distance */
iouRequestType: PropTypes.oneOf(_.values(CONST.IOU.REQUEST_TYPE)).isRequired,

/** Whether the parent screen transition has ended */
didScreenTransitionEnd: PropTypes.bool,
};

const defaultProps = {
participants: [],
betas: [],
didScreenTransitionEnd: false,
};

function MoneyTemporaryForRefactorRequestParticipantsSelector({betas, participants, onFinish, onParticipantsAdded, iouType, iouRequestType, didScreenTransitionEnd}) {
function MoneyTemporaryForRefactorRequestParticipantsSelector({betas, participants, onFinish, onParticipantsAdded, iouType, iouRequestType}) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
Expand All @@ -70,6 +67,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({betas, participan
const personalDetails = usePersonalDetails();
const {isDismissed} = useDismissedReferralBanners({referralContentType});
const {canUseP2PDistanceRequests} = usePermissions();
const {didScreenTransitionEnd} = useScreenWrapperTranstionStatus();
const {options, areOptionsInitialized} = useOptionsList({
shouldInitialize: didScreenTransitionEnd,
});
Expand All @@ -89,7 +87,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({betas, participan
*/
const [sections, newChatOptions] = useMemo(() => {
const newSections = [];
if (!areOptionsInitialized) {
if (!areOptionsInitialized || !didScreenTransitionEnd) {
return [newSections, {}];
}
const chatOptions = OptionsListUtils.getFilteredOptions(
Expand Down Expand Up @@ -168,6 +166,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({betas, participan
maxParticipantsReached,
personalDetails,
translate,
didScreenTransitionEnd,
]);

/**
Expand Down Expand Up @@ -352,7 +351,7 @@ function MoneyTemporaryForRefactorRequestParticipantsSelector({betas, participan
onSelectRow={addSingleParticipant}
footerContent={footerContent}
headerMessage={headerMessage}
showLoadingPlaceholder={!areOptionsInitialized}
showLoadingPlaceholder={!areOptionsInitialized || !didScreenTransitionEnd}
rightHandSideComponent={itemRightSideComponent}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import lodashGet from 'lodash/get';
import lodashSize from 'lodash/size';
import PropTypes from 'prop-types';
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import transactionPropTypes from '@components/transactionPropTypes';
import useInitialValue from '@hooks/useInitialValue';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import compose from '@libs/compose';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';
Expand Down Expand Up @@ -53,7 +51,6 @@ const defaultProps = {
};

function MoneyRequestParticipantsPage({iou, selectedTab, route, transaction}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const prevMoneyRequestId = useRef(iou.id);
const iouType = useInitialValue(() => lodashGet(route, 'params.iouType', ''));
Expand Down Expand Up @@ -128,8 +125,8 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route, transaction}) {
shouldEnableMaxHeight={DeviceCapabilities.canUseTouchScreen()}
testID={MoneyRequestParticipantsPage.displayName}
>
{({safeAreaPaddingBottomStyle}) => (
<View style={styles.flex1}>
{({didScreenTransitionEnd}) => (
<>
<HeaderWithBackButton
title={headerTitle}
onBackButtonPress={navigateBack}
Expand All @@ -139,12 +136,12 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route, transaction}) {
onAddParticipants={IOU.setMoneyRequestParticipants}
navigateToRequest={() => navigateToConfirmationStep(iouType)}
navigateToSplit={() => navigateToConfirmationStep(CONST.IOU.TYPE.SPLIT)}
safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle}
iouType={iouType}
isDistanceRequest={isDistanceRequest}
isScanRequest={isScanRequest}
didScreenTransitionEnd={didScreenTransitionEnd}
/>
</View>
</>
)}
</ScreenWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,27 @@ const propTypes = {

/** Whether the money request is a distance request or not */
isDistanceRequest: PropTypes.bool,

/** Whether the screen transition has ended */
didScreenTransitionEnd: PropTypes.bool,
};

const defaultProps = {
participants: [],
betas: [],
isDistanceRequest: false,
didScreenTransitionEnd: false,
};

function MoneyRequestParticipantsSelector({betas, participants, navigateToRequest, navigateToSplit, onAddParticipants, iouType, isDistanceRequest}) {
function MoneyRequestParticipantsSelector({betas, participants, navigateToRequest, navigateToSplit, onAddParticipants, iouType, isDistanceRequest, didScreenTransitionEnd}) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
const referralContentType = iouType === CONST.IOU.TYPE.SEND ? CONST.REFERRAL_PROGRAM.CONTENT_TYPES.SEND_MONEY : CONST.REFERRAL_PROGRAM.CONTENT_TYPES.MONEY_REQUEST;
const {isOffline} = useNetwork();
const personalDetails = usePersonalDetails();
const {canUseP2PDistanceRequests} = usePermissions();
const {options, areOptionsInitialized} = useOptionsList();
const {options, areOptionsInitialized} = useOptionsList({shouldInitialize: didScreenTransitionEnd});

const maxParticipantsReached = participants.length === CONST.REPORT.MAXIMUM_PARTICIPANTS;
const setSearchTermAndSearchInServer = useSearchTermAndSearch(setSearchTerm, maxParticipantsReached);
Expand Down Expand Up @@ -344,7 +348,7 @@ function MoneyRequestParticipantsSelector({betas, participants, navigateToReques
onSelectRow={addSingleParticipant}
footerContent={footerContent}
headerMessage={headerMessage}
showLoadingPlaceholder={!areOptionsInitialized}
showLoadingPlaceholder={!areOptionsInitialized && !didScreenTransitionEnd}
rightHandSideComponent={itemRightSideComponent}
/>
);
Expand Down
5 changes: 3 additions & 2 deletions src/pages/workspace/WorkspaceInvitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ function WorkspaceInvitePage({
invitedEmailsToAccountIDsDraft,
policy,
isLoadingReportData = true,
didScreenTransitionEnd,
}: WorkspaceInvitePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [searchTerm, setSearchTerm] = useState('');
const [selectedOptions, setSelectedOptions] = useState<MemberForList[]>([]);
const [personalDetails, setPersonalDetails] = useState<OptionData[]>([]);
const [usersToInvite, setUsersToInvite] = useState<OptionData[]>([]);
const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false);
const openWorkspaceInvitePage = () => {
const policyMemberEmailsToAccountIDs = PolicyUtils.getMemberAccountIDsForWorkspace(policyMembers, personalDetailsProp);
Policy.openWorkspaceInvitePage(route.params.policyID, Object.keys(policyMemberEmailsToAccountIDs));
Expand Down Expand Up @@ -290,6 +290,7 @@ function WorkspaceInvitePage({
shouldUseCachedViewportHeight
testID={WorkspaceInvitePage.displayName}
includeSafeAreaPaddingBottom={false}
onEntryTransitionEnd={() => setDidScreenTransitionEnd(true)}
>
<FullPageNotFoundView
shouldShow={(isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)}
Expand Down Expand Up @@ -321,7 +322,7 @@ function WorkspaceInvitePage({
onSelectRow={toggleOption}
onConfirm={inviteUser}
showScrollIndicator
showLoadingPlaceholder={!areOptionsInitialized}
showLoadingPlaceholder={!areOptionsInitialized || !didScreenTransitionEnd}
shouldPreventDefaultFocusOnSelectRow={!DeviceCapabilities.canUseTouchScreen()}
footerContent={footerContent}
/>
Expand Down

0 comments on commit 16eccc0

Please sign in to comment.