import * as React from 'react' import { Platform, View } from 'react-native' import type { DrawerNavigationProp } from '@react-navigation/drawer' import { CardStyleInterpolators, createStackNavigator } from '@react-navigation/stack' import { Appbar, Text, useTheme } from 'react-native-paper' import RBSheet from 'react-native-raw-bottom-sheet' import { useTranslation } from 'react-i18next' import HomePage from '../HomePage' import RelaysPage from '../RelaysPage' import AboutPage from '../AboutPage' import ProfileConfigPage from '../ProfileConfigPage' import ProfilePage from '../ProfilePage' import ProfileCard from '../../Components/ProfileCard' import NotePage from '../NotePage' import SendPage from '../SendPage' import ConversationPage from '../ConversationPage' export const HomeNavigator: React.FC = () => { const theme = useTheme() const { t } = useTranslation('common') const bottomSheetRef = React.useRef(null) const [bottomSheetPage, setBottomSheetPage] = React.useState('keys') const bottomSheetProfileRef = React.useRef(null) const Stack = React.useMemo(() => createStackNavigator(), []) const [showProfile, setShowProfile] = React.useState() const cardStyleInterpolator = React.useMemo( () => Platform.OS === 'android' ? CardStyleInterpolators.forFadeFromBottomAndroid : CardStyleInterpolators.forHorizontalIOS, [], ) const bottomSheetStyles = React.useMemo(() => { return { container: { backgroundColor: theme.colors.background, padding: 16, borderTopRightRadius: 28, borderTopLeftRadius: 28, }, } }, []) const onPressQuestion: (pageName: string) => void = (pageName) => { bottomSheetRef.current?.open() setBottomSheetPage(pageName === 'Relays' ? 'relays' : 'keys') } const BottomSheetRelays = React.useMemo( () => ( {t('drawers.relaysTitle')} {t('drawers.relaysDescription')} ), [], ) const BottomSheets = { relays: { component: BottomSheetRelays, height: 700, }, } return ( <> { return { detachPreviousScreen: !navigation.isFocused(), cardStyleInterpolator, header: ({ navigation, route, options, back }) => { return ( {back ? ( navigation.goBack()} /> ) : (navigation as any).openDrawer ? ( (navigation as any as DrawerNavigationProp<{}>).openDrawer()} /> ) : null} {['Profile', 'Conversation'].includes(route.name) && ( { const params = route?.params as { pubKey: string } setShowProfile(params?.pubKey ?? '') bottomSheetProfileRef.current?.open() }} /> )} {['Relays'].includes(route.name) && ( onPressQuestion(route.name)} /> )} ) }, } }} > {BottomSheets[bottomSheetPage]?.component} ) } export default HomeNavigator