nostros/frontend/Pages/FeedNavigator/index.tsx

144 lines
5.0 KiB
TypeScript
Raw Normal View History

2023-01-13 11:51:30 +00:00
import * as React from 'react'
import { Platform, View } from 'react-native'
import type { DrawerNavigationProp } from '@react-navigation/drawer'
2023-01-13 16:36:05 +00:00
import { CardStyleInterpolators, createStackNavigator } from '@react-navigation/stack'
2023-01-16 20:06:12 +00:00
import { Appbar, Text, useTheme } from 'react-native-paper'
2023-01-15 14:22:02 +00:00
import RBSheet from 'react-native-raw-bottom-sheet'
2023-01-13 11:51:30 +00:00
import { useTranslation } from 'react-i18next'
2023-01-13 16:36:05 +00:00
import HomePage from '../HomePage'
2023-01-14 14:52:10 +00:00
import RelaysPage from '../RelaysPage'
import AboutPage from '../AboutPage'
import ProfileConfigPage from '../ProfileConfigPage'
2023-01-14 20:35:35 +00:00
import ProfilePage from '../ProfilePage'
2023-01-15 14:22:02 +00:00
import ProfileCard from '../../Components/ProfileCard'
2023-01-15 18:04:59 +00:00
import NotePage from '../NotePage'
2023-01-16 09:03:01 +00:00
import SendPage from '../SendPage'
2023-01-16 16:00:10 +00:00
import ConversationPage from '../ConversationPage'
2023-01-13 11:51:30 +00:00
2023-01-13 16:36:05 +00:00
export const HomeNavigator: React.FC = () => {
2023-01-13 11:51:30 +00:00
const theme = useTheme()
const { t } = useTranslation('common')
2023-01-16 20:06:12 +00:00
const bottomSheetRef = React.useRef<RBSheet>(null)
const [bottomSheetPage, setBottomSheetPage] = React.useState<string>('keys')
2023-01-15 14:22:02 +00:00
const bottomSheetProfileRef = React.useRef<RBSheet>(null)
2023-01-13 11:51:30 +00:00
const Stack = React.useMemo(() => createStackNavigator(), [])
2023-01-15 14:22:02 +00:00
const [showProfile, setShowProfile] = React.useState<string>()
2023-01-13 11:51:30 +00:00
const cardStyleInterpolator = React.useMemo(
() =>
Platform.OS === 'android'
? CardStyleInterpolators.forFadeFromBottomAndroid
: CardStyleInterpolators.forHorizontalIOS,
[],
)
2023-01-15 14:22:02 +00:00
const bottomSheetStyles = React.useMemo(() => {
return {
container: {
backgroundColor: theme.colors.background,
padding: 16,
borderTopRightRadius: 28,
2023-01-16 12:09:18 +00:00
borderTopLeftRadius: 28,
2023-01-15 14:22:02 +00:00
},
}
}, [])
2023-01-16 20:06:12 +00:00
const onPressQuestion: (pageName: string) => void = (pageName) => {
bottomSheetRef.current?.open()
setBottomSheetPage(pageName === 'Relays' ? 'relays' : 'keys')
}
const BottomSheetRelays = React.useMemo(
() => (
<View>
<Text variant='headlineSmall'>{t('drawers.relaysTitle')}</Text>
2023-01-17 08:46:57 +00:00
<Text variant='bodyMedium'>{t('drawers.relaysDescription')}</Text>
2023-01-16 20:06:12 +00:00
</View>
),
[],
)
const BottomSheets = {
relays: {
component: BottomSheetRelays,
height: 700,
},
}
2023-01-13 11:51:30 +00:00
return (
<>
<Stack.Navigator
screenOptions={({ navigation }) => {
return {
detachPreviousScreen: !navigation.isFocused(),
cardStyleInterpolator,
header: ({ navigation, route, options, back }) => {
return (
<Appbar.Header>
{back ? (
<Appbar.BackAction onPress={() => navigation.goBack()} />
) : (navigation as any).openDrawer ? (
<Appbar.Action
icon='menu'
isLeading
onPress={() => (navigation as any as DrawerNavigationProp<{}>).openDrawer()}
/>
) : null}
2023-01-14 14:52:10 +00:00
<Appbar.Content title={t(`homeNavigator.${route.name}`)} />
2023-01-16 16:00:10 +00:00
{['Profile', 'Conversation'].includes(route.name) && (
2023-01-15 14:22:02 +00:00
<Appbar.Action
icon='dots-vertical'
onPress={() => {
2023-01-16 12:09:18 +00:00
const params = route?.params as { pubKey: string }
2023-01-15 14:22:02 +00:00
setShowProfile(params?.pubKey ?? '')
bottomSheetProfileRef.current?.open()
}}
/>
)}
2023-01-16 20:06:12 +00:00
{['Relays'].includes(route.name) && (
<Appbar.Action
icon='help-circle-outline'
isLeading
onPress={() => onPressQuestion(route.name)}
/>
)}
2023-01-13 11:51:30 +00:00
</Appbar.Header>
)
},
}
}}
>
<Stack.Group>
2023-01-14 14:52:10 +00:00
<Stack.Screen name='Landing' component={HomePage} />
2023-01-20 14:09:05 +00:00
<Stack.Screen name='Note' component={NotePage} />
<Stack.Screen name='Send' component={SendPage} />
<Stack.Screen name='Reply' component={SendPage} />
<Stack.Screen name='Conversation' component={ConversationPage} />
2023-01-14 14:52:10 +00:00
</Stack.Group>
<Stack.Group>
<Stack.Screen name='Relays' component={RelaysPage} />
<Stack.Screen name='About' component={AboutPage} />
<Stack.Screen name='ProfileConfig' component={ProfileConfigPage} />
2023-01-14 20:35:35 +00:00
<Stack.Screen name='Profile' component={ProfilePage} />
2023-01-13 11:51:30 +00:00
</Stack.Group>
</Stack.Navigator>
<RBSheet
2023-01-15 14:22:02 +00:00
ref={bottomSheetProfileRef}
closeOnDragDown={true}
height={280}
customStyles={bottomSheetStyles}
>
2023-01-16 12:09:18 +00:00
<ProfileCard userPubKey={showProfile ?? ''} bottomSheetRef={bottomSheetProfileRef} />
2023-01-15 14:22:02 +00:00
</RBSheet>
<RBSheet
2023-01-16 20:06:12 +00:00
ref={bottomSheetRef}
2023-01-13 11:51:30 +00:00
closeOnDragDown={true}
2023-01-16 20:06:12 +00:00
height={BottomSheets[bottomSheetPage]?.height}
2023-01-15 14:22:02 +00:00
customStyles={bottomSheetStyles}
2023-01-13 11:51:30 +00:00
>
2023-01-16 20:06:12 +00:00
{BottomSheets[bottomSheetPage]?.component}
2023-01-13 11:51:30 +00:00
</RBSheet>
</>
)
}
2023-01-13 16:36:05 +00:00
export default HomeNavigator