2022-06-30 06:50:52 +00:00
|
|
|
import {
|
2023-11-13 04:33:32 +00:00
|
|
|
NavigationContainer,
|
2022-07-15 06:06:33 +00:00
|
|
|
DarkTheme as NavigationDarkTheme,
|
|
|
|
DefaultTheme as NavigationDefaultTheme,
|
2023-08-12 03:22:50 +00:00
|
|
|
} from "@react-navigation/native";
|
|
|
|
import React, { useEffect, useMemo, useState } from "react";
|
2023-09-04 02:20:36 +00:00
|
|
|
import { useColorScheme } from "react-native";
|
2022-07-06 09:03:56 +00:00
|
|
|
import {
|
2023-07-15 01:21:09 +00:00
|
|
|
MD3DarkTheme as PaperDarkTheme,
|
|
|
|
MD3LightTheme as PaperDefaultTheme,
|
2023-11-12 04:05:37 +00:00
|
|
|
Provider as PaperProvider,
|
2023-08-12 03:22:50 +00:00
|
|
|
} from "react-native-paper";
|
2023-10-19 05:28:56 +00:00
|
|
|
import MaterialIcon from "react-native-vector-icons/MaterialCommunityIcons";
|
2023-11-13 04:33:32 +00:00
|
|
|
import AppSnack from "./AppSnack";
|
2023-11-12 04:05:37 +00:00
|
|
|
import AppStack from "./AppStack";
|
2023-11-13 04:33:32 +00:00
|
|
|
import TimerProgress from "./TimerProgress";
|
2023-08-12 03:22:50 +00:00
|
|
|
import { AppDataSource } from "./data-source";
|
|
|
|
import { settingsRepo } from "./db";
|
|
|
|
import { ThemeContext } from "./use-theme";
|
2022-07-03 01:50:01 +00:00
|
|
|
|
2022-08-26 01:54:51 +00:00
|
|
|
export const CombinedDefaultTheme = {
|
2022-07-15 06:06:33 +00:00
|
|
|
...NavigationDefaultTheme,
|
2022-09-24 03:59:52 +00:00
|
|
|
...PaperDefaultTheme,
|
2022-07-15 06:06:33 +00:00
|
|
|
colors: {
|
|
|
|
...NavigationDefaultTheme.colors,
|
2022-09-24 03:59:52 +00:00
|
|
|
...PaperDefaultTheme.colors,
|
2022-07-15 06:06:33 +00:00
|
|
|
},
|
2023-08-12 03:22:50 +00:00
|
|
|
};
|
2022-10-14 04:24:02 +00:00
|
|
|
|
2022-08-26 01:54:51 +00:00
|
|
|
export const CombinedDarkTheme = {
|
2022-07-15 06:06:33 +00:00
|
|
|
...NavigationDarkTheme,
|
2022-09-24 03:59:52 +00:00
|
|
|
...PaperDarkTheme,
|
2022-07-15 06:06:33 +00:00
|
|
|
colors: {
|
|
|
|
...NavigationDarkTheme.colors,
|
2022-09-24 03:59:52 +00:00
|
|
|
...PaperDarkTheme.colors,
|
2022-07-15 06:06:33 +00:00
|
|
|
},
|
2023-08-12 03:22:50 +00:00
|
|
|
};
|
2022-07-15 06:06:33 +00:00
|
|
|
|
2022-07-01 01:42:42 +00:00
|
|
|
const App = () => {
|
2023-11-13 06:40:05 +00:00
|
|
|
const systemTheme = useColorScheme();
|
2022-11-01 03:11:39 +00:00
|
|
|
|
2023-11-13 04:33:32 +00:00
|
|
|
const [appSettings, setAppSettings] = useState({
|
|
|
|
startup: undefined,
|
|
|
|
theme: "system",
|
|
|
|
lightColor: CombinedDefaultTheme.colors.primary,
|
|
|
|
darkColor: CombinedDarkTheme.colors.primary,
|
|
|
|
});
|
2022-11-26 00:15:12 +00:00
|
|
|
|
2022-10-04 01:35:56 +00:00
|
|
|
useEffect(() => {
|
2023-08-12 03:22:50 +00:00
|
|
|
(async () => {
|
|
|
|
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
2023-11-12 10:27:28 +00:00
|
|
|
const gotSettings = await settingsRepo.findOne({ where: {} });
|
|
|
|
console.log({ gotSettings });
|
2023-11-13 04:33:32 +00:00
|
|
|
setAppSettings({
|
|
|
|
startup: gotSettings.startup,
|
|
|
|
theme: gotSettings.theme,
|
|
|
|
lightColor: gotSettings.lightColor,
|
|
|
|
darkColor: gotSettings.darkColor,
|
|
|
|
});
|
2023-08-12 03:22:50 +00:00
|
|
|
})();
|
|
|
|
}, []);
|
2022-10-04 01:35:56 +00:00
|
|
|
|
2022-11-01 03:50:03 +00:00
|
|
|
const paperTheme = useMemo(() => {
|
2023-11-13 06:40:05 +00:00
|
|
|
const darkTheme = {
|
|
|
|
...CombinedDarkTheme,
|
|
|
|
colors: {
|
|
|
|
...CombinedDarkTheme.colors,
|
|
|
|
primary: appSettings.darkColor,
|
|
|
|
},
|
|
|
|
dark: true,
|
|
|
|
};
|
|
|
|
const lightTheme = {
|
|
|
|
...CombinedDefaultTheme,
|
|
|
|
colors: {
|
|
|
|
...CombinedDefaultTheme.colors,
|
|
|
|
primary: appSettings.lightColor,
|
|
|
|
},
|
|
|
|
dark: false,
|
|
|
|
};
|
|
|
|
let theme = systemTheme === "dark" ? darkTheme : lightTheme;
|
|
|
|
if (appSettings.theme === "dark") theme = darkTheme;
|
|
|
|
else if (appSettings.theme === "light") theme = lightTheme;
|
|
|
|
return theme;
|
|
|
|
}, [systemTheme, appSettings]);
|
2022-11-01 03:08:02 +00:00
|
|
|
|
2022-06-30 06:50:52 +00:00
|
|
|
return (
|
2022-10-31 08:32:33 +00:00
|
|
|
<PaperProvider
|
2022-11-01 03:50:03 +00:00
|
|
|
theme={paperTheme}
|
2023-06-27 03:16:59 +00:00
|
|
|
settings={{ icon: (props) => <MaterialIcon {...props} /> }}
|
|
|
|
>
|
2022-11-01 03:50:03 +00:00
|
|
|
<NavigationContainer theme={paperTheme}>
|
2023-11-13 04:33:32 +00:00
|
|
|
{appSettings.startup !== undefined && (
|
2022-11-26 00:15:12 +00:00
|
|
|
<ThemeContext.Provider
|
|
|
|
value={{
|
2023-11-13 04:33:32 +00:00
|
|
|
theme: appSettings.theme,
|
|
|
|
setTheme: (theme) => setAppSettings({ ...appSettings, theme }),
|
|
|
|
lightColor: appSettings.lightColor,
|
|
|
|
setLightColor: (color) =>
|
|
|
|
setAppSettings({ ...appSettings, lightColor: color }),
|
|
|
|
darkColor: appSettings.darkColor,
|
|
|
|
setDarkColor: (color) =>
|
|
|
|
setAppSettings({ ...appSettings, darkColor: color }),
|
2023-06-27 03:16:59 +00:00
|
|
|
}}
|
|
|
|
>
|
2023-11-13 04:33:32 +00:00
|
|
|
<AppStack startup={appSettings.startup} />
|
2022-11-01 03:50:03 +00:00
|
|
|
</ThemeContext.Provider>
|
2022-11-01 02:55:37 +00:00
|
|
|
)}
|
2022-10-31 08:32:33 +00:00
|
|
|
</NavigationContainer>
|
2022-11-01 02:55:37 +00:00
|
|
|
|
2023-11-13 04:33:32 +00:00
|
|
|
<AppSnack textColor={paperTheme.colors.background} />
|
|
|
|
<TimerProgress />
|
2022-10-31 08:32:33 +00:00
|
|
|
</PaperProvider>
|
2023-08-12 03:22:50 +00:00
|
|
|
);
|
|
|
|
};
|
2022-06-30 06:50:52 +00:00
|
|
|
|
2023-08-12 03:22:50 +00:00
|
|
|
export default App;
|