Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ describe('TabBar', () => {
);

fireEvent.press(getByTestId(`tab-bar-item-${TabBarIconKey.Trending}`));
expect(navigation.navigate).toHaveBeenCalledWith(Routes.TRENDING_VIEW);
expect(navigation.reset).toHaveBeenCalledWith({
index: 0,
routes: [{ name: Routes.TRENDING_VIEW }],
});
});

it('does not navigate to trending when trending feature flag is disabled', () => {
Expand Down
13 changes: 11 additions & 2 deletions app/component-library/components/Navigation/TabBar/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const TabBar = ({ state, descriptors, navigation }: TabBarProps) => {
const callback = options.callback;
const rootScreenName = options.rootScreenName;
const key = `tab-bar-item-${tabBarIconKey}`; // this key is also used to identify elements for e2e testing
const isSelected = state.index === index;
const isSelected = options?.isSelected
? options.isSelected(state.routeNames[state.index])
: state.index === index;
const icon = ICON_BY_TAB_BAR_ICON_KEY[tabBarIconKey];
const labelKey = LABEL_BY_TAB_BAR_ICON_KEY[tabBarIconKey];
const labelText = labelKey ? strings(labelKey) : '';
Expand Down Expand Up @@ -93,7 +95,10 @@ const TabBar = ({ state, descriptors, navigation }: TabBarProps) => {
break;
case Routes.TRENDING_VIEW:
if (isAssetsTrendingTokensEnabled) {
navigation.navigate(Routes.TRENDING_VIEW);
navigation.reset({
index: 0,
routes: [{ name: Routes.TRENDING_VIEW }],
});
}
break;
}
Expand All @@ -102,6 +107,10 @@ const TabBar = ({ state, descriptors, navigation }: TabBarProps) => {
const isWalletAction =
rootScreenName === Routes.MODAL.TRADE_WALLET_ACTIONS;

if (options?.isHidden) {
return null;
}

return (
<View key={key} style={tw.style('flex-1 w-full')}>
<TabBarItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface ExtendedBottomTabDescriptor extends BottomTabDescriptor {
tabBarIconKey: TabBarIconKey;
callback: () => void;
rootScreenName: string;
isSelected?: (rootScreenName: string) => boolean;
isHidden?: boolean;
};
}

Expand Down
166 changes: 90 additions & 76 deletions app/components/Nav/Main/MainNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ import { Confirm as RedesignedConfirm } from '../../Views/confirmations/componen
import ContactForm from '../../Views/Settings/Contacts/ContactForm';
import ActivityView from '../../Views/ActivityView';
import RewardsNavigator from '../../UI/Rewards/RewardsNavigator';
import TrendingView from '../../Views/TrendingView/TrendingView';
import { ExploreFeed } from '../../Views/TrendingView/TrendingView';
import ExploreSearchScreen from '../../Views/TrendingView/ExploreSearchScreen/ExploreSearchScreen';
import SwapsAmountView from '../../UI/Swaps';
import SwapsQuotesView from '../../UI/Swaps/QuotesView';
import CollectiblesDetails from '../../UI/CollectibleModal';
Expand Down Expand Up @@ -133,7 +134,6 @@ import {
} from '../../Views/AddAsset/AddAsset.constants';
import { strings } from '../../../../locales/i18n';
import SitesFullView from '../../Views/SitesFullView/SitesFullView';
import BrowserWrapper from '../../Views/TrendingView/components/BrowserWrapper/BrowserWrapper';
import BridgeView from '../../UI/Bridge/Views/BridgeView';

const Stack = createStackNavigator();
Expand Down Expand Up @@ -278,25 +278,6 @@ const RewardsHome = () => (
</Stack.Navigator>
);

// Persist the last trending screen across unmounts
export const lastTrendingScreenRef = { current: 'TrendingFeed' };

// Callback to update the last trending screen (outside component to persist)
export const updateLastTrendingScreen = (screenName) => {
// eslint-disable-next-line react-compiler/react-compiler
lastTrendingScreenRef.current = screenName;
};

const TrendingHome = () => (
<Stack.Navigator mode="modal" screenOptions={clearStackNavigatorOptions}>
<Stack.Screen
name={Routes.TRENDING_VIEW}
component={TrendingView}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);

/* eslint-disable react/prop-types */
const BrowserFlow = (props) => (
<Stack.Navigator
Expand Down Expand Up @@ -324,6 +305,63 @@ const BrowserFlow = (props) => (
</Stack.Navigator>
);

const ExploreHome = () => (
<Stack.Navigator initialRouteName={Routes.TRENDING_FEED} mode="modal">
<Stack.Screen
name={Routes.TRENDING_FEED}
component={ExploreFeed}
options={{ headerShown: false }}
/>
<Stack.Screen
name={Routes.EXPLORE_SEARCH}
component={ExploreSearchScreen}
options={{
headerShown: false,
animationEnabled: true,
cardStyleInterpolator: ({ current, layouts }) => ({
cardStyle: {
transform: [
{
translateX: current.progress.interpolate({
inputRange: [0, 1],
outputRange: [layouts.screen.width, 0],
}),
},
],
},
}),
}}
/>
<Stack.Screen
name={Routes.SITES_FULL_VIEW}
component={SitesFullView}
options={{
headerShown: false,
animationEnabled: true,
cardStyleInterpolator: ({ current, layouts }) => ({
cardStyle: {
transform: [
{
translateX: current.progress.interpolate({
inputRange: [0, 1],
outputRange: [layouts.screen.width, 0],
}),
},
],
},
}),
}}
/>

{/* Trending Browser Stack (uses existing browser flow) */}
<Stack.Screen
name={Routes.BROWSER.HOME}
component={BrowserFlow}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);

///: BEGIN:ONLY_INCLUDE_IF(external-snaps)
const SnapsSettingsStack = () => (
<Stack.Navigator>
Expand Down Expand Up @@ -642,10 +680,12 @@ const HomeTabs = () => {
}

// Hide tab bar when browser is in fullscreen mode
if (
isBrowserFullscreen &&
currentRoute.name?.startsWith(Routes.BROWSER.HOME)
) {
const currentStackRouteName =
currentRoute?.state?.routes?.[currentRoute?.state?.index]?.name;
const isInBrowser =
currentRoute.name?.startsWith(Routes.BROWSER.HOME) ||
currentStackRouteName?.startsWith(Routes.BROWSER.HOME);
if (isBrowserFullscreen && isInBrowser) {
return null;
}

Expand All @@ -669,21 +709,33 @@ const HomeTabs = () => {
component={WalletTabModalFlow}
/>
{isAssetsTrendingTokensEnabled ? (
<Tab.Screen
name={Routes.TRENDING_VIEW}
options={options.trending}
component={TrendingHome}
layout={({ children }) => UnmountOnBlurComponent(children)}
/>
<>
<Tab.Screen
name={Routes.TRENDING_VIEW}
options={{
...options.trending,
isSelected: (rootScreenName) =>
[Routes.TRENDING_VIEW, Routes.BROWSER.HOME].includes(
rootScreenName,
),
}}
component={ExploreHome}
layout={({ children }) => UnmountOnBlurComponent(children)}
/>
<Tab.Screen
name={Routes.BROWSER.HOME}
options={{
...options.browser,
isHidden: true,
}}
component={BrowserFlow}
layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
/>
</>
) : (
<Tab.Screen
name={Routes.BROWSER.HOME}
options={{
...options.browser,
tabBarButton: isAssetsTrendingTokensEnabled
? () => null
: undefined,
}}
options={options.browser}
component={BrowserFlow}
layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
/>
Expand Down Expand Up @@ -950,26 +1002,6 @@ const MainNavigator = () => {
}}
/>
<Stack.Screen name="Home" component={HomeTabs} />
<Stack.Screen
name="TrendingBrowser"
component={BrowserWrapper}
options={{
headerShown: false,
animationEnabled: true,
cardStyleInterpolator: ({ current, layouts }) => ({
cardStyle: {
transform: [
{
translateX: current.progress.interpolate({
inputRange: [0, 1],
outputRange: [layouts.screen.width, 0],
}),
},
],
},
}),
}}
/>
<Stack.Screen
name={Routes.WALLET.TOKENS_FULL_VIEW}
component={TokensFullView}
Expand Down Expand Up @@ -1033,25 +1065,7 @@ const MainNavigator = () => {
}),
}}
/>
<Stack.Screen
name={Routes.SITES_FULL_VIEW}
component={SitesFullView}
options={{
animationEnabled: true,
cardStyleInterpolator: ({ current, layouts }) => ({
cardStyle: {
transform: [
{
translateX: current.progress.interpolate({
inputRange: [0, 1],
outputRange: [layouts.screen.width, 0],
}),
},
],
},
}),
}}
/>

<Stack.Screen name="Webview" component={Webview} />
<Stack.Screen name="SendView" component={SendView} />
<Stack.Screen
Expand Down
21 changes: 0 additions & 21 deletions app/components/Nav/Main/__snapshots__/MainNavigator.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ exports[`MainNavigator matches rendered snapshot 1`] = `
component={[Function]}
name="Home"
/>
<Screen
component={[Function]}
name="TrendingBrowser"
options={
{
"animationEnabled": true,
"cardStyleInterpolator": [Function],
"headerShown": false,
}
}
/>
<Screen
component={[Function]}
name="TokensFullView"
Expand Down Expand Up @@ -97,16 +86,6 @@ exports[`MainNavigator matches rendered snapshot 1`] = `
}
}
/>
<Screen
component={[Function]}
name="SitesFullView"
options={
{
"animationEnabled": true,
"cardStyleInterpolator": [Function],
}
}
/>
<Screen
component={[Function]}
name="Webview"
Expand Down
Loading
Loading