Skip to content

Commit 1e2f7ca

Browse files
authored
fix: hide trending and show browser when ff is false (MetaMask#22209)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR implements a complete navigation flow for the Trending feature, allowing users to browse web content from within the Trending tab without modifying the bottom navigation structure. you should set the two env vars: ``` export OVERRIDE_REMOTE_FEATURE_FLAGS="true" export ASSETS_TRENDING_TOKENS_ENABLED="true" ``` ### Key Changes: 1. **TrendingView Stack Navigator**: Converted TrendingView to use a Stack Navigator with two routes: - `TrendingFeed`: Pure React Native "coming soon" screen with an Explore button - `TrendingBrowser`: Full Browser component with all features (tabs, URL bar, search) 2. **Native Coming Soon Screen**: Replaced WebView-based HTML content with native React Native components using `@metamask/design-system-react-native` 3. **Navigation Flow**: Users can tap the Explore button (🔍) in TrendingFeed to open the Browser with the MetaMask portfolio, browse any website, and navigate back using: - ← Back arrow button (left side of URL bar) - ✕ Close button (right side of URL bar) 4. **Back Button Implementation**: Added a back button in `BrowserTab` that: - Appears on the left side of BrowserUrlBar - Only shows when `fromTrending && isAssetsTrendingTokensEnabled` is true - Uses `navigation.goBack()` to return to TrendingFeed 5. **No MainNavigator Changes**: All navigation is self-contained within TrendingView's Stack Navigator, maintaining the existing bottom tab structure ## **Changelog** CHANGELOG entry: Implemented Trending view with browser navigation support ## **Related issues** Fixes: N/A ## **Manual testing steps** ### **Before** - Trending tab showed WebView with HTML-based "coming soon" message - No way to access browser functionality from Trending tab ### **After** - Trending tab shows native React Native "coming soon" screen - Explore button opens full browser experience - Back button allows easy return to Trending feed - Complete browser functionality available within Trending context https://github.com/user-attachments/assets/4a37f02b-3c1b-4f85-a6fa-f319221e688f ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [x] I've converted TrendingView from WebView to native React Native components - [x] I've implemented a Stack Navigator for proper navigation flow - [x] I've added back button functionality that respects the feature flag ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. - [ ] I've verified the Explore button opens the browser with portfolio - [ ] I've verified the back button (←) and close button (✕) both navigate back to Trending - [ ] I've verified the back button only appears when navigating from Trending - [ ] I've verified all browser features work correctly (tabs, URL bar, search, history) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduces a stack navigator for Trending with a native feed and embedded browser, adds a back button in BrowserTab, and conditionally shows Trending tab via feature flag with last-screen persistence. > > - **Trending navigation (stack-based)**: > - Add `TrendingView` as a stack with `TrendingFeed` (native "coming soon") and `TrendingBrowser` (wrapped `Browser`). > - Intercept navigation in `BrowserWrapper` to `goBack` when targeting `Routes.TRENDING_VIEW`. > - Persist last viewed screen via `lastTrendingScreenRef` and `updateLastTrendingScreen`. > - Explore button navigates to `TrendingBrowser` with `newTabUrl`, `timestamp`, and `fromTrending`. > - **Browser tab UI/behavior**: > - Add left-side back button in `BrowserTab` header (Design System `ButtonIcon`) when assets trending flag is enabled; navigates to `TrendingFeed`. > - Refactor URL bar container to include back button; simplify cancel behavior; keep close button visibility for `fromTrending && isAssetsTrendingTokensEnabled`. > - **Main tabs logic**: > - Conditionally show `Trending` tab (or fallback to `Browser` tab) based on `assetsTrendingTokens` flag. > - **Tests & snapshots**: > - Update `TrendingView.test.tsx` for new stack flow and navigation params. > - Update BrowserTab snapshot to reflect new header layout. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8eeba12. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent a80db11 commit 1e2f7ca

5 files changed

Lines changed: 377 additions & 252 deletions

File tree

app/components/Nav/Main/MainNavigator.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useMemo } from 'react';
1+
import React, { useState, useEffect, useMemo, useCallback } from 'react';
22
import { Image, StyleSheet, Keyboard, Platform } from 'react-native';
33
import { createStackNavigator } from '@react-navigation/stack';
44
import { useSelector } from 'react-redux';
@@ -271,6 +271,15 @@ const RewardsHome = () => (
271271
</Stack.Navigator>
272272
);
273273

274+
// Persist the last trending screen across unmounts
275+
export const lastTrendingScreenRef = { current: 'TrendingFeed' };
276+
277+
// Callback to update the last trending screen (outside component to persist)
278+
export const updateLastTrendingScreen = (screenName) => {
279+
// eslint-disable-next-line react-compiler/react-compiler
280+
lastTrendingScreenRef.current = screenName;
281+
};
282+
274283
const TrendingHome = () => (
275284
<Stack.Navigator mode="modal" screenOptions={clearStackNavigatorOptions}>
276285
<Stack.Screen
@@ -667,23 +676,26 @@ const HomeTabs = () => {
667676
options={options.home}
668677
component={WalletTabModalFlow}
669678
/>
670-
{isAssetsTrendingTokensEnabled && (
679+
{isAssetsTrendingTokensEnabled ? (
671680
<Tab.Screen
672681
name={Routes.TRENDING_VIEW}
673682
options={options.trending}
674683
component={TrendingHome}
675684
layout={({ children }) => UnmountOnBlurComponent(children)}
676685
/>
686+
) : (
687+
<Tab.Screen
688+
name={Routes.BROWSER.HOME}
689+
options={{
690+
...options.browser,
691+
tabBarButton: isAssetsTrendingTokensEnabled
692+
? () => null
693+
: undefined,
694+
}}
695+
component={BrowserFlow}
696+
layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
697+
/>
677698
)}
678-
<Tab.Screen
679-
name={Routes.BROWSER.HOME}
680-
options={{
681-
...options.browser,
682-
tabBarButton: isAssetsTrendingTokensEnabled ? () => null : undefined,
683-
}}
684-
component={BrowserFlow}
685-
layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
686-
/>
687699
<Tab.Screen
688700
name={Routes.MODAL.TRADE_WALLET_ACTIONS}
689701
options={options.trade}

app/components/Views/BrowserTab/BrowserTab.tsx

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ import { toHex } from '@metamask/controller-utils';
122122
import { parseCaipAccountId } from '@metamask/utils';
123123
import { selectBrowserFullscreen } from '../../../selectors/browser';
124124
import { selectAssetsTrendingTokensEnabled } from '../../../selectors/featureFlagController/assetsTrendingTokens';
125+
import {
126+
Box,
127+
BoxFlexDirection,
128+
BoxAlignItems,
129+
ButtonIcon,
130+
ButtonIconSize,
131+
IconName,
132+
} from '@metamask/design-system-react-native';
125133

126134
/**
127135
* Tab component for the in-app browser
@@ -1354,24 +1362,19 @@ export const BrowserTab: React.FC<BrowserTabProps> = React.memo(
13541362
[],
13551363
);
13561364

1357-
const onCancelUrlBar = useCallback(() => {
1358-
// If from trending and feature flag is on, navigate back to trending
1359-
if (fromTrending && isAssetsTrendingTokensEnabled) {
1360-
navigation.navigate(Routes.TRENDING_VIEW);
1361-
return;
1362-
}
1365+
const handleBackPress = useCallback(() => {
1366+
navigation.navigate('TrendingFeed');
1367+
}, [navigation]);
13631368

1369+
const onCancelUrlBar = useCallback(() => {
13641370
hideAutocomplete();
13651371
// Reset the url bar to the current url
13661372
const hostName =
13671373
new URLParse(resolvedUrlRef.current).origin || resolvedUrlRef.current;
13681374
urlBarRef.current?.setNativeProps({ text: hostName });
1369-
}, [
1370-
hideAutocomplete,
1371-
fromTrending,
1372-
isAssetsTrendingTokensEnabled,
1373-
navigation,
1374-
]);
1375+
}, [hideAutocomplete]);
1376+
1377+
const showBackButton = isAssetsTrendingTokensEnabled;
13751378

13761379
const onFocusUrlBar = useCallback(() => {
13771380
// Show the autocomplete results
@@ -1494,20 +1497,37 @@ export const BrowserTab: React.FC<BrowserTabProps> = React.memo(
14941497
style={styles.wrapper}
14951498
{...(Device.isAndroid() ? { collapsable: false } : {})}
14961499
>
1497-
<BrowserUrlBar
1498-
ref={urlBarRef}
1499-
connectionType={connectionType}
1500-
onSubmitEditing={onSubmitEditing}
1501-
onCancel={onCancelUrlBar}
1502-
onFocus={onFocusUrlBar}
1503-
onBlur={hideAutocomplete}
1504-
onChangeText={onChangeUrlBar}
1505-
connectedAccounts={permittedCaipAccountAddressesList}
1506-
activeUrl={resolvedUrlRef.current}
1507-
setIsUrlBarFocused={setIsUrlBarFocused}
1508-
isUrlBarFocused={isUrlBarFocused}
1509-
showCloseButton={fromTrending && isAssetsTrendingTokensEnabled}
1510-
/>
1500+
<Box
1501+
flexDirection={BoxFlexDirection.Row}
1502+
alignItems={BoxAlignItems.Center}
1503+
>
1504+
{showBackButton && (
1505+
<ButtonIcon
1506+
iconName={IconName.ArrowLeft}
1507+
size={ButtonIconSize.Lg}
1508+
onPress={handleBackPress}
1509+
testID="browser-tab-back-button"
1510+
/>
1511+
)}
1512+
<Box twClassName="flex-1">
1513+
<BrowserUrlBar
1514+
ref={urlBarRef}
1515+
connectionType={connectionType}
1516+
onSubmitEditing={onSubmitEditing}
1517+
onCancel={onCancelUrlBar}
1518+
onFocus={onFocusUrlBar}
1519+
onBlur={hideAutocomplete}
1520+
onChangeText={onChangeUrlBar}
1521+
connectedAccounts={permittedCaipAccountAddressesList}
1522+
activeUrl={resolvedUrlRef.current}
1523+
setIsUrlBarFocused={setIsUrlBarFocused}
1524+
isUrlBarFocused={isUrlBarFocused}
1525+
showCloseButton={
1526+
fromTrending && isAssetsTrendingTokensEnabled
1527+
}
1528+
/>
1529+
</Box>
1530+
</Box>
15111531
<View style={styles.wrapper}>
15121532
{renderProgressBar()}
15131533
<View style={styles.webview}>

0 commit comments

Comments
 (0)