Skip to content

Commit

Permalink
fix: nav bugs (#2781)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmorizon committed Mar 29, 2023
1 parent 57ed22b commit 3982d7c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
20 changes: 16 additions & 4 deletions packages/kit/src/hooks/useNavigationActions.ts
Expand Up @@ -64,21 +64,29 @@ export function useNavigationActions() {
[dispatch, navigation],
);

const openDrawer = useCallback(() => {
navigation.dispatch(DrawerActions.openDrawer());
}, [navigation]);

const closeDrawer = useCallback(() => {
navigation.dispatch(DrawerActions.closeDrawer());
}, [navigation]);

const closeWalletSelector = useCallback(() => {
if (isVertical) {
navigation.dispatch(DrawerActions.closeDrawer());
closeDrawer();
} else {
dispatch(updateDesktopWalletSelectorVisible(false));
}
}, [dispatch, isVertical, navigation]);
}, [closeDrawer, dispatch, isVertical]);

const openWalletSelector = useCallback(() => {
if (isVertical) {
navigation.dispatch(DrawerActions.openDrawer());
openDrawer();
} else {
dispatch(updateDesktopWalletSelectorVisible(true));
}
}, [dispatch, isVertical, navigation]);
}, [dispatch, isVertical, openDrawer]);

const toggleWalletSelector = useCallback(() => {
setTimeout(() => {
Expand Down Expand Up @@ -189,6 +197,8 @@ export function useNavigationActions() {
openAccountSelector,
openNetworkSelector,
sendToken,
openDrawer,
closeDrawer,
}),
[
openAccountSelector,
Expand All @@ -200,6 +210,8 @@ export function useNavigationActions() {
resetToWelcome,
openRootHome,
sendToken,
openDrawer,
closeDrawer,
],
);
}
Expand Up @@ -9,8 +9,10 @@ export const tabRoutesOrders = [
TabRoutes.NFT,
TabRoutes.Discover,
TabRoutes.Me,
TabRoutes.Developer,
];
if (process.env.NODE_ENV !== 'production') {
tabRoutesOrders.push(TabRoutes.Developer);
}

export const swapAndMarketRoutes = [TabRoutes.Swap, TabRoutes.Market];

Expand Down
10 changes: 5 additions & 5 deletions packages/kit/src/routes/Root/Main/Tab/routes/tabRoutes.tsx
Expand Up @@ -20,17 +20,17 @@ const allRoutes: TabRouteConfig[] = [
];
export const tabRoutes: TabRouteConfig[] = tabRoutesOrders
.map((name) => {
const r = allRoutes.find((item) => item.name === name);
let r = allRoutes.find((item) => item.name === name);
if (!r && name === TabRoutes.Developer) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
r = require('./AppRootTabDeveloper').default;
}
if (r) {
if (r?.hideOnProduction && process.env.NODE_ENV === 'production') {
return undefined;
}
return r;
}
if (name === TabRoutes.Developer) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
return require('./AppRootTabDeveloper').default;
}
return undefined;
})
.filter(Boolean);
9 changes: 9 additions & 0 deletions packages/kit/src/views/Developer/index.tsx
Expand Up @@ -39,6 +39,7 @@ import platformEnv from '@onekeyhq/shared/src/platformEnv';

import walletConnectUtils from '../../components/WalletConnect/utils/walletConnectUtils';
import { WalletConnectDappSideTest } from '../../components/WalletConnect/WalletConnectDappSideTest';
import { useNavigationActions } from '../../hooks';
import useAppNavigation from '../../hooks/useAppNavigation';
import {
GalleryRoutes,
Expand Down Expand Up @@ -71,6 +72,7 @@ export const Debug = () => {
const { width, height } = useWindowDimensions();
const { network, account, wallet } = useActiveWalletAccount();
const { serviceAccount, engine } = backgroundApiProxy;
const navigationActions = useNavigationActions();

const pressableProps = {
p: '4',
Expand Down Expand Up @@ -583,6 +585,13 @@ export const Debug = () => {
>
<Typography.Body1>Batch Transfer DAI</Typography.Body1>
</Pressable>
<Pressable
{...pressableProps}
onPress={() => navigationActions.openDrawer()}
>
<Typography.Body1>Open Drawer</Typography.Body1>
</Pressable>

<Pressable
{...pressableProps}
onPress={async () => {
Expand Down

0 comments on commit 3982d7c

Please sign in to comment.