diff --git a/apps/mobile/src/components/AccountSwitcher/AccountsPanel.tsx b/apps/mobile/src/components/AccountSwitcher/AccountsPanel.tsx index d73b3729c..866db1cb5 100644 --- a/apps/mobile/src/components/AccountSwitcher/AccountsPanel.tsx +++ b/apps/mobile/src/components/AccountSwitcher/AccountsPanel.tsx @@ -4,9 +4,7 @@ import { Dimensions, ScrollView, StyleProp, - StyleSheet, Text, - TouchableOpacity, View, ViewStyle, } from 'react-native'; @@ -20,14 +18,11 @@ import { } from '@/hooks/accountsSwitcher'; import { AccountSwitcherAopProps, useAccountSceneVisible } from './hooks'; import React, { useCallback, useEffect, useMemo } from 'react'; -import { AddressItem } from '@/components2024/AddressItem/AddressItem'; -import { ICONS_COMMON_2024 } from '@/assets2024/icons/common'; -import RcIconCorrectCC from './icons/correct-cc.svg'; import { Account } from '@/core/services/preference'; -import { trigger } from 'react-native-haptic-feedback'; import { LinearGradientContainer } from '@/components2024/ScreenContainer/LinearGradientContainer'; import { AddressItemInPanel, AddressItemSizes } from './AddressItemInPanel'; import { UseAllAccountsItemInPanel } from './AddressItemUseAll'; +import { ScreenWithAccountSwitcherLayouts } from '@/constant/layout'; const SectionCollapsableNav = function ({ isCollapsed = false, @@ -287,7 +282,9 @@ AccountSwitcherAopProps<{ } export function getAccountsPanelInModalMaxHeight() { - return Dimensions.get('window').height - 133; + const winInfo = Dimensions.get('window'); + + return winInfo.height - ScreenWithAccountSwitcherLayouts.modalBottomSpace; } const getPanelStyle = createGetStyles2024(ctx => { return { @@ -295,7 +292,7 @@ const getPanelStyle = createGetStyles2024(ctx => { position: 'relative', width: '100%', minHeight: '50%', - maxHeight: getAccountsPanelInModalMaxHeight(), + height: '100%', flexDirection: 'column', }, scrollViewContainer: { diff --git a/apps/mobile/src/components/AccountSwitcher/Modal.tsx b/apps/mobile/src/components/AccountSwitcher/Modal.tsx index 2ec709534..c0298c6af 100644 --- a/apps/mobile/src/components/AccountSwitcher/Modal.tsx +++ b/apps/mobile/src/components/AccountSwitcher/Modal.tsx @@ -1,4 +1,4 @@ -import { Dimensions, TouchableOpacity, View } from 'react-native'; +import { TouchableOpacity, View } from 'react-native'; import { AccountSwitcherAopProps, useAccountSceneVisible } from './hooks'; import { createGetStyles2024, @@ -16,7 +16,7 @@ import { getAccountsPanelInModalMaxHeight, } from './AccountsPanel'; import AutoLockView from '../AutoLockView'; -import { useLayoutEffect } from 'react'; +import { useCallback, useLayoutEffect } from 'react'; import { useDappCurrentAccount } from '@/hooks/useDapps'; import { DappInfo } from '@/core/services/dappService'; import { IS_ANDROID } from '@/core/native/utils'; @@ -36,7 +36,8 @@ export function AccountSwitcherModal({ const { styles } = useTheme2024({ getStyle: getModalStyle }); const { topValue, offScreen } = useSafeOffTop({ - modalBackgroundHeight: ScreenWithAccountSwitcherLayouts.screenHeaderHeight, + modalBackgroundHeight: + ScreenWithAccountSwitcherLayouts.screenHeaderHeight /* + ScreenWithAccountSwitcherLayouts.modalBottomSpace */, }); useLayoutEffect(() => { @@ -45,6 +46,10 @@ export function AccountSwitcherModal({ }; }, [forScene, toggleSceneVisible]); + const handlePressToClose = useCallback(() => { + toggleSceneVisible(forScene, false); + }, [forScene, toggleSceneVisible]); + if (!isVisible) return null; const absoluteStyle = { @@ -61,9 +66,7 @@ export function AccountSwitcherModal({ absoluteStyle, ]}> { - toggleSceneVisible(forScene, false); - }} + onPressIn={handlePressToClose} style={[styles.bgMask, { height: absoluteStyle.maxHeight }]} delayLongPress={1000} /> @@ -71,7 +74,11 @@ export function AccountSwitcherModal({ style={[styles.panelContainer, { maxHeight: absoluteStyle.maxHeight }]}> @@ -97,10 +104,12 @@ const getModalStyle = createGetStyles2024(ctx => { panelContainer: { position: 'relative', width: '100%', - height: getAccountsPanelInModalMaxHeight(), - // ...makeDevOnlyStyle({ - // backgroundColor: 'blue', - // }), + height: + getAccountsPanelInModalMaxHeight() - + ScreenWithAccountSwitcherLayouts.screenHeaderHeight, + ...makeDevOnlyStyle({ + backgroundColor: 'blue', + }), }, bgMask: { position: 'absolute', @@ -139,6 +148,10 @@ export function AccountSwitcherModalInDappWebView({ const { setDappCurrentAccount } = useDappCurrentAccount(); + const handlePressToClose = useCallback(() => { + toggleSceneVisible(forScene, false); + }, [forScene, toggleSceneVisible]); + if (!isVisible) return null; const absoluteStyle = IS_ANDROID @@ -158,19 +171,16 @@ export function AccountSwitcherModalInDappWebView({ { - toggleSceneVisible(forScene, false); - }} + onPressIn={handlePressToClose} style={[styles.bgMask, { height: absoluteStyle.maxHeight }]} delayLongPress={1000} /> - + { @@ -202,10 +212,12 @@ const getModalInDappWebViewStyle = createGetStyles2024(ctx => { panelContainer: { position: 'relative', width: '100%', - height: getAccountsPanelInModalMaxHeight(), - // ...makeDevOnlyStyle({ - // backgroundColor: 'blue', - // }), + height: + getAccountsPanelInModalMaxHeight() - + ScreenWithAccountSwitcherLayouts.screenHeaderHeight, + ...makeDevOnlyStyle({ + backgroundColor: 'blue', + }), }, bgMask: { position: 'absolute', diff --git a/apps/mobile/src/components/AccountSwitcher/hooks.ts b/apps/mobile/src/components/AccountSwitcher/hooks.ts index f74c26c63..be7447618 100644 --- a/apps/mobile/src/components/AccountSwitcher/hooks.ts +++ b/apps/mobile/src/components/AccountSwitcher/hooks.ts @@ -47,8 +47,9 @@ export function useAccountSceneVisible(forScene?: AccountSwitcherScene) { const [scenes, setScenes] = useAtom(screenHeaderAccountSwitcherAtom); const toggleSceneVisible = useCallback( - (scene: AccountSwitcherScene, nextVisible: boolean) => { + (scene: AccountSwitcherScene, nextVisible?: boolean) => { setScenes(prev => { + nextVisible = nextVisible ?? !!prev[scene]?.collapsed; return { ...prev, [scene]: { diff --git a/apps/mobile/src/components/WebView/DappWebViewControl2/WebViewHeaderRight.tsx b/apps/mobile/src/components/WebView/DappWebViewControl2/WebViewHeaderRight.tsx index ba907e0a0..edc889702 100644 --- a/apps/mobile/src/components/WebView/DappWebViewControl2/WebViewHeaderRight.tsx +++ b/apps/mobile/src/components/WebView/DappWebViewControl2/WebViewHeaderRight.tsx @@ -56,7 +56,7 @@ export function WebViewHeaderRight({ }, ]} onPress={() => { - toggleSceneVisible('@ActiveDappWebViewModal', true); + toggleSceneVisible('@ActiveDappWebViewModal'); }}>