index.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {
  2. Platform
  3. } from "react-native";
  4. import Navigation from "./navigation";
  5. import defaultLocaleJSON from "./variants/locales/default.json";
  6. import defaultThemeJSON from "./variants/themes/default.json";
  7. import {
  8. type NCoreUIKitConfig,
  9. setupNCoreUIKit,
  10. Host
  11. } from "ncore-ui-kit";
  12. import {
  13. useFonts
  14. } from "expo-font";
  15. import moment from "moment";
  16. import "moment/locale/tr";
  17. let NCoreConfig: NCoreUIKitConfig = {
  18. projectThemes: defaultThemeJSON as NCoreUIKit.Palette,
  19. initialSelectedGapPropagation: "spacious",
  20. projectLocales: defaultLocaleJSON,
  21. initialSelectedPalette: "nibgat",
  22. initialSelectedTheme: "light"
  23. };
  24. const themeStorage = Platform.OS === "web" ? window.localStorage.getItem("theme") : null;
  25. if(themeStorage) {
  26. const parsedThemeStorage = JSON.parse(themeStorage);
  27. NCoreConfig = {
  28. ...NCoreConfig,
  29. initialSelectedGapPropagation: parsedThemeStorage.activeGapPropagation,
  30. initialSelectedActiveSharpness: parsedThemeStorage.activeSharpness,
  31. initialSelectedTheme: parsedThemeStorage.activeTheme
  32. };
  33. }
  34. const localeStorage = Platform.OS === "web" ? window.localStorage.getItem("locale") : null;
  35. if(localeStorage) {
  36. const parsedLocaleStorage = JSON.parse(localeStorage);
  37. NCoreConfig = {
  38. ...NCoreConfig,
  39. initialSelectedLocale: parsedLocaleStorage.activeLocale
  40. };
  41. }
  42. if (Platform.OS === "web") {
  43. const urlParams = new URLSearchParams(window.location.search);
  44. const langParam = urlParams.get("lang");
  45. if (langParam) {
  46. const isValidLocale = defaultLocaleJSON.some(item => item.locale === langParam);
  47. if (isValidLocale) {
  48. NCoreConfig.initialSelectedLocale = langParam as keyof NCoreUIKit.LocaleKey;
  49. }
  50. }
  51. }
  52. const NCoreUIKitBase = setupNCoreUIKit(NCoreConfig);
  53. moment.locale("tr");
  54. const App = () => {
  55. return <Navigation/>;
  56. };
  57. const isExpo = typeof globalThis !== "undefined" && ("__expo" in globalThis || "Expo" in globalThis);
  58. const ContextAPI = () => {
  59. if(isExpo) {
  60. /* eslint-disable @typescript-eslint/no-require-imports */
  61. const [loaded] = useFonts({
  62. "Geist-ExtraLight": require("./assets/fonts/Geist-ExtraLight.ttf"),
  63. "Geist-ExtraBold": require("./assets/fonts/Geist-ExtraBold.ttf"),
  64. "Geist-SemiBold": require("./assets/fonts/Geist-SemiBold.ttf"),
  65. "Geist-Regular": require("./assets/fonts/Geist-Regular.ttf"),
  66. "Geist-Medium": require("./assets/fonts/Geist-Medium.ttf"),
  67. "Geist-Black": require("./assets/fonts/Geist-Black.ttf"),
  68. "Geist-Light": require("./assets/fonts/Geist-Light.ttf"),
  69. "Geist-Bold": require("./assets/fonts/Geist-Bold.ttf"),
  70. "Geist-Thin": require("./assets/fonts/Geist-Thin.ttf")
  71. });
  72. if (!loaded) return null;
  73. }
  74. return <NCoreUIKitBase.Provider>
  75. <Host
  76. name="main-header"
  77. >
  78. <App/>
  79. </Host>
  80. </NCoreUIKitBase.Provider>;
  81. };
  82. export default ContextAPI;