Skip to content

Commit 407aed2

Browse files
authored
Dapp browser: disable tab closing for empty state (#5573)
* fix * vars * remove early returns from gesture handler
1 parent fb3d0eb commit 407aed2

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/components/DappBrowser/BrowserTab.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export const BrowserTab = React.memo(function BrowserTab({ tabId, tabIndex, inje
225225
const isActiveTab = activeTabIndex === tabIndex;
226226
const multipleTabsOpen = tabStates?.length > 1;
227227
const isOnHomepage = tabUrl === RAINBOW_HOME;
228+
const isEmptyState = !multipleTabsOpen && isOnHomepage;
228229
const isLogoUnset = tabStates[tabIndex]?.logoUrl === undefined;
229230

230231
const screenshotData = useSharedValue<ScreenshotType | undefined>(findTabScreenshot(tabId, tabUrl) || undefined);
@@ -624,12 +625,15 @@ export const BrowserTab = React.memo(function BrowserTab({ tabId, tabIndex, inje
624625
gestureX.value = xDelta;
625626
},
626627
onEnd: (e, ctx: { startX?: number }) => {
627-
if (!tabViewVisible?.value) return;
628-
629628
const xDelta = e.absoluteX - (ctx.startX || 0);
630629
setNativeProps(scrollViewRef, { scrollEnabled: !!tabViewVisible?.value });
631630

632-
if ((xDelta < -(TAB_VIEW_COLUMN_WIDTH / 2 + 20) && e.velocityX <= 0) || e.velocityX < -500) {
631+
const isBeyondDismissThreshold = xDelta < -(TAB_VIEW_COLUMN_WIDTH / 2 + 20) && e.velocityX <= 0;
632+
const isFastLeftwardSwipe = e.velocityX < -500;
633+
634+
const shouldDismiss = !!tabViewVisible?.value && !isEmptyState && (isBeyondDismissThreshold || isFastLeftwardSwipe);
635+
636+
if (shouldDismiss) {
633637
const xDestination = -Math.min(Math.max(deviceWidth * 1.25, Math.abs(e.velocityX * 0.3)), 1000);
634638
gestureX.value = withTiming(xDestination, TIMING_CONFIGS.tabPressConfig, () => {
635639
runOnJS(closeTab)(tabId);

src/components/DappBrowser/CloseTabButton.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Box, Cover, TextIcon, useColorMode } from '@/design-system';
55
import { IS_IOS } from '@/env';
66
import { deviceUtils } from '@/utils';
77
import { AnimatedBlurView } from '@/__swaps__/screens/Swap/components/AnimatedBlurView';
8-
import { useBrowserContext } from './BrowserContext';
8+
import { RAINBOW_HOME, useBrowserContext } from './BrowserContext';
99
import { TAB_VIEW_COLUMN_WIDTH } from './Dimensions';
1010
import { TIMING_CONFIGS } from '../animations/animationConfigs';
1111

@@ -28,7 +28,10 @@ export const CloseTabButton = ({ onPress, tabIndex }: { onPress: () => void; tab
2828
const { animatedActiveTabIndex, tabStates, tabViewProgress, tabViewVisible } = useBrowserContext();
2929
const { isDarkMode } = useColorMode();
3030

31-
const multipleTabsOpen = React.useMemo(() => tabStates.length > 1, [tabStates.length]);
31+
const multipleTabsOpen = tabStates.length > 1;
32+
const tabUrl = tabStates[tabIndex]?.url;
33+
const isOnHomepage = tabUrl === RAINBOW_HOME;
34+
const isEmptyState = !multipleTabsOpen && isOnHomepage;
3235
const buttonSize = multipleTabsOpen ? SCALE_ADJUSTED_X_BUTTON_SIZE : SCALE_ADJUSTED_X_BUTTON_SIZE_SINGLE_TAB;
3336
const buttonPadding = multipleTabsOpen ? SCALE_ADJUSTED_X_BUTTON_PADDING : SCALE_ADJUSTED_X_BUTTON_PADDING_SINGLE_TAB;
3437

@@ -40,13 +43,13 @@ export const CloseTabButton = ({ onPress, tabIndex }: { onPress: () => void; tab
4043
// entered. This is mainly to avoid showing the close button in the
4144
// active tab until the tab view animation is near complete.
4245
const interpolatedOpacity = interpolate(progress, [0, 80, 100], [isActiveTab ? 0 : 1, isActiveTab ? 0 : 1, 1]);
43-
const opacity = tabViewVisible?.value || !isActiveTab ? interpolatedOpacity : withTiming(0, TIMING_CONFIGS.fastFadeConfig);
44-
46+
const opacity =
47+
!isEmptyState && (tabViewVisible?.value || !isActiveTab) ? interpolatedOpacity : withTiming(0, TIMING_CONFIGS.fastFadeConfig);
4548
return { opacity };
4649
});
4750

4851
const pointerEventsStyle = useAnimatedStyle(() => {
49-
const pointerEvents = tabViewVisible?.value ? 'auto' : 'none';
52+
const pointerEvents = tabViewVisible?.value && !isEmptyState ? 'auto' : 'none';
5053
return { pointerEvents };
5154
});
5255

0 commit comments

Comments
 (0)