Skip to content

Commit a42a9f3

Browse files
authored
fix: lazy render app lock when the portal is not found (#3340)
* Revert "fix: portal container init (#3335)" This reverts commit 358fb2a. * fix: lazy render app lock when the portal is not found
1 parent e437fb6 commit a42a9f3

File tree

12 files changed

+81
-95
lines changed

12 files changed

+81
-95
lines changed

packages/components/src/Layout/NavigationBar/MobileBottomTabBar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
swapAndMarketRoutes,
2020
} from '@onekeyhq/kit/src/routes/Root/Main/Tab/routes/tabRoutes.base';
2121
import { TabRoutes } from '@onekeyhq/kit/src/routes/routesEnum';
22-
import { PortalContainer } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
22+
import { PortalExit } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
2323
import platformEnv from '@onekeyhq/shared/src/platformEnv';
2424

2525
import Box from '../../Box';
@@ -206,8 +206,8 @@ export default function MobileBottomTabBar({
206206
>
207207
{tabs}
208208
</Box>
209-
<PortalContainer
210-
// testID="Mobile-AppTabBar-PortalContainer"
209+
<PortalExit
210+
// testID="Mobile-AppTabBar-PortalExit"
211211
name={`BottomTab-Overlay-${state.key}`}
212212
/>
213213
</Box>

packages/components/src/OverlayContainer/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { FC } from 'react';
33
import { StyleSheet, View } from 'react-native';
44

55
import { FULLWINDOW_OVERLAY_PORTAL } from '@onekeyhq/kit/src/utils/overlayUtils';
6-
import { PortalRender } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
6+
import { PortalEntry } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
77

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

@@ -20,7 +20,7 @@ const OverlayContainer: FC<{
2020
/>
2121
);
2222
return (
23-
<PortalRender container={FULLWINDOW_OVERLAY_PORTAL}>{content}</PortalRender>
23+
<PortalEntry target={FULLWINDOW_OVERLAY_PORTAL}>{content}</PortalEntry>
2424
);
2525
};
2626
export default OverlayContainer;

packages/components/src/Select/Container/Mobile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Modalize } from 'react-native-modalize';
44

55
import { useSafeAreaInsets, useThemeValue } from '@onekeyhq/components';
66
import { FULLWINDOW_OVERLAY_PORTAL } from '@onekeyhq/kit/src/utils/overlayUtils';
7-
import { PortalRender } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
7+
import { PortalEntry } from '@onekeyhq/kit/src/views/Overlay/RootPortal';
88

99
import Box from '../../Box';
1010
import Button from '../../Button';
@@ -148,7 +148,7 @@ function Mobile<T>({
148148
);
149149

150150
return (
151-
<PortalRender container={FULLWINDOW_OVERLAY_PORTAL}>{content}</PortalRender>
151+
<PortalEntry target={FULLWINDOW_OVERLAY_PORTAL}>{content}</PortalEntry>
152152
);
153153
}
154154

packages/ext/src/ui/uiJsBridge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414

1515
function init() {
1616
const jsBridgeReceiveHandler = (payload: IJsBridgeMessagePayload) => {
17-
// console.log('jsBridgeReceiveHandler Ext-UI', payload);
17+
console.log('jsBridgeReceiveHandler Ext-UI', payload);
1818
const { method, params } = payload.data as IJsonRpcRequest;
1919
if (method === DISPATCH_ACTION_BROADCAST_METHOD_NAME) {
2020
const { actions } = params as IDispatchActionBroadcastParams;

packages/kit/src/components/AppLock/AppLock.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FC } from 'react';
2-
import { useEffect, useMemo } from 'react';
2+
import { Fragment, useEffect, useMemo } from 'react';
33

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

1215
import { AppStateHeartbeat } from './AppStateHeartbeat';
1316
import { AppStateUnlock } from './AppStateUnlock';
@@ -53,12 +56,21 @@ export const AppLockView: FC<AppLockProps> = ({
5356
return <AppStateUnlock />;
5457
}
5558

59+
const Parent =
60+
!isPortalExisted(FULLWINDOW_OVERLAY_PORTAL) &&
61+
showUnlockView &&
62+
renderAsOverlay
63+
? LazyDisplayView
64+
: Fragment;
65+
5666
return (
5767
<Box w="full" h="full" testID="AppLockView">
5868
{showUnlockView && renderAsOverlay ? (
59-
<OverlayContainer>
60-
<AppStateUnlock />
61-
</OverlayContainer>
69+
<Parent>
70+
<OverlayContainer>
71+
<AppStateUnlock />
72+
</OverlayContainer>
73+
</Parent>
6274
) : null}
6375
{prerequisites && isUnlock ? <AppStateUpdater /> : null}
6476
{isUnlock ? <AppStateHeartbeat /> : null}

packages/kit/src/provider/AppLoading.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const AppLoading: FC = ({ children }) => {
9191
}
9292

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

102102
// redux ready check move to ThemeApp
103-
// serviceApp.initApp();
104103

105-
serviceApp.checkLockStatus();
104+
// serviceApp.initApp();
105+
await serviceApp.checkLockStatus();
106106
setInitDataReady(true);
107107

108108
// end splash screen to show AnimatedSplash after 50ms to avoid twinkling

packages/kit/src/provider/NavigationProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import '../routes/deepLink';
2525
import buildLinking from '../routes/linking';
2626
import { createLazyComponent } from '../utils/createLazyComponent';
2727
import { FULLWINDOW_OVERLAY_PORTAL } from '../utils/overlayUtils';
28-
import { PortalContainer } from '../views/Overlay/RootPortal';
28+
import { PortalExit } from '../views/Overlay/RootPortal';
2929

3030
import RedirectProvider from './RedirectProvider';
3131

@@ -133,7 +133,7 @@ const NavigationApp = () => {
133133
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
134134
<ChainWebEmbed />
135135
<CustomToast bottomOffset={60} />
136-
<PortalContainer name={FULLWINDOW_OVERLAY_PORTAL} />
136+
<PortalExit name={FULLWINDOW_OVERLAY_PORTAL} />
137137
</View>
138138
),
139139
[],

packages/kit/src/utils/overlayUtils.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@ import { cloneElement } from 'react';
44
import { throttle } from 'lodash';
55
import { StyleSheet, View } from 'react-native';
66

7-
import { renderToPortal } from '../views/Overlay/RootPortal';
7+
import { enterPortal } from '../views/Overlay/RootPortal';
88

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

1111
export const FULLWINDOW_OVERLAY_PORTAL = 'Root-FullWindowOverlay';
1212

13-
type IOverlayContentRender = (closeOverlay: () => void) => ReactElement;
1413
export const showOverlay = throttle(
15-
(renderOverlay: IOverlayContentRender) => {
14+
(renderOverlay: (closeOverlay: () => void) => ReactElement) => {
1615
let portal: PortalManager | null;
1716
const closeOverlay = () => {
1817
portal?.destroy();
1918
portal = null;
2019
};
20+
const content = (
21+
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
22+
{renderOverlay(closeOverlay)}
23+
</View>
24+
);
2125
setTimeout(() => {
22-
const content = (
23-
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
24-
{renderOverlay(closeOverlay)}
25-
</View>
26-
);
27-
portal = renderToPortal(FULLWINDOW_OVERLAY_PORTAL, content);
26+
portal = enterPortal(FULLWINDOW_OVERLAY_PORTAL, content);
2827
});
2928
return closeOverlay;
3029
},
@@ -36,14 +35,12 @@ export const showOverlay = throttle(
3635
);
3736

3837
export const showDialog = (render: ReactElement) =>
39-
showOverlay(
40-
//
41-
(closeOverlay) =>
42-
cloneElement(render, {
43-
onClose: () => {
44-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
45-
render.props.onClose?.();
46-
closeOverlay();
47-
},
48-
}),
38+
showOverlay((onClose) =>
39+
cloneElement(render, {
40+
onClose: () => {
41+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
42+
render.props.onClose?.();
43+
onClose();
44+
},
45+
}),
4946
);

packages/kit/src/views/Developer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ export const Debug = () => {
825825
});
826826
}}
827827
>
828-
<Typography.Body1>Open Gas Panel000</Typography.Body1>
828+
<Typography.Body1>Open Gas Panel</Typography.Body1>
829829
</Pressable>
830830
<Pressable
831831
{...pressableProps}

packages/kit/src/views/Discover/Explorer/Mobile/ControllerBarMobile.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
} from '../../../../store/observable/webTabs';
3030
import { showOverlay } from '../../../../utils/overlayUtils';
3131
import { OverlayPanel } from '../../../Overlay/OverlayPanel';
32-
import { PortalRender } from '../../../Overlay/RootPortal';
32+
import { PortalEntry } from '../../../Overlay/RootPortal';
3333
import { useWebController } from '../Controller/useWebController';
3434
import {
3535
MAX_OR_SHOW,
@@ -198,7 +198,7 @@ export const ControllerBarMobile: FC = () => {
198198
</Animated.View>
199199
);
200200
return (
201-
<PortalRender container={`BottomTab-Overlay-${TabRoutes.Discover}`}>
201+
<PortalEntry target={`BottomTab-Overlay-${TabRoutes.Discover}`}>
202202
<Animated.View
203203
style={[
204204
StyleSheet.absoluteFill,
@@ -223,6 +223,6 @@ export const ControllerBarMobile: FC = () => {
223223
{tabController}
224224
</Box>
225225
</Animated.View>
226-
</PortalRender>
226+
</PortalEntry>
227227
);
228228
};

0 commit comments

Comments
 (0)