@hoddy-ui/core 1.0.95 → 1.0.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/theme/index.tsx +26 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hoddy-ui/core",
3
- "version": "1.0.95",
3
+ "version": "1.0.96",
4
4
  "description": "Core rich react native components written in typescript",
5
5
  "main": "index.ts",
6
6
  "repository": {
@@ -1,18 +1,18 @@
1
1
  import AsyncStorage from "@react-native-async-storage/async-storage";
2
2
  import * as NavigationBar from "expo-navigation-bar";
3
3
  import * as SystemUI from "expo-system-ui";
4
- import React, { createContext, useReducer, useState } from "react";
4
+ import React, { createContext, useEffect, useReducer } from "react";
5
5
  import { Platform, useColorScheme } from "react-native";
6
+ import { SafeAreaProvider } from "react-native-safe-area-context";
7
+ import FlashMessage from "../Components/FlashMessage";
8
+ import { useColors, useTheme } from "../hooks";
6
9
  import {
7
- FlashMessageProps,
8
10
  ThemeActionTypes,
9
11
  ThemeContext,
10
12
  ThemeProviderProps,
11
13
  ThemeState,
12
14
  ThemeTypes,
13
15
  } from "../types";
14
- import FlashMessage from "../Components/FlashMessage";
15
- import { SafeAreaProvider } from "react-native-safe-area-context";
16
16
 
17
17
  export const UIThemeContext = createContext<ThemeContext>({
18
18
  themeState: { mode: "default", value: "light" },
@@ -23,19 +23,6 @@ function themeReducer(
23
23
  { type, payload }: ThemeActionTypes
24
24
  ): ThemeState {
25
25
  // Platform
26
- if (payload === "dark" || type === "dark") {
27
- SystemUI.setBackgroundColorAsync("#000000");
28
- if (Platform.OS === "android") {
29
- NavigationBar.setButtonStyleAsync("light");
30
- NavigationBar.setBackgroundColorAsync("#000000");
31
- }
32
- } else {
33
- SystemUI.setBackgroundColorAsync("#ffffff");
34
- if (Platform.OS === "android") {
35
- NavigationBar.setButtonStyleAsync("dark");
36
- NavigationBar.setBackgroundColorAsync("#fff");
37
- }
38
- }
39
26
 
40
27
  switch (type) {
41
28
  case "dark":
@@ -49,6 +36,27 @@ function themeReducer(
49
36
  }
50
37
  }
51
38
 
39
+ const ConfigureSystemUI = () => {
40
+ const theme = useTheme();
41
+ const colors = useColors();
42
+
43
+ useEffect(() => {
44
+ if (colors) {
45
+ SystemUI.setBackgroundColorAsync(colors.white[1]);
46
+ NavigationBar.setBackgroundColorAsync(colors.white[1]);
47
+ }
48
+ if (Platform.OS === "android") {
49
+ if (theme === "dark") {
50
+ NavigationBar.setButtonStyleAsync("light");
51
+ } else {
52
+ NavigationBar.setButtonStyleAsync("dark");
53
+ }
54
+ }
55
+ }, [colors, theme]);
56
+
57
+ return <></>;
58
+ };
59
+
52
60
  export const UIThemeProvider = ({ children }: ThemeProviderProps) => {
53
61
  const [themeState, themeDispatch] = useReducer(themeReducer, {
54
62
  mode: "default",
@@ -87,6 +95,7 @@ export const UIThemeProvider = ({ children }: ThemeProviderProps) => {
87
95
  >
88
96
  {children}
89
97
  <FlashMessage />
98
+ <ConfigureSystemUI />
90
99
  </UIThemeContext.Provider>
91
100
  </SafeAreaProvider>
92
101
  );