Skip to content
Draft
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
14 changes: 11 additions & 3 deletions components/CustomTopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Animated, {
withSequence,
} from 'react-native-reanimated';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { HomeIcon } from './Icons';
import { HomeIcon, DiscoverIcon } from './Icons';

const { width: screenWidth } = Dimensions.get('window');
const ANIMATION_DURATION = 300;
Expand All @@ -19,16 +19,24 @@ const SPRING_CONFIG = {
mass: 1,
};

const getIcon = (_routeName: string, focused: boolean) => {
const getIcon = (routeName: string, focused: boolean) => {
const iconProps = {
size: focused ? 28 : 24,
focused,
};

if (routeName === 'Discover') {
return <DiscoverIcon {...iconProps} />;
}

return <HomeIcon {...iconProps} />;
};

const getTabColor = (_routeName: string) => {
const getTabColor = (routeName: string) => {
if (routeName === 'Discover') {
return 'text-emerald-600';
}

return 'text-emerald-600';
};

Expand Down
36 changes: 34 additions & 2 deletions navigation/TabNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ import {
BottomTabScreenProps,
} from '@react-navigation/bottom-tabs';
import { Text } from 'react-native';
import Animated, { SlideInRight, SlideOutLeft } from 'react-native-reanimated';
import Animated, {
SlideInRight,
SlideOutLeft,
FadeIn,
FadeOut,
} from 'react-native-reanimated';
import HomeScreen from '../screens/HomeScreen';
import { CustomTabBar } from '../components/CustomTopBar';
import { TabParamList } from '../navigation';
import { TabParamList, RootStackParamList } from '../navigation';
import { CompositeScreenProps } from '@react-navigation/native';
import { StackScreenProps } from '@react-navigation/stack';
import DiscoverScreen from '../screens/DiscoverScreen';

const Tab = createBottomTabNavigator<TabParamList>();

type HomeScreenProps = BottomTabScreenProps<TabParamList, 'Home'>;

type DiscoverScreenProps = CompositeScreenProps<
BottomTabScreenProps<TabParamList, 'Discover'>,
StackScreenProps<RootStackParamList>
>;

const AnimatedHomeScreen = (_props: HomeScreenProps) => (
<Animated.View
entering={SlideInRight.duration(300).springify()}
Expand All @@ -22,6 +35,16 @@ const AnimatedHomeScreen = (_props: HomeScreenProps) => (
</Animated.View>
);

const AnimatedDiscoverScreen = (props: DiscoverScreenProps) => (
<Animated.View
entering={FadeIn.duration(300)}
exiting={FadeOut.duration(300)}
style={{ flex: 1 }}
>
<DiscoverScreen {...props} />
</Animated.View>
);

export const TabNavigation = () => {
return (
<Tab.Navigator
Expand Down Expand Up @@ -53,6 +76,15 @@ export const TabNavigation = () => {
headerTitleAlign: 'center',
}}
/>

<Tab.Screen
name="Discover"
component={AnimatedDiscoverScreen}
options={{
headerTitle: 'Discover',
headerTitleAlign: 'center',
}}
/>
</Tab.Navigator>
);
};
1 change: 1 addition & 0 deletions navigation/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type TabParamList = {
Home: undefined;
Discover: undefined;
};

export type RootStackParamList = {
Expand Down
74 changes: 74 additions & 0 deletions screens/DiscoverScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import {
FlatList,
SafeAreaView,
StatusBar,
Text,
TouchableOpacity,
View,
} from 'react-native';
import { StackScreenProps } from '@react-navigation/stack';
import { RootStackParamList, TabParamList } from '../navigation';
import { BottomTabScreenProps } from '@react-navigation/bottom-tabs';
import { CompositeScreenProps } from '@react-navigation/native';

const linkData = [
{
id: '1',
title: 'Template DApp',
url: 'https://devnet.template-dapp.multiversx.com',
},
{
id: '2',
title: 'xExchange',
url: 'https://devnet.xexchange.com',
},
];

type DiscoverScreenProps = CompositeScreenProps<
BottomTabScreenProps<TabParamList, 'Discover'>,
StackScreenProps<RootStackParamList>
>;

const DiscoverScreen: React.FC<DiscoverScreenProps> = ({ navigation }) => {
const handleLinkPress = (url: string, title: string) => {
navigation.navigate('DAppScreen', { url: url, title: title });
};

const renderLinkItem = ({
item,
}: {
item: { url: string; title: string };
}) => (
<TouchableOpacity
className="bg-white p-4 my-2 mx-5 rounded-xl border border-gray-200 shadow-sm active:bg-gray-50"
onPress={() => handleLinkPress(item.url, item.title)}
>
<Text className="text-lg font-semibold text-gray-800 mb-1">
{item.title}
</Text>
<Text className="text-sm text-gray-500 italic">{item.url}</Text>
</TouchableOpacity>
);

return (
<SafeAreaView className="flex-1 bg-gray-50">
<StatusBar barStyle="dark-content" backgroundColor="#f9fafb" />

<View className="bg-white px-5 py-4 border-b border-gray-200">
<Text className="text-2xl font-bold text-gray-900">Links</Text>
</View>

<FlatList
data={linkData}
renderItem={renderLinkItem}
keyExtractor={item => item.id}
className="flex-1"
showsVerticalScrollIndicator={false}
contentContainerStyle={{ paddingVertical: 8 }}
/>
</SafeAreaView>
);
};

export default DiscoverScreen;