Skip to content

Commit

Permalink
fix: lazy render app lock when the portal is not found (#3340)
Browse files Browse the repository at this point in the history
* Revert "fix: portal container init (#3335)"

This reverts commit 358fb2a.

* fix: lazy render app lock when the portal is not found
  • Loading branch information
kwoktung authored Aug 2, 2023
1 parent e437fb6 commit a42a9f3
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
swapAndMarketRoutes,
} from '@onekeyhq/kit/src/routes/Root/Main/Tab/routes/tabRoutes.base';
import { TabRoutes } from '@onekeyhq/kit/src/routes/routesEnum';
import { PortalContainer } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
import { PortalExit } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
import platformEnv from '@onekeyhq/shared/src/platformEnv';

import Box from '../../Box';
Expand Down Expand Up @@ -206,8 +206,8 @@ export default function MobileBottomTabBar({
>
{tabs}
</Box>
<PortalContainer
// testID="Mobile-AppTabBar-PortalContainer"
<PortalExit
// testID="Mobile-AppTabBar-PortalExit"
name={`BottomTab-Overlay-${state.key}`}
/>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/OverlayContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { FC } from 'react';
import { StyleSheet, View } from 'react-native';

import { FULLWINDOW_OVERLAY_PORTAL } from '@onekeyhq/kit/src/utils/overlayUtils';
import { PortalRender } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
import { PortalEntry } from '@onekeyhq/kit/src/views/Overlay/RootPortal';

import type { StyleProp, ViewStyle } from 'react-native';

Expand All @@ -20,7 +20,7 @@ const OverlayContainer: FC<{
/>
);
return (
<PortalRender container={FULLWINDOW_OVERLAY_PORTAL}>{content}</PortalRender>
<PortalEntry target={FULLWINDOW_OVERLAY_PORTAL}>{content}</PortalEntry>
);
};
export default OverlayContainer;
4 changes: 2 additions & 2 deletions packages/components/src/Select/Container/Mobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Modalize } from 'react-native-modalize';

import { useSafeAreaInsets, useThemeValue } from '@onekeyhq/components';
import { FULLWINDOW_OVERLAY_PORTAL } from '@onekeyhq/kit/src/utils/overlayUtils';
import { PortalRender } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
import { PortalEntry } from '@onekeyhq/kit/src/views/Overlay/RootPortal';

import Box from '../../Box';
import Button from '../../Button';
Expand Down Expand Up @@ -148,7 +148,7 @@ function Mobile<T>({
);

return (
<PortalRender container={FULLWINDOW_OVERLAY_PORTAL}>{content}</PortalRender>
<PortalEntry target={FULLWINDOW_OVERLAY_PORTAL}>{content}</PortalEntry>
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ext/src/ui/uiJsBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {

function init() {
const jsBridgeReceiveHandler = (payload: IJsBridgeMessagePayload) => {
// console.log('jsBridgeReceiveHandler Ext-UI', payload);
console.log('jsBridgeReceiveHandler Ext-UI', payload);
const { method, params } = payload.data as IJsonRpcRequest;
if (method === DISPATCH_ACTION_BROADCAST_METHOD_NAME) {
const { actions } = params as IDispatchActionBroadcastParams;
Expand Down
20 changes: 16 additions & 4 deletions packages/kit/src/components/AppLock/AppLock.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FC } from 'react';
import { useEffect, useMemo } from 'react';
import { Fragment, useEffect, useMemo } from 'react';

import { Box, OverlayContainer } from '@onekeyhq/components';
import platformEnv from '@onekeyhq/shared/src/platformEnv';
Expand All @@ -8,6 +8,9 @@ import backgroundApiProxy from '../../background/instance/backgroundApiProxy';
import { useAppSelector, useDebounce } from '../../hooks';
import { unlockWhiteListUrls } from '../../routes/linking.path';
import { setAppRenderReady } from '../../store/reducers/data';
import { FULLWINDOW_OVERLAY_PORTAL } from '../../utils/overlayUtils';
import { isPortalExisted } from '../../views/Overlay/RootPortal';
import { LazyDisplayView } from '../LazyDisplayView';

import { AppStateHeartbeat } from './AppStateHeartbeat';
import { AppStateUnlock } from './AppStateUnlock';
Expand Down Expand Up @@ -53,12 +56,21 @@ export const AppLockView: FC<AppLockProps> = ({
return <AppStateUnlock />;
}

const Parent =
!isPortalExisted(FULLWINDOW_OVERLAY_PORTAL) &&
showUnlockView &&
renderAsOverlay
? LazyDisplayView
: Fragment;

return (
<Box w="full" h="full" testID="AppLockView">
{showUnlockView && renderAsOverlay ? (
<OverlayContainer>
<AppStateUnlock />
</OverlayContainer>
<Parent>
<OverlayContainer>
<AppStateUnlock />
</OverlayContainer>
</Parent>
) : null}
{prerequisites && isUnlock ? <AppStateUpdater /> : null}
{isUnlock ? <AppStateHeartbeat /> : null}
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/provider/AppLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const AppLoading: FC = ({ children }) => {
}

useEffect(() => {
function main() {
async function main() {
// TODO initApp too slow, maybe do not need waiting for initApp in UI
// await Promise.all([
// serviceApp.waitForAppInited({
Expand All @@ -100,9 +100,9 @@ const AppLoading: FC = ({ children }) => {
// ]);

// redux ready check move to ThemeApp
// serviceApp.initApp();

serviceApp.checkLockStatus();
// serviceApp.initApp();
await serviceApp.checkLockStatus();
setInitDataReady(true);

// end splash screen to show AnimatedSplash after 50ms to avoid twinkling
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/provider/NavigationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import '../routes/deepLink';
import buildLinking from '../routes/linking';
import { createLazyComponent } from '../utils/createLazyComponent';
import { FULLWINDOW_OVERLAY_PORTAL } from '../utils/overlayUtils';
import { PortalContainer } from '../views/Overlay/RootPortal';
import { PortalExit } from '../views/Overlay/RootPortal';

import RedirectProvider from './RedirectProvider';

Expand Down Expand Up @@ -133,7 +133,7 @@ const NavigationApp = () => {
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
<ChainWebEmbed />
<CustomToast bottomOffset={60} />
<PortalContainer name={FULLWINDOW_OVERLAY_PORTAL} />
<PortalExit name={FULLWINDOW_OVERLAY_PORTAL} />
</View>
),
[],
Expand Down
35 changes: 16 additions & 19 deletions packages/kit/src/utils/overlayUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ import { cloneElement } from 'react';
import { throttle } from 'lodash';
import { StyleSheet, View } from 'react-native';

import { renderToPortal } from '../views/Overlay/RootPortal';
import { enterPortal } from '../views/Overlay/RootPortal';

import type { PortalManager } from '../views/Overlay/RootPortal';

export const FULLWINDOW_OVERLAY_PORTAL = 'Root-FullWindowOverlay';

type IOverlayContentRender = (closeOverlay: () => void) => ReactElement;
export const showOverlay = throttle(
(renderOverlay: IOverlayContentRender) => {
(renderOverlay: (closeOverlay: () => void) => ReactElement) => {
let portal: PortalManager | null;
const closeOverlay = () => {
portal?.destroy();
portal = null;
};
const content = (
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
{renderOverlay(closeOverlay)}
</View>
);
setTimeout(() => {
const content = (
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
{renderOverlay(closeOverlay)}
</View>
);
portal = renderToPortal(FULLWINDOW_OVERLAY_PORTAL, content);
portal = enterPortal(FULLWINDOW_OVERLAY_PORTAL, content);
});
return closeOverlay;
},
Expand All @@ -36,14 +35,12 @@ export const showOverlay = throttle(
);

export const showDialog = (render: ReactElement) =>
showOverlay(
//
(closeOverlay) =>
cloneElement(render, {
onClose: () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
render.props.onClose?.();
closeOverlay();
},
}),
showOverlay((onClose) =>
cloneElement(render, {
onClose: () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
render.props.onClose?.();
onClose();
},
}),
);
2 changes: 1 addition & 1 deletion packages/kit/src/views/Developer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ export const Debug = () => {
});
}}
>
<Typography.Body1>Open Gas Panel000</Typography.Body1>
<Typography.Body1>Open Gas Panel</Typography.Body1>
</Pressable>
<Pressable
{...pressableProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from '../../../../store/observable/webTabs';
import { showOverlay } from '../../../../utils/overlayUtils';
import { OverlayPanel } from '../../../Overlay/OverlayPanel';
import { PortalRender } from '../../../Overlay/RootPortal';
import { PortalEntry } from '../../../Overlay/RootPortal';
import { useWebController } from '../Controller/useWebController';
import {
MAX_OR_SHOW,
Expand Down Expand Up @@ -198,7 +198,7 @@ export const ControllerBarMobile: FC = () => {
</Animated.View>
);
return (
<PortalRender container={`BottomTab-Overlay-${TabRoutes.Discover}`}>
<PortalEntry target={`BottomTab-Overlay-${TabRoutes.Discover}`}>
<Animated.View
style={[
StyleSheet.absoluteFill,
Expand All @@ -223,6 +223,6 @@ export const ControllerBarMobile: FC = () => {
{tabController}
</Box>
</Animated.View>
</PortalRender>
</PortalEntry>
);
};
11 changes: 4 additions & 7 deletions packages/kit/src/views/Market/ScreenMarketOrSwap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import platformEnv from '@onekeyhq/shared/src/platformEnv';

import { TabRoutes } from '../../routes/routesEnum';
import { PortalContainer, PortalRender } from '../Overlay/RootPortal';
import { PortalEntry, PortalExit } from '../Overlay/RootPortal';
import Swap from '../Swap';

import MarketHeader from './Components/MarketList/MarketTopHeader';
Expand All @@ -32,9 +32,9 @@ export function ScreenMarketOrSwap({
useCallback(() => {
if (isNativeSmall) {
sharedMobileTabRef.update(
<PortalRender container={`${routeName}-portal`}>
<PortalEntry target={`${routeName}-portal`}>
<SharedMobileTab routeName={routeName} />
</PortalRender>,
</PortalEntry>,
);
}
}, [routeName, isNativeSmall]),
Expand All @@ -43,10 +43,7 @@ export function ScreenMarketOrSwap({
return (
<Box flex={1} mt={`${top}px`}>
{isNativeSmall ? (
<PortalContainer
key={`${routeName}-portal`}
name={`${routeName}-portal`}
/>
<PortalExit key={`${routeName}-portal`} name={`${routeName}-portal`} />
) : (
<>
<MarketHeader marketTopTabName={routeName} />
Expand Down
Loading

0 comments on commit a42a9f3

Please sign in to comment.