Skip to content

Commit

Permalink
prevent portal overlay on pin authentication screen
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Nov 25, 2024
1 parent 176cac6 commit 11f079f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-cont
import { enableScreens } from 'react-native-screens';
import { connect, Provider as ReduxProvider, shallowEqual } from 'react-redux';
import { RecoilRoot } from 'recoil';
import PortalConsumer from '@/components/PortalConsumer';
import ErrorBoundary from '@/components/error-boundary/ErrorBoundary';
import { OfflineToast } from '@/components/toasts';
import { designSystemPlaygroundEnabled, reactNativeDisableYellowBox, showNetworkRequests, showNetworkResponses } from '@/config/debug';
Expand All @@ -26,7 +25,6 @@ import { MainThemeProvider } from '@/theme/ThemeContext';
import { addressKey } from '@/utils/keychainConstants';
import { SharedValuesProvider } from '@/helpers/SharedValuesContext';
import { InitialRouteContext } from '@/navigation/initialRoute';
import { Portal } from '@/react-native-cool-modals/Portal';
import { NotificationsHandler } from '@/notifications/NotificationsHandler';
import { analyticsV2 } from '@/analytics';
import { getOrCreateDeviceId, securelyHashWalletAddress } from '@/analytics/utils';
Expand Down Expand Up @@ -82,8 +80,6 @@ function App({ walletReady }: AppProps) {
</View>
<NotificationsHandler walletReady={walletReady} />
<DeeplinkHandler initialRoute={initialRoute} walletReady={walletReady} />
<Portal />
<PortalConsumer />
<BackupsSync />
</>
);
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/useActiveRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Navigation, useNavigation } from '@/navigation';
import { useEffect, useState } from 'react';

export const useActiveRoute = () => {
const { addListener } = useNavigation();
const [activeRoute, setActiveRoute] = useState(Navigation.getActiveRoute());

useEffect(() => {
const unsubscribe = addListener('state', () => {
setActiveRoute(Navigation.getActiveRoute());
});
return unsubscribe;
}, [addListener]);

return activeRoute?.name;
};
6 changes: 6 additions & 0 deletions src/navigation/Routes.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ import { ControlPanel } from '@/components/DappBrowser/control-panel/ControlPane
import { ClaimRewardsPanel } from '@/screens/points/claim-flow/ClaimRewardsPanel';
import { ClaimClaimablePanel } from '@/screens/claimables/ClaimClaimablePanel';
import { RootStackParamList } from './types';
import PortalConsumer from '@/components/PortalConsumer';
import { Portal as CMPortal } from '@/react-native-cool-modals/Portal';

const Stack = createStackNavigator();
const OuterStack = createStackNavigator();
Expand Down Expand Up @@ -272,6 +274,10 @@ const AppContainerWithAnalytics = React.forwardRef<NavigationContainerRef<RootSt
<PointsProfileProvider>
<AuthNavigator />
</PointsProfileProvider>

{/* NOTE: Internally, these use some navigational checks */}
<CMPortal />
<PortalConsumer />
</NavigationContainer>
));

Expand Down
6 changes: 6 additions & 0 deletions src/navigation/Routes.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ import { ControlPanel } from '@/components/DappBrowser/control-panel/ControlPane
import { ClaimRewardsPanel } from '@/screens/points/claim-flow/ClaimRewardsPanel';
import { ClaimClaimablePanel } from '@/screens/claimables/ClaimClaimablePanel';
import { RootStackParamList } from './types';
import PortalConsumer from '@/components/PortalConsumer';
import { Portal as CMPortal } from '@/react-native-cool-modals/Portal';

const Stack = createStackNavigator();
const NativeStack = createNativeStackNavigator();
Expand Down Expand Up @@ -286,6 +288,10 @@ const AppContainerWithAnalytics = React.forwardRef<NavigationContainerRef<RootSt
<PointsProfileProvider>
<NativeStackNavigator />
</PointsProfileProvider>

{/* NOTE: Internally, these use some navigational checks */}
<CMPortal />
<PortalConsumer />
</NavigationContainer>
));

Expand Down
11 changes: 8 additions & 3 deletions src/react-native-cool-modals/Portal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import React from 'react';
import { IS_IOS } from '@/env';
import React, { useEffect, useState } from 'react';
import { IS_ANDROID, IS_IOS } from '@/env';
import { portalStore } from '@/state/portal/portal';
import { requireNativeComponent, StyleSheet, View } from 'react-native';
import Routes from '@/navigation/routesNames';
import { Navigation, useNavigation } from '@/navigation';
import { useActiveRoute } from '@/hooks/useActiveRoute';

const NativePortal = IS_IOS ? requireNativeComponent('WindowPortal') : View;
const Wrapper = IS_IOS ? ({ children }: { children: React.ReactNode }) => children : View;

export function Portal() {
const activeRoute = useActiveRoute();

const { blockTouches, Component } = portalStore(state => ({
blockTouches: state.blockTouches,
Component: state.Component,
}));

if (!Component) {
if (!Component || (activeRoute === Routes.PIN_AUTHENTICATION_SCREEN && !IS_IOS)) {
return null;
}

Expand Down

0 comments on commit 11f079f

Please sign in to comment.