Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat / LIVE-3666 - New homepage tab navigator #1462

Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -1,39 +1,29 @@
import React, { useMemo } from "react";
import { useSelector } from "react-redux";
import { createStackNavigator } from "@react-navigation/stack";
import { useTheme } from "styled-components/native";
import { NavigatorName, ScreenName } from "../../const";
import Portfolio from "../../screens/Portfolio";
// eslint-disable-next-line import/no-cycle
import ReadOnlyPortfolio from "../../screens/Portfolio/ReadOnly";
import { NavigatorName } from "../../const";
// eslint-disable-next-line import/no-cycle
import AccountsNavigator from "./AccountsNavigator";
import { getStackNavigatorConfig } from "../../navigation/navigatorConfig";
import { readOnlyModeEnabledSelector } from "../../reducers/settings";
import { accountsSelector } from "../../reducers/accounts";
// eslint-disable-next-line import/no-cycle
import WalletTabNavigator from "./WalletTabNavigator";

export default function PortfolioNavigator() {
const { colors } = useTheme();
const stackNavigationConfig = useMemo(
() => getStackNavigatorConfig(colors, true),
[colors],
);
const readOnlyModeEnabled = useSelector(readOnlyModeEnabledSelector);
const accounts = useSelector(accountsSelector);

return (
<Stack.Navigator
screenOptions={stackNavigationConfig}
initialRouteName={ScreenName.Portfolio}
initialRouteName={NavigatorName.WalletTab}
backBehavior={"initialRoute"}
>
<Stack.Screen
name={ScreenName.Portfolio}
component={
readOnlyModeEnabled && accounts.length <= 0
? ReadOnlyPortfolio
: Portfolio
}
name={NavigatorName.WalletTab}
component={WalletTabNavigator}
options={{
headerShown: false,
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { useTheme } from "styled-components/native";
import {
createMaterialTopTabNavigator,
MaterialTopTabBarProps,
} from "@react-navigation/material-top-tabs";
import styled from "@ledgerhq/native-ui/components/styled";
import { Flex, Text } from "@ledgerhq/native-ui";
import { useSelector } from "react-redux";
import { ScreenName } from "../../const";
import Portfolio from "../../screens/Portfolio";
import WalletNftGallery from "../../screens/Nft/WalletNftGallery";
import { rgba } from "../../colors";
import { readOnlyModeEnabledSelector } from "../../reducers/settings";
import { accountsSelector } from "../../reducers/accounts";
// eslint-disable-next-line import/no-cycle
import ReadOnlyPortfolio from "../../screens/Portfolio/ReadOnly";

const Tab = createMaterialTopTabNavigator();

const TabBarContainer = styled(Flex)`
border-bottom-width: 1px;
border-bottom-color: ${p => p.theme.colors.palette.neutral.c40};
background-color: transparent;
`;

const StyledTab = styled.TouchableOpacity``;

function TabBar({ state, descriptors, navigation }: MaterialTopTabBarProps) {
const { colors } = useTheme();

return (
<TabBarContainer
paddingLeft={4}
paddingRight={4}
paddingBottom={4}
paddingTop={4}
Comment on lines +35 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p={4} no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, seems that this was on purpose because with the styled wrapper, just putting p={4} doesn't work ...

>
<Flex flexDirection={"row"}>
{state.routes.map((route, index) => {
const { options } = descriptors[route.key];
const label = options.title;

const isActive = state.index === index;

const onPress = () => {
const event = navigation.emit({
type: "tabPress",
target: route.key,
canPreventDefault: true,
});

if (!isActive && !event.defaultPrevented) {
navigation.navigate(route.name);
}
};

return (
<StyledTab
key={index}
bg={isActive ? "primary.c70" : rgba(colors.constant.white, 0.08)}
borderRadius={2}
px={4}
py={3}
mr={4}
onPress={onPress}
>
<Text
fontWeight={"semiBold"}
variant={"body"}
color={"neutral.c100"}
>
{label}
</Text>
</StyledTab>
);
})}
</Flex>
</TabBarContainer>
);
}

export default function WalletTabNavigator() {
const readOnlyModeEnabled = useSelector(readOnlyModeEnabledSelector);
const accounts = useSelector(accountsSelector);

const { t } = useTranslation();
return (
// <Box bg={"red"} flex={1}>
<Tab.Navigator
tabBar={(props: MaterialTopTabBarProps) => <TabBar {...props} />}
screenOptions={{
tabBarStyle: { backgroundColor: "red" },
}}
style={{ backgroundColor: "transparent" }}
sceneContainerStyle={{ backgroundColor: "transparent" }}
tabBarOptions={{ style: { backgroundColor: "transparent" } }}
// lazy
lazy={true}
>
<Tab.Screen
name={ScreenName.Portfolio}
component={
readOnlyModeEnabled && accounts.length <= 0
? ReadOnlyPortfolio
: Portfolio
}
options={{
title: t("wallet.tabs.crypto"),
}}
/>
<Tab.Screen
name={ScreenName.WalletNftGallery}
component={WalletNftGallery}
options={{
title: t("wallet.tabs.nft"),
}}
/>
</Tab.Navigator>
// </Box>
);
}
2 changes: 2 additions & 0 deletions apps/ledger-live-mobile/src/const/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const ScreenName = {
VoteValidation: "VoteValidation",
VoteValidationError: "VoteValidationError",
VoteValidationSuccess: "VoteValidationSuccess",
WalletNftGallery: "WalletNftGallery",

// celo
CeloRegistrationValidationSuccess: "CeloRegistrationValidationSuccess",
Expand Down Expand Up @@ -523,6 +524,7 @@ export const NavigatorName = {
CeloWithdrawFlow: "CeloWithdrawFlow",
// Tab
Main: "Main",
WalletTab: "WalletTabNavigator",
// Root
RootNavigator: "RootNavigator",
Discover: "Discover",
Expand Down
6 changes: 6 additions & 0 deletions apps/ledger-live-mobile/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -5131,5 +5131,11 @@
"title": "Getting started",
"description": "Click here to finish setting up your {{productName}} with Ledger Live"
}
},
"wallet": {
"tabs": {
"crypto": "Crypto",
"nft": "NFTs"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Box } from "@ledgerhq/native-ui";
import React from "react";

const WalletNftGallery = () => {
console.log("WalletNftGallery screen");
return <Box bg={"red"} height={200} width={400} />;
};

export default WalletNftGallery;