Skip to content

Commit be626ce

Browse files
author
Nur Fikri
committed
simplify the ThemeProvider, add more colors
1 parent 7c6b5cf commit be626ce

File tree

14 files changed

+51
-23
lines changed

14 files changed

+51
-23
lines changed

constants/theme.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,9 @@
9898
"gray500": "#6c6c6c",
9999
"white": "#FFFFFF",
100100
"white100": "#f7f7f7",
101-
"white200": "#e6e6e6"
101+
"white200": "#e6e6e6",
102+
"dark" : "#191921",
103+
"dark100": "#383b4d",
104+
"dark200": "#262834"
105+
102106
}

examples/showcase/App.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import React from "react";
2-
import { ThemeProvider, useTheme } from "react-native-rapi-ui";
2+
import { ThemeProvider } from "react-native-rapi-ui";
33
import Navigator from "./src/navigation";
44
import { enableScreens } from "react-native-screens";
55
export default function App() {
66
enableScreens();
7-
const { setTheme } = useTheme();
87

98
return (
10-
<ThemeProvider theme="light" setTheme={setTheme}>
9+
<ThemeProvider>
1110
<Navigator />
1211
</ThemeProvider>
1312
);

examples/showcase/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/showcase/src/rapi/constants/theme.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,9 @@
9898
"gray500": "#6c6c6c",
9999
"white": "#FFFFFF",
100100
"white100": "#f7f7f7",
101-
"white200": "#e6e6e6"
101+
"white200": "#e6e6e6",
102+
"dark" : "#191921",
103+
"dark100": "#383b4d",
104+
"dark200": "#262834"
105+
102106
}

examples/showcase/src/rapi/provider/ThemeProvider.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,36 @@ const ThemeContext = React.createContext<ContextProps>({
1919

2020
const useTheme = () => React.useContext(ThemeContext);
2121

22-
const ThemeProvider: React.FC<ContextProps> = (props) => {
22+
const ThemeProvider = (props: {
23+
theme?: "light" | "dark";
24+
isDarkmode?: boolean;
25+
images?: Array<any> | null;
26+
fonts?: any;
27+
children?: React.ReactNode;
28+
loading?: React.ReactNode;
29+
}) => {
2330
const [theme, setTheme] = React.useState<"light" | "dark">(
2431
props.theme || "light"
2532
);
2633
const isLoadingComplete = useCachedResources(props.images, props.fonts);
2734
const isDarkmode = theme === "dark";
2835

2936
return (
30-
<ThemeContext.Provider value={{ theme, setTheme, isDarkmode }}>
37+
<ThemeContext.Provider value={{ theme, isDarkmode, setTheme }}>
3138
<StatusBar
3239
backgroundColor={component[theme].statusBar.color}
3340
barStyle={isDarkmode ? "light-content" : "dark-content"}
3441
/>
3542
<SafeAreaProvider
3643
style={{
37-
backgroundColor: isDarkmode ? "#191921" : themeColor.white100,
44+
backgroundColor: isDarkmode ? themeColor.dark : themeColor.white100,
3845
}}
3946
>
40-
{!isLoadingComplete ? null : props.children}
47+
{!isLoadingComplete
48+
? props.loading
49+
? props.loading
50+
: null
51+
: props.children}
4152
</SafeAreaProvider>
4253
</ThemeContext.Provider>
4354
);

examples/showcase/src/screens/Avatar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function ({
3434
<Ionicons
3535
name={isDarkmode ? "sunny" : "moon"}
3636
size={20}
37-
color={isDarkmode ? themeColor.white100 : "#191921"}
37+
color={isDarkmode ? themeColor.white100 : themeColor.dark}
3838
/>
3939
}
4040
rightAction={() => {

examples/showcase/src/screens/Buttons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function ({
3434
<Ionicons
3535
name={isDarkmode ? "sunny" : "moon"}
3636
size={20}
37-
color={isDarkmode ? themeColor.white100 : "#191921"}
37+
color={isDarkmode ? themeColor.white100 : themeColor.dark}
3838
/>
3939
}
4040
rightAction={() => {

examples/showcase/src/screens/Colors.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default function ({
3232
<Ionicons
3333
name={isDarkmode ? "sunny" : "moon"}
3434
size={20}
35-
color={isDarkmode ? themeColor.white100 : "#191921"}
35+
color={isDarkmode ? themeColor.white100 : themeColor.dark}
3636
/>
3737
}
3838
rightAction={() => {

examples/showcase/src/screens/Forms.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function ({
5050
<Ionicons
5151
name={isDarkmode ? "sunny" : "moon"}
5252
size={20}
53-
color={isDarkmode ? themeColor.white100 : "#191921"}
53+
color={isDarkmode ? themeColor.white100 : themeColor.dark}
5454
/>
5555
}
5656
rightAction={() => {

examples/showcase/src/screens/Home.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
TopNav,
66
Text,
77
themeColor,
8-
Button,
98
useTheme,
109
} from "react-native-rapi-ui";
1110
import { Ionicons } from "@expo/vector-icons";
@@ -39,7 +38,7 @@ export default function ({
3938
<Ionicons
4039
name={isDarkmode ? "sunny" : "moon"}
4140
size={20}
42-
color={isDarkmode ? themeColor.white100 : "#191921"}
41+
color={isDarkmode ? themeColor.white100 : themeColor.dark}
4342
/>
4443
}
4544
rightAction={() => {

0 commit comments

Comments
 (0)