2023-05-18 21:09:33 +00:00
|
|
|
import React, { useEffect, useLayoutEffect, useState } from 'react';
|
2020-06-26 20:22:56 +00:00
|
|
|
import { Dimensions } from 'react-native';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { NavigationContainer } from '@react-navigation/native';
|
2019-07-18 17:44:02 +00:00
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
|
2023-05-18 21:09:33 +00:00
|
|
|
import { getTheme, setNativeTheme, initialTheme as initialThemeFunction } from './lib/methods/helpers/theme';
|
2022-04-07 13:13:19 +00:00
|
|
|
import UserPreferences from './lib/methods/userPreferences';
|
2022-04-07 13:22:19 +00:00
|
|
|
import Navigation from './lib/navigation/shareNavigation';
|
2022-04-07 14:19:54 +00:00
|
|
|
import store from './lib/store';
|
|
|
|
import { initStore } from './lib/store/auxStore';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { closeShareExtension, shareExtensionInit } from './lib/methods/shareExtension';
|
2023-05-18 21:09:33 +00:00
|
|
|
import { getActiveRouteName, navigationTheme } from './lib/methods/helpers/navigation';
|
2022-08-18 23:25:39 +00:00
|
|
|
import { ThemeContext } from './theme';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { localAuthenticate } from './lib/methods/helpers/localAuthentication';
|
2020-05-08 17:04:37 +00:00
|
|
|
import ScreenLockedView from './views/ScreenLockedView';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { setCurrentScreen } from './lib/methods/helpers/log';
|
2020-06-26 20:22:56 +00:00
|
|
|
import { DimensionsContext } from './dimensions';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { colors, CURRENT_SERVER } from './lib/constants';
|
2022-08-19 21:14:37 +00:00
|
|
|
import Loading from './containers/Loading';
|
2023-05-18 21:09:33 +00:00
|
|
|
import ShareExtensionStack from './stacks/ShareExtensionStack';
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2022-02-09 21:16:20 +00:00
|
|
|
initStore(store);
|
|
|
|
|
2022-08-18 23:25:39 +00:00
|
|
|
const { width, height, scale, fontScale } = Dimensions.get('screen');
|
|
|
|
const initialTheme = initialThemeFunction();
|
|
|
|
const theme = getTheme(initialTheme);
|
2019-07-29 16:33:28 +00:00
|
|
|
|
2022-08-18 23:25:39 +00:00
|
|
|
const Root = (): React.ReactElement => {
|
|
|
|
const [root, setRoot] = useState('');
|
|
|
|
const navTheme = navigationTheme(theme);
|
2022-05-27 17:11:26 +00:00
|
|
|
|
2022-08-18 23:25:39 +00:00
|
|
|
useLayoutEffect(() => {
|
|
|
|
setNativeTheme(initialTheme);
|
|
|
|
}, []);
|
2019-12-04 16:39:53 +00:00
|
|
|
|
2022-08-18 23:25:39 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const authenticateShare = async (currentServer: string) => {
|
2020-05-08 17:04:37 +00:00
|
|
|
await localAuthenticate(currentServer);
|
2022-08-18 23:25:39 +00:00
|
|
|
setRoot('inside');
|
2022-03-16 20:40:32 +00:00
|
|
|
await shareExtensionInit(currentServer);
|
2022-08-18 23:25:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const currentServer = UserPreferences.getString(CURRENT_SERVER);
|
|
|
|
if (currentServer) {
|
|
|
|
authenticateShare(currentServer);
|
2022-05-27 17:11:26 +00:00
|
|
|
} else {
|
2022-08-18 23:25:39 +00:00
|
|
|
setRoot('outside');
|
2019-07-29 16:33:28 +00:00
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2020-07-02 17:10:11 +00:00
|
|
|
const state = Navigation.navigationRef.current?.getRootState();
|
2020-06-15 14:00:46 +00:00
|
|
|
const currentRouteName = getActiveRouteName(state);
|
|
|
|
Navigation.routeNameRef.current = currentRouteName;
|
|
|
|
setCurrentScreen(currentRouteName);
|
2019-12-04 16:39:53 +00:00
|
|
|
|
2022-08-18 23:25:39 +00:00
|
|
|
return () => {
|
|
|
|
closeShareExtension();
|
|
|
|
};
|
|
|
|
}, []);
|
2020-06-26 20:22:56 +00:00
|
|
|
|
2022-08-18 23:25:39 +00:00
|
|
|
return (
|
|
|
|
<Provider store={store}>
|
|
|
|
<ThemeContext.Provider value={{ theme, colors: colors[theme] }}>
|
|
|
|
<DimensionsContext.Provider
|
|
|
|
value={{
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
scale,
|
|
|
|
fontScale
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<NavigationContainer
|
|
|
|
theme={navTheme}
|
|
|
|
ref={Navigation.navigationRef}
|
|
|
|
onStateChange={state => {
|
|
|
|
const previousRouteName = Navigation.routeNameRef.current;
|
|
|
|
const currentRouteName = getActiveRouteName(state);
|
|
|
|
if (previousRouteName !== currentRouteName) {
|
|
|
|
setCurrentScreen(currentRouteName);
|
|
|
|
}
|
|
|
|
Navigation.routeNameRef.current = currentRouteName;
|
2022-08-08 21:02:08 +00:00
|
|
|
}}
|
|
|
|
>
|
2023-05-18 21:09:33 +00:00
|
|
|
<ShareExtensionStack root={root} />
|
2022-08-19 21:14:37 +00:00
|
|
|
<Loading />
|
2022-08-18 23:25:39 +00:00
|
|
|
</NavigationContainer>
|
|
|
|
<ScreenLockedView />
|
|
|
|
</DimensionsContext.Provider>
|
|
|
|
</ThemeContext.Provider>
|
|
|
|
</Provider>
|
|
|
|
);
|
|
|
|
};
|
2019-07-18 17:44:02 +00:00
|
|
|
|
|
|
|
export default Root;
|