import React from 'react' import {StatusBar} from 'expo-status-bar' import { DimensionValue, StyleSheet, useWindowDimensions, View, BackHandler, } from 'react-native' import {useSafeAreaInsets} from 'react-native-safe-area-context' import {Drawer} from 'react-native-drawer-layout' import {useNavigationState} from '@react-navigation/native' import {ModalsContainer} from 'view/com/modals/Modal' import {Lightbox} from 'view/com/lightbox/Lightbox' import {ErrorBoundary} from 'view/com/util/ErrorBoundary' import {DrawerContent} from './Drawer' import {Composer} from './Composer' import {useTheme} from 'lib/ThemeContext' import {usePalette} from 'lib/hooks/usePalette' import {RoutesContainer, TabsNavigator} from '../../Navigation' import {isStateAtTabRoot} from 'lib/routes/helpers' import { useIsDrawerOpen, useSetDrawerOpen, useIsDrawerSwipeDisabled, } from '#/state/shell' import {isAndroid} from 'platform/detection' import {useSession} from '#/state/session' import {useCloseAnyActiveElement} from '#/state/util' import * as notifications from 'lib/notifications/notifications' import {Outlet as PortalOutlet} from '#/components/Portal' import {MutedWordsDialog} from '#/components/dialogs/MutedWords' import {useDialogStateContext} from 'state/dialogs' import Animated from 'react-native-reanimated' function ShellInner() { const isDrawerOpen = useIsDrawerOpen() const isDrawerSwipeDisabled = useIsDrawerSwipeDisabled() const setIsDrawerOpen = useSetDrawerOpen() const winDim = useWindowDimensions() const safeAreaInsets = useSafeAreaInsets() const containerPadding = React.useMemo( () => ({height: '100%' as DimensionValue, paddingTop: safeAreaInsets.top}), [safeAreaInsets], ) const renderDrawerContent = React.useCallback(() => , []) const onOpenDrawer = React.useCallback( () => setIsDrawerOpen(true), [setIsDrawerOpen], ) const onCloseDrawer = React.useCallback( () => setIsDrawerOpen(false), [setIsDrawerOpen], ) const canGoBack = useNavigationState(state => !isStateAtTabRoot(state)) const {hasSession, currentAccount} = useSession() const closeAnyActiveElement = useCloseAnyActiveElement() const {importantForAccessibility} = useDialogStateContext() // start undefined const currentAccountDid = React.useRef(undefined) React.useEffect(() => { let listener = {remove() {}} if (isAndroid) { listener = BackHandler.addEventListener('hardwareBackPress', () => { return closeAnyActiveElement() }) } return () => { listener.remove() } }, [closeAnyActiveElement]) React.useEffect(() => { // only runs when did changes if (currentAccount && currentAccountDid.current !== currentAccount.did) { currentAccountDid.current = currentAccount.did notifications.requestPermissionsAndRegisterToken(currentAccount) const unsub = notifications.registerTokenChangeHandler(currentAccount) return unsub } }, [currentAccount]) return ( <> ) } export const Shell: React.FC = function ShellImpl() { const pal = usePalette('default') const theme = useTheme() return ( ) } const styles = StyleSheet.create({ outerContainer: { height: '100%', }, })