diff --git a/packages/mobile/src/App.tsx b/packages/mobile/src/App.tsx index f6a52073d..ff519aeee 100644 --- a/packages/mobile/src/App.tsx +++ b/packages/mobile/src/App.tsx @@ -9,7 +9,6 @@ import { MobileThemeVariables } from '@Root/Style/Themes/styled-components' import { ApplicationGroupEvent, DeinitMode, DeinitSource } from '@standardnotes/snjs' import { ThemeService, ThemeServiceContext } from '@Style/ThemeService' import React, { useCallback, useEffect, useRef, useState } from 'react' -import { StatusBar } from 'react-native' import { ThemeProvider } from 'styled-components/native' import { ApplicationContext } from './ApplicationContext' import { MainStackComponent } from './ModalStack' @@ -107,7 +106,6 @@ const AppComponent: React.FC<{ }} ref={navigationRef} > - {themeService.current && ( <> diff --git a/packages/mobile/src/AppStack.tsx b/packages/mobile/src/AppStack.tsx index d2ec25580..f7efc6d80 100644 --- a/packages/mobile/src/AppStack.tsx +++ b/packages/mobile/src/AppStack.tsx @@ -3,22 +3,22 @@ import { AlwaysOpenWebAppOnLaunchKey } from '@Lib/constants' import { useHasEditor, useIsLocked } from '@Lib/SnjsHelperHooks' import { ScreenStatus } from '@Lib/StatusManager' import { IsDev } from '@Lib/Utils' -import { CompositeNavigationProp, RouteProp, useNavigation } from '@react-navigation/native' +import { CompositeNavigationProp, RouteProp } from '@react-navigation/native' import { createStackNavigator, StackNavigationProp } from '@react-navigation/stack' import { HeaderTitleView } from '@Root/Components/HeaderTitleView' import { IoniconsHeaderButton } from '@Root/Components/IoniconsHeaderButton' import { Compose } from '@Root/Screens/Compose/Compose' -import { SCREEN_COMPOSE, SCREEN_NOTES, SCREEN_VIEW_PROTECTED_NOTE, SCREEN_WEB_APP } from '@Root/Screens/screens' +import { SCREEN_COMPOSE, SCREEN_NOTES, SCREEN_VIEW_PROTECTED_NOTE } from '@Root/Screens/screens' import { MainSideMenu } from '@Root/Screens/SideMenu/MainSideMenu' import { NoteSideMenu } from '@Root/Screens/SideMenu/NoteSideMenu' import { ViewProtectedNote } from '@Root/Screens/ViewProtectedNote/ViewProtectedNote' import { Root } from '@Screens/Root' -import { ApplicationEvent, StorageValueModes, UuidString } from '@standardnotes/snjs' +import { StorageValueModes, UuidString } from '@standardnotes/snjs' import { ICON_MENU } from '@Style/Icons' import { ThemeService } from '@Style/ThemeService' import { getDefaultDrawerWidth } from '@Style/Utils' import React, { useCallback, useContext, useEffect, useRef, useState } from 'react' -import { Dimensions, Keyboard, ScaledSize } from 'react-native' +import { Dimensions, Keyboard, ScaledSize, StatusBar } from 'react-native' import DrawerLayout, { DrawerState } from 'react-native-gesture-handler/DrawerLayout' import { HeaderButtons, Item } from 'react-navigation-header-buttons' import { ThemeContext } from 'styled-components' @@ -27,9 +27,6 @@ import { ApplicationContext } from './ApplicationContext' import { MobileWebAppContainer } from './MobileWebAppContainer' import { ModalStackNavigationProp } from './ModalStack' -const IS_DEBUGGING_WEB_APP = false -const DEFAULT_TO_WEB_APP = IsDev && IS_DEBUGGING_WEB_APP - export type AppStackNavigatorParamList = { [SCREEN_NOTES]: HeaderTitleParams [SCREEN_COMPOSE]: HeaderTitleParams & { @@ -124,28 +121,6 @@ export const AppStackComponent = (props: ModalStackNavigationProp<'AppStack'>) = [application], ) - const navigation = useNavigation['navigation']>() - - useEffect(() => { - if (!application) { - return - } - - const removeObserver = application.addEventObserver(async (event) => { - if (event === ApplicationEvent.Launched) { - const value = (await application.getValue(AlwaysOpenWebAppOnLaunchKey, StorageValueModes.Nonwrapped)) as - | boolean - | undefined - const shouldAlwaysOpenWebAppOnLaunch = value ?? false - if (shouldAlwaysOpenWebAppOnLaunch) { - navigation.push(SCREEN_WEB_APP) - } - } - }) - - return removeObserver - }, [application, navigation]) - if (IsDev) { return ( ) = })} initialRouteName={SCREEN_NOTES} > - + ) } + if (!application) { + return null + } + + const shouldOpenWebApp = application.getValue(AlwaysOpenWebAppOnLaunchKey, StorageValueModes.Nonwrapped) as boolean + return ( ) = onDrawerStateChanged={handleDrawerStateChange} renderNavigationView={() => !isLocked && } > + ) = name={SCREEN_NOTES} options={({ route }) => ({ title: 'All notes', + headerShown: !shouldOpenWebApp, headerTitle: ({ children }) => { const screenStatus = isInTabletMode ? composeStatus || notesStatus : notesStatus @@ -237,7 +220,7 @@ export const AppStackComponent = (props: ModalStackNavigationProp<'AppStack'>) = ), })} - component={DEFAULT_TO_WEB_APP ? MobileWebAppContainer : Root} + component={shouldOpenWebApp ? MobileWebAppContainer : Root} /> { ) }, [application.alertService]) - const [shouldAlwaysOpenWebAppOnLaunch, setShouldAlwaysOpenWebAppOnLaunch] = useState(false) - - useEffect(() => { - const getSetting = async () => { - const value = (await application.getValue(AlwaysOpenWebAppOnLaunchKey, StorageValueModes.Nonwrapped)) as - | boolean - | undefined - setShouldAlwaysOpenWebAppOnLaunch(value ?? false) - } - void getSetting() - }, [application]) - - const openWebApp = useCallback(() => { - navigation.push(SCREEN_WEB_APP) - }, [navigation]) - return ( @@ -238,15 +222,19 @@ export const OptionsSection = ({ title, encryptionAvailable }: Props) => { onPress={onExportPress} /> - openWebApp()} /> - { - const newValue = !shouldAlwaysOpenWebAppOnLaunch - setShouldAlwaysOpenWebAppOnLaunch(newValue) - void application.setValue(AlwaysOpenWebAppOnLaunchKey, newValue, StorageValueModes.Nonwrapped) + { + const confirmationText = + 'This will close the app and fully switch to the web view next time you open it. You will be able to switch back from the settings.' + + if ( + await application.alertService.confirm(confirmationText, 'Switch To Web View?', 'Switch', ButtonType.Info) + ) { + application.setValue(AlwaysOpenWebAppOnLaunchKey, true, StorageValueModes.Nonwrapped) + setTimeout(() => application.deviceInterface.performSoftReset(), 1000) + } }} - text="Always Open Web App On Launch" - selected={() => shouldAlwaysOpenWebAppOnLaunch} + title="Switch to Web View" /> {!signedIn && ( diff --git a/packages/web/src/javascripts/Components/ComponentView/ComponentView.tsx b/packages/web/src/javascripts/Components/ComponentView/ComponentView.tsx index 1d271d06f..aa9b1c301 100644 --- a/packages/web/src/javascripts/Components/ComponentView/ComponentView.tsx +++ b/packages/web/src/javascripts/Components/ComponentView/ComponentView.tsx @@ -200,7 +200,6 @@ const ComponentView: FunctionComponent = ({ application, onLoad, compone {error === ComponentViewerError.MissingUrl && } {component.uuid && isComponentValid && (