Skip to content

Commit

Permalink
Get state from useRootNavigationState
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Mar 7, 2025
1 parent e97ff0f commit a4aea2b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/Navigation/TopLevelBottomTabBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function TopLevelBottomTabBar({state}: TopLevelBottomTabBarProps) {
isTooltipAllowed={isReadyToDisplayBottomBar}
/>
</View>
<SidePane state={state} />
<SidePane />
</>
);
}
Expand Down
24 changes: 9 additions & 15 deletions src/components/SidePane/index.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,41 @@
import type {ParamListBase} from '@react-navigation/native';
import {findFocusedRoute} from '@react-navigation/native';
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
import React, {useCallback, useEffect, useRef} from 'react';
// eslint-disable-next-line no-restricted-imports
import {Animated, View} from 'react-native';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import useEnvironment from '@hooks/useEnvironment';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useRootNavigationState from '@hooks/useRootNavigationState';
import useSidePane from '@hooks/useSidePane';
import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets';
import useThemeStyles from '@hooks/useThemeStyles';
import {triggerSidePane} from '@libs/actions/SidePane';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackNavigationState} from '@libs/Navigation/PlatformStackNavigation/types';
import {substituteRouteParameters} from '@libs/SidePaneUtils';
import CONST from '@src/CONST';
import NAVIGATORS from '@src/NAVIGATORS';
import getHelpContent from './getHelpContent';
import SidePaneOverlay from './SidePaneOverlay';

type SidePaneProps = {
state: PlatformStackNavigationState<ParamListBase>;
};

function SidePane({state}: SidePaneProps) {
function SidePane() {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isProduction} = useEnvironment();

const {isExtraLargeScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const {sidePaneTranslateX, shouldHideSidePane, shouldHideSidePaneBackdrop} = useSidePane();
const {paddingTop} = useStyledSafeAreaInsets();

const {route, isInNarrowPaneModal} = useMemo(() => {
const {route, isInNarrowPaneModal} = useRootNavigationState((state) => {
const params = (findFocusedRoute(state)?.params as Record<string, string>) ?? {};
const activeRoute = Navigation.getActiveRouteWithoutParams();

return {
route: substituteRouteParameters(activeRoute, params),
isInNarrowPaneModal: state?.routes?.some((r) => r.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR),
};
}, [state]);
});

const {isExtraLargeScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
const {sidePaneTranslateX, shouldHideSidePane, shouldHideSidePaneBackdrop} = useSidePane();
const {paddingTop} = useStyledSafeAreaInsets();

const onClose = useCallback(
(shouldUpdateNarrow = false) => {
Expand Down

0 comments on commit a4aea2b

Please sign in to comment.