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
4 changes: 2 additions & 2 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import type {MoneyRequestHeaderStatusBarProps} from './MoneyRequestHeaderStatusB
import MoneyRequestHeaderStatusBar from './MoneyRequestHeaderStatusBar';
import MoneyRequestReportTransactionsNavigation from './MoneyRequestReportView/MoneyRequestReportTransactionsNavigation';
import {useSearchContext} from './Search/SearchContext';
import {WideRHPContext} from './WideRHPContextProvider';
import {useWideRHPState} from './WideRHPContextProvider';

type MoneyRequestHeaderProps = {
/** The report currently being looked at */
Expand Down Expand Up @@ -171,7 +171,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
// If the parent report is a selfDM, it should always be opened in the Inbox tab
const shouldOpenParentReportInCurrentTab = !isSelfDM(parentReport);

const {wideRHPRouteKeys} = useContext(WideRHPContext);
const {wideRHPRouteKeys} = useWideRHPState();
const [network] = useOnyx(ONYXKEYS.NETWORK, {canBeMissing: true});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {canBeMissing: true, selector: hasSeenTourSelector});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useFocusEffect} from '@react-navigation/native';
import isEmpty from 'lodash/isEmpty';
import React, {memo, useCallback, useContext, useEffect, useMemo, useState} from 'react';
import React, {memo, useCallback, useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import type {TupleToUnion} from 'type-fest';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
Expand All @@ -11,7 +11,7 @@
import {useSearchContext} from '@components/Search/SearchContext';
import type {SortOrder} from '@components/Search/types';
import Text from '@components/Text';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import {useWideRHPActions} from '@components/WideRHPContextProvider';
import useCopySelectionHelper from '@hooks/useCopySelectionHelper';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useHandleSelectionMode from '@hooks/useHandleSelectionMode';
Expand Down Expand Up @@ -171,7 +171,7 @@
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth, isMediumScreenWidth} = useResponsiveLayout();
const {shouldUseNarrowLayout} = useResponsiveLayoutOnWideRHP();
const {markReportIDAsExpense} = useContext(WideRHPContext);
const {markReportIDAsExpense} = useWideRHPActions();
const [isModalVisible, setIsModalVisible] = useState(false);
const [selectedTransactionID, setSelectedTransactionID] = useState<string>('');
const {reportPendingAction} = getReportOfflinePendingActionAndErrors(report);
Expand All @@ -191,7 +191,7 @@

const addExpenseDropdownOptions = useMemo(
() => getAddExpenseDropdownOptions(expensifyIcons, report?.reportID, policy, undefined, undefined, lastDistanceExpenseType),
[report?.reportID, policy, lastDistanceExpenseType, expensifyIcons.Location],

Check warning on line 194 in src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has a missing dependency: 'expensifyIcons'. Either include it or remove the dependency array

Check warning on line 194 in src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has a missing dependency: 'expensifyIcons'. Either include it or remove the dependency array
);

const hasPendingAction = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {findFocusedRoute} from '@react-navigation/native';
import React, {useCallback, useContext, useEffect, useMemo} from 'react';
import React, {useCallback, useEffect, useMemo} from 'react';
import type {GestureResponderEvent} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import PrevNextButtons from '@components/PrevNextButtons';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import {useWideRHPActions} from '@components/WideRHPContextProvider';
import useOnyx from '@hooks/useOnyx';
import {createTransactionThreadReport, setOptimisticTransactionThread} from '@libs/actions/Report';
import {clearActiveTransactionIDs} from '@libs/actions/TransactionThreadNavigation';
Expand Down Expand Up @@ -38,7 +38,7 @@ function MoneyRequestReportTransactionsNavigation({currentTransactionID, isFromR
canBeMissing: true,
});

const {markReportIDAsExpense} = useContext(WideRHPContext);
const {markReportIDAsExpense} = useWideRHPActions();

const {prevTransactionID, nextTransactionID} = useMemo(() => {
if (!transactionIDsList || transactionIDsList.length < 2) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Navigation/TopBar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, {useContext} from 'react';
import React from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import LoadingBar from '@components/LoadingBar';
import {PressableWithoutFeedback} from '@components/Pressable';
import SearchButton from '@components/Search/SearchRouter/SearchButton';
import SidePanelButton from '@components/SidePanel/SidePanelButton';
import Text from '@components/Text';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import {useWideRHPState} from '@components/WideRHPContextProvider';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -34,7 +34,7 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB
const shouldShowLoadingBarForReports = useLoadingBarVisibility();
const isAnonymousUser = isAnonymousUserUtil(session);

const {wideRHPRouteKeys} = useContext(WideRHPContext);
const {wideRHPRouteKeys} = useWideRHPState();
const isWideRHPVisible = !!wideRHPRouteKeys.length;

const displaySignIn = isAnonymousUser;
Expand Down
6 changes: 3 additions & 3 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Str} from 'expensify-common';
import React, {useCallback, useContext, useEffect, useMemo, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
Expand All @@ -13,7 +13,7 @@ import {useSearchContext} from '@components/Search/SearchContext';
import Switch from '@components/Switch';
import Text from '@components/Text';
import ViolationMessages from '@components/ViolationMessages';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import {useWideRHPState} from '@components/WideRHPContextProvider';
import useActiveRoute from '@hooks/useActiveRoute';
import useCurrencyList from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
Expand Down Expand Up @@ -801,7 +801,7 @@ function MoneyRequestView({
// In this case we want to use this value. The shouldUseNarrowLayout will always be true as this case is handled when we display ReportScreen in RHP.
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();
const {wideRHPRouteKeys} = useContext(WideRHPContext);
const {wideRHPRouteKeys} = useWideRHPState();

// If the view is readonly, we don't need the transactionThread dependency
if ((!readonly && !transactionThreadReport?.reportID) || !transaction?.transactionID) {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {findFocusedRoute, useFocusEffect, useIsFocused, useNavigation} from '@react-navigation/native';
import * as Sentry from '@sentry/react-native';
import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {NativeScrollEvent, NativeSyntheticEvent, StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
Expand All @@ -11,7 +11,7 @@ import {ModalActions} from '@components/Modal/Global/ModalContext';
import SearchTableHeader from '@components/SelectionListWithSections/SearchTableHeader';
import type {ReportActionListItemType, SearchListItem, SelectionListHandle, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionListWithSections/types';
import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import {useWideRHPActions} from '@components/WideRHPContextProvider';
import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet';
import useCardFeedsForDisplay from '@hooks/useCardFeedsForDisplay';
import useConfirmModal from '@hooks/useConfirmModal';
Expand Down Expand Up @@ -222,7 +222,7 @@ function Search({
const {isSmallScreenWidth, isLargeScreenWidth} = useResponsiveLayout();
const navigation = useNavigation<PlatformStackNavigationProp<SearchFullscreenNavigatorParamList>>();
const isFocused = useIsFocused();
const {markReportIDAsExpense} = useContext(WideRHPContext);
const {markReportIDAsExpense} = useWideRHPActions();
const {
currentSearchHash,
setCurrentSearchHashAndKey,
Expand Down Expand Up @@ -254,7 +254,7 @@ function Search({
const [customCardNames] = useOnyx(ONYXKEYS.NVP_EXPENSIFY_COMPANY_CARDS_CUSTOM_NAMES, {canBeMissing: true});

const isExpenseReportType = type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT;
const {markReportIDAsMultiTransactionExpense, unmarkReportIDAsMultiTransactionExpense} = useContext(WideRHPContext);
const {markReportIDAsMultiTransactionExpense, unmarkReportIDAsMultiTransactionExpense} = useWideRHPActions();

const archivedReportsIdSet = useArchivedReportsIdSet();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useContext} from 'react';
import React from 'react';
import {View} from 'react-native';
import ActivityIndicator from '@components/ActivityIndicator';
import Button from '@components/Button';
Expand All @@ -9,7 +9,7 @@ import SearchTableHeader from '@components/SelectionListWithSections/SearchTable
import type {ListItem, TransactionGroupListExpandedProps, TransactionListItemType} from '@components/SelectionListWithSections/types';
import Text from '@components/Text';
import TransactionItemRow from '@components/TransactionItemRow';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import {useWideRHPActions} from '@components/WideRHPContextProvider';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -87,7 +87,7 @@ function TransactionGroupListExpanded<TItem extends ListItem>({
const taxAmountColumnSize = isTaxAmountColumnWide ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL;
const dateColumnSize = shouldShowYearForSomeTransaction ? CONST.SEARCH.TABLE_COLUMN_SIZES.WIDE : CONST.SEARCH.TABLE_COLUMN_SIZES.NORMAL;

const {markReportIDAsExpense} = useContext(WideRHPContext);
const {markReportIDAsExpense} = useWideRHPActions();
const openReportInRHP = (transactionItem: TransactionListItemType) => {
const backTo = Navigation.getActiveRoute();
const reportID = getReportIDForTransaction(transactionItem, transactionItem?.reportAction?.childReportID);
Expand Down
6 changes: 3 additions & 3 deletions src/components/SidePanel/SidePanelModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {isRHPVisibleSelector} from '@selectors/Modal';
import React, {useContext, useEffect} from 'react';
import React, {useEffect} from 'react';
// eslint-disable-next-line no-restricted-imports
import {Animated, View} from 'react-native';
// @ts-expect-error This is a workaround to display SidePanel on top of everything,
Expand All @@ -8,7 +8,7 @@ import ModalPortal from 'react-native-web/dist/exports/Modal/ModalPortal';
import ColorSchemeWrapper from '@components/ColorSchemeWrapper';
import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal';
import SidePanelOverlay from '@components/SidePanel/SidePanelOverlay';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import {useWideRHPState} from '@components/WideRHPContextProvider';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useOnyx from '@hooks/useOnyx';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand All @@ -27,7 +27,7 @@ function SidePanelModal({children, sidePanelTranslateX, closeSidePanel, shouldHi
const [isRHPVisible = false] = useOnyx(ONYXKEYS.MODAL, {selector: isRHPVisibleSelector, canBeMissing: true});
const uniqueModalId = ComposerFocusManager.getId();

const {wideRHPRouteKeys, isWideRHPFocused, superWideRHPRouteKeys, isSuperWideRHPFocused} = useContext(WideRHPContext);
const {wideRHPRouteKeys, isWideRHPFocused, superWideRHPRouteKeys, isSuperWideRHPFocused} = useWideRHPState();

const shouldOverlayBeVisible = (!!wideRHPRouteKeys.length && isWideRHPFocused) || (!!superWideRHPRouteKeys.length && isSuperWideRHPFocused) || !isRHPVisible;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {useFocusEffect} from '@react-navigation/native';
import type {ForwardedRef} from 'react';
import React, {useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import type {StyleProp, ViewStyle} from 'react-native';
import Button from '@components/Button';
Expand All @@ -12,7 +12,7 @@ import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Text from '@components/Text';
import ValidateCodeCountdown from '@components/ValidateCodeCountdown';
import type {ValidateCodeCountdownHandle} from '@components/ValidateCodeCountdown/types';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import {useWideRHPState} from '@components/WideRHPContextProvider';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -114,7 +114,7 @@ function BaseValidateCodeForm({
}: ValidateCodeFormProps) {
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const {wideRHPRouteKeys} = useContext(WideRHPContext);
const {wideRHPRouteKeys} = useWideRHPState();
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down
21 changes: 12 additions & 9 deletions src/components/WideRHPContextProvider/default.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import type {WideRHPContextType} from './types';
import type {WideRHPActionsContextType, WideRHPStateContextType} from './types';

const defaultWideRHPContextValue: WideRHPContextType = {
const defaultWideRHPStateContextValue: WideRHPStateContextType = {
wideRHPRouteKeys: [],
superWideRHPRouteKeys: [],
shouldRenderSecondaryOverlayForWideRHP: false,
shouldRenderSecondaryOverlayForRHPOnWideRHP: false,
shouldRenderSecondaryOverlayForRHPOnSuperWideRHP: false,
shouldRenderTertiaryOverlay: false,
isWideRHPFocused: false,
isSuperWideRHPFocused: false,
};

const defaultWideRHPActionsContextValue: WideRHPActionsContextType = {
showWideRHPVersion: () => {},
showSuperWideRHPVersion: () => {},
removeWideRHPRouteKey: () => {},
removeSuperWideRHPRouteKey: () => {},
markReportIDAsExpense: () => {},
markReportIDAsMultiTransactionExpense: () => {},
unmarkReportIDAsMultiTransactionExpense: () => {},
isReportIDMarkedAsExpense: () => false,
isReportIDMarkedAsMultiTransactionExpense: () => false,
isWideRHPFocused: false,
isSuperWideRHPFocused: false,
shouldRenderTertiaryOverlay: false,
superWideRHPRouteKeys: [],
showSuperWideRHPVersion: () => {},
removeSuperWideRHPRouteKey: () => {},
syncRHPKeys: () => {},
clearWideRHPKeys: () => {},
setIsWideRHPClosing: () => {},
setIsSuperWideRHPClosing: () => {},
};

export default defaultWideRHPContextValue;
export {defaultWideRHPStateContextValue, defaultWideRHPActionsContextValue};
30 changes: 23 additions & 7 deletions src/components/WideRHPContextProvider/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, {createContext} from 'react';
import React, {createContext, useContext} from 'react';
// We use Animated for all functionality related to wide RHP to make it easier
// to interact with react-navigation components (e.g., CardContainer, interpolator), which also use Animated.
// eslint-disable-next-line no-restricted-imports
import {Animated} from 'react-native';
import defaultWideRHPContextValue from './default';
import type {WideRHPContextType} from './types';
import {defaultWideRHPActionsContextValue, defaultWideRHPStateContextValue} from './default';
import type {WideRHPActionsContextType, WideRHPStateContextType} from './types';

const secondOverlayWideRHPProgress = new Animated.Value(0);
const secondOverlayRHPOnWideRHPProgress = new Animated.Value(0);
Expand All @@ -20,10 +20,23 @@ const modalStackOverlayWideRHPPositionLeft = new Animated.Value(0);

const expandedRHPProgress = new Animated.Value(0);

const WideRHPContext = createContext<WideRHPContextType>(defaultWideRHPContextValue);
const WideRHPStateContext = createContext<WideRHPStateContextType>(defaultWideRHPStateContextValue);
const WideRHPActionsContext = createContext<WideRHPActionsContextType>(defaultWideRHPActionsContextValue);

function WideRHPContextProvider({children}: React.PropsWithChildren) {
return <WideRHPContext.Provider value={defaultWideRHPContextValue}>{children}</WideRHPContext.Provider>;
return (
<WideRHPStateContext.Provider value={defaultWideRHPStateContextValue}>
<WideRHPActionsContext.Provider value={defaultWideRHPActionsContextValue}>{children}</WideRHPActionsContext.Provider>
</WideRHPStateContext.Provider>
);
}

function useWideRHPState() {
return useContext(WideRHPStateContext);
}

function useWideRHPActions() {
return useContext(WideRHPActionsContext);
}

export default WideRHPContextProvider;
Expand All @@ -38,6 +51,9 @@ export {
secondOverlayRHPOnWideRHPProgress,
secondOverlayWideRHPProgress,
thirdOverlayProgress,
WideRHPContext,
WideRHPStateContext,
WideRHPActionsContext,
useWideRHPState,
useWideRHPActions,
};
export type {WideRHPContextType};
export type {WideRHPStateContextType, WideRHPActionsContextType};
Loading
Loading