related-ui-components 1.9.7 → 1.9.9
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.
- package/lib/module/components/CustomIcon/CustomIcon.js +27 -0
- package/lib/module/components/CustomIcon/CustomIcon.js.map +1 -0
- package/lib/module/components/CustomIcon/index.js +5 -0
- package/lib/module/components/CustomIcon/index.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/theme/ThemeContext.js +22 -37
- package/lib/module/theme/ThemeContext.js.map +1 -1
- package/lib/typescript/src/components/CustomIcon/CustomIcon.d.ts +12 -0
- package/lib/typescript/src/components/CustomIcon/CustomIcon.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomIcon/index.d.ts +3 -0
- package/lib/typescript/src/components/CustomIcon/index.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +1 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/theme/ThemeContext.d.ts +6 -7
- package/lib/typescript/src/theme/ThemeContext.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/CustomIcon/CustomIcon.tsx +40 -0
- package/src/components/CustomIcon/index.ts +2 -0
- package/src/components/index.ts +2 -1
- package/src/theme/ThemeContext.tsx +27 -55
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { StyleSheet } from 'react-native';
|
|
5
|
+
import { Image } from 'expo-image';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const CustomIcon = ({
|
|
8
|
+
source,
|
|
9
|
+
size = 24,
|
|
10
|
+
color,
|
|
11
|
+
style
|
|
12
|
+
}) => {
|
|
13
|
+
const combinedStyle = StyleSheet.flatten([{
|
|
14
|
+
width: size,
|
|
15
|
+
height: size
|
|
16
|
+
}, color && {
|
|
17
|
+
tintColor: color
|
|
18
|
+
}, style]);
|
|
19
|
+
return /*#__PURE__*/_jsx(Image, {
|
|
20
|
+
source: source,
|
|
21
|
+
style: combinedStyle,
|
|
22
|
+
contentFit: "contain",
|
|
23
|
+
accessibilityRole: "image"
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export default CustomIcon;
|
|
27
|
+
//# sourceMappingURL=CustomIcon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","StyleSheet","Image","jsx","_jsx","CustomIcon","source","size","color","style","combinedStyle","flatten","width","height","tintColor","contentFit","accessibilityRole"],"sourceRoot":"..\\..\\..\\..\\src","sources":["components/CustomIcon/CustomIcon.tsx"],"mappings":";;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,UAAU,QAAQ,cAAc;AAEzC,SAASC,KAAK,QAAmB,YAAY;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAS9C,MAAMC,UAAqC,GAAGA,CAAC;EAC7CC,MAAM;EACNC,IAAI,GAAG,EAAE;EACTC,KAAK;EACLC;AACF,CAAC,KAAK;EACJ,MAAMC,aAAa,GAAGT,UAAU,CAACU,OAAO,CAAC,CACvC;IACEC,KAAK,EAAEL,IAAI;IACXM,MAAM,EAAEN;EACV,CAAC,EACDC,KAAK,IAAI;IAACM,SAAS,EAAEN;EAAK,CAAC,EAC3BC,KAAK,CACN,CAAC;EAEF,oBACEL,IAAA,CAACF,KAAK;IACJI,MAAM,EAAEA,MAAO;IACfG,KAAK,EAAEC,aAAc;IACrBK,UAAU,EAAC,SAAS;IACpBC,iBAAiB,EAAC;EAAO,CAC1B,CAAC;AAEN,CAAC;AAED,eAAeX,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["default","CustomIcon"],"sourceRoot":"..\\..\\..\\..\\src","sources":["components/CustomIcon/index.ts"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,UAAU,QAAO,iBAAc;AACnD,cAAc,iBAAc","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"..\\..\\..\\src","sources":["components/index.ts"],"mappings":";;AAAA,cAAc,iBAAQ;AACtB,cAAc,wBAAe;AAC7B,cAAe,mBAAU;AACzB,cAAc,mBAAU;AACxB,cAAc,sBAAa;AAC3B,cAAc,oBAAW;AACzB,cAAc,kBAAS;AACvB,cAAc,wBAAe;AAC7B,cAAc,kBAAS;AACvB,cAAc,6BAAoB;AAClC,cAAc,wBAAe;AAC7B,cAAc,0BAAiB;AAC/B,cAAc,kBAAS;AACvB,cAAc,sBAAa;AAC3B,cAAc,oBAAW;AACzB,cAAc,4BAAmB;AACjC,cAAc,mBAAU;AACxB,cAAc,qBAAY","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"..\\..\\..\\src","sources":["components/index.ts"],"mappings":";;AAAA,cAAc,iBAAQ;AACtB,cAAc,wBAAe;AAC7B,cAAe,mBAAU;AACzB,cAAc,mBAAU;AACxB,cAAc,sBAAa;AAC3B,cAAc,oBAAW;AACzB,cAAc,kBAAS;AACvB,cAAc,wBAAe;AAC7B,cAAc,kBAAS;AACvB,cAAc,6BAAoB;AAClC,cAAc,wBAAe;AAC7B,cAAc,0BAAiB;AAC/B,cAAc,kBAAS;AACvB,cAAc,sBAAa;AAC3B,cAAc,oBAAW;AACzB,cAAc,4BAAmB;AACjC,cAAc,mBAAU;AACxB,cAAc,qBAAY;AAC1B,cAAc,uBAAc","ignoreList":[]}
|
|
@@ -1,42 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React, { createContext, useContext, useState
|
|
4
|
-
import { I18nManager, useColorScheme } from "react-native";
|
|
5
|
-
import { lightTheme, darkTheme } from "./Colors.js";
|
|
3
|
+
import React, { createContext, useContext, useState } from "react";
|
|
4
|
+
import { I18nManager, useColorScheme } from "react-native";
|
|
5
|
+
import { lightTheme, darkTheme } from "./Colors.js";
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
export const ThemeContext = /*#__PURE__*/createContext({
|
|
8
8
|
theme: lightTheme,
|
|
9
|
-
isDark: false,
|
|
10
|
-
toggleTheme: () => console.warn("toggleTheme called outside of ThemeProvider"),
|
|
11
9
|
isRTL: I18nManager.isRTL,
|
|
12
|
-
|
|
10
|
+
isDark: useColorScheme() === "dark",
|
|
11
|
+
toggleTheme: () => {}
|
|
13
12
|
});
|
|
13
|
+
|
|
14
|
+
// Define props for ThemeProvider
|
|
15
|
+
|
|
16
|
+
// Provider component
|
|
14
17
|
export const RelatedProvider = ({
|
|
15
18
|
children,
|
|
16
19
|
customLightTheme,
|
|
17
20
|
customDarkTheme,
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
dark,
|
|
22
|
+
forceRTL
|
|
20
23
|
}) => {
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
setIsDark(initialDark);
|
|
27
|
-
}
|
|
28
|
-
}, [initialDark]);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
if (typeof initialRTL === "boolean") {
|
|
31
|
-
setIsRTLState(initialRTL);
|
|
32
|
-
}
|
|
33
|
-
}, [initialRTL]);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (initialDark === undefined) {
|
|
36
|
-
setIsDark(useColorScheme() === "dark");
|
|
37
|
-
}
|
|
38
|
-
}, [initialDark]);
|
|
39
|
-
const themes = React.useMemo(() => ({
|
|
24
|
+
const [isDark, setIsDark] = useState(dark || useColorScheme() === "dark");
|
|
25
|
+
const currentIsRTL = typeof forceRTL === "boolean" ? forceRTL : false;
|
|
26
|
+
|
|
27
|
+
// Allow custom themes to override defaults
|
|
28
|
+
const [themes, setThemes] = useState({
|
|
40
29
|
light: {
|
|
41
30
|
...lightTheme,
|
|
42
31
|
...customLightTheme
|
|
@@ -45,25 +34,21 @@ export const RelatedProvider = ({
|
|
|
45
34
|
...darkTheme,
|
|
46
35
|
...customDarkTheme
|
|
47
36
|
}
|
|
48
|
-
})
|
|
37
|
+
});
|
|
38
|
+
const toggleTheme = () => setIsDark(prev => !prev);
|
|
49
39
|
const currentTheme = isDark ? themes.dark : themes.light;
|
|
50
|
-
const toggleTheme = useCallback(() => {
|
|
51
|
-
setIsDark(prevIsDark => !prevIsDark);
|
|
52
|
-
}, []);
|
|
53
|
-
const setRTL = useCallback(rtlValue => {
|
|
54
|
-
setIsRTLState(rtlValue);
|
|
55
|
-
}, []);
|
|
56
40
|
const contextValue = {
|
|
57
41
|
theme: currentTheme,
|
|
42
|
+
isRTL: currentIsRTL,
|
|
58
43
|
isDark,
|
|
59
|
-
toggleTheme
|
|
60
|
-
isRTL,
|
|
61
|
-
setRTL
|
|
44
|
+
toggleTheme
|
|
62
45
|
};
|
|
63
46
|
return /*#__PURE__*/_jsx(ThemeContext.Provider, {
|
|
64
47
|
value: contextValue,
|
|
65
48
|
children: children
|
|
66
49
|
});
|
|
67
50
|
};
|
|
51
|
+
|
|
52
|
+
// Hook for easy access
|
|
68
53
|
export const useTheme = () => useContext(ThemeContext);
|
|
69
54
|
//# sourceMappingURL=ThemeContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","createContext","useContext","useState","
|
|
1
|
+
{"version":3,"names":["React","createContext","useContext","useState","I18nManager","useColorScheme","lightTheme","darkTheme","jsx","_jsx","ThemeContext","theme","isRTL","isDark","toggleTheme","RelatedProvider","children","customLightTheme","customDarkTheme","dark","forceRTL","setIsDark","currentIsRTL","themes","setThemes","light","prev","currentTheme","contextValue","Provider","value","useTheme"],"sourceRoot":"..\\..\\..\\src","sources":["theme/ThemeContext.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IACVC,aAAa,EACbC,UAAU,EACVC,QAAQ,QAGH,OAAO;AAEd,SAASC,WAAW,EAAEC,cAAc,QAAQ,cAAc;AAC1D,SAASC,UAAU,EAAaC,SAAS,QAAQ,aAAU;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAQ5D,OAAO,MAAMC,YAAY,gBAAGT,aAAa,CAAiB;EACxDU,KAAK,EAAEL,UAAU;EACjBM,KAAK,EAAER,WAAW,CAACQ,KAAK;EACxBC,MAAM,EAAER,cAAc,CAAC,CAAC,KAAK,MAAM;EACnCS,WAAW,EAAEA,CAAA,KAAM,CAAC;AACtB,CAAC,CAAC;;AAEF;;AASA;AACA,OAAO,MAAMC,eAA+C,GAAGA,CAAC;EAC9DC,QAAQ;EACRC,gBAAgB;EAChBC,eAAe;EACfC,IAAI;EACJC;AACF,CAAC,KAAK;EACJ,MAAM,CAACP,MAAM,EAAEQ,SAAS,CAAC,GAAGlB,QAAQ,CAClCgB,IAAI,IAAId,cAAc,CAAC,CAAC,KAAK,MAC/B,CAAC;EACD,MAAMiB,YAAY,GAAG,OAAOF,QAAQ,KAAK,SAAS,GAAGA,QAAQ,GAAG,KAAK;;EAErE;EACA,MAAM,CAACG,MAAM,EAAEC,SAAS,CAAC,GAAGrB,QAAQ,CAAC;IACnCsB,KAAK,EAAE;MAAE,GAAGnB,UAAU;MAAE,GAAGW;IAAiB,CAAc;IAC1DE,IAAI,EAAE;MAAE,GAAGZ,SAAS;MAAE,GAAGW;IAAgB;EAC3C,CAAC,CAAC;EAEF,MAAMJ,WAAW,GAAGA,CAAA,KAAMO,SAAS,CAAEK,IAAI,IAAK,CAACA,IAAI,CAAC;EAEpD,MAAMC,YAAY,GAAGd,MAAM,GAAGU,MAAM,CAACJ,IAAI,GAAGI,MAAM,CAACE,KAAK;EAExD,MAAMG,YAA4B,GAAG;IACnCjB,KAAK,EAAEgB,YAAY;IACnBf,KAAK,EAAEU,YAAY;IACnBT,MAAM;IACNC;EACF,CAAC;EAED,oBACEL,IAAA,CAACC,YAAY,CAACmB,QAAQ;IAACC,KAAK,EAAEF,YAAa;IAAAZ,QAAA,EACxCA;EAAQ,CACY,CAAC;AAE5B,CAAC;;AAED;AACA,OAAO,MAAMe,QAAQ,GAAGA,CAAA,KAAM7B,UAAU,CAACQ,YAAY,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ImageSourcePropType, StyleProp } from 'react-native';
|
|
3
|
+
import { ImageStyle } from 'expo-image';
|
|
4
|
+
interface CustomIconProps {
|
|
5
|
+
source: ImageSourcePropType;
|
|
6
|
+
size?: number;
|
|
7
|
+
color?: string;
|
|
8
|
+
style?: StyleProp<ImageStyle>;
|
|
9
|
+
}
|
|
10
|
+
declare const CustomIcon: React.FC<CustomIconProps>;
|
|
11
|
+
export default CustomIcon;
|
|
12
|
+
//# sourceMappingURL=CustomIcon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomIcon.d.ts","sourceRoot":"","sources":["../../../../../src/components/CustomIcon/CustomIcon.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAS,UAAU,EAAC,MAAM,YAAY,CAAC;AAE9C,UAAU,eAAe;IACvB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;CAC/B;AAED,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAuBzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/CustomIcon/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAC,MAAM,cAAc,CAAC;AACpD,cAAc,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAe,UAAU,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAe,UAAU,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAA"}
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import React, { ReactNode } from "react";
|
|
2
2
|
import { ThemeType } from "./Colors";
|
|
3
|
-
interface
|
|
3
|
+
interface RelatedContext {
|
|
4
4
|
theme: ThemeType;
|
|
5
|
+
isRTL: boolean;
|
|
5
6
|
isDark: boolean;
|
|
6
7
|
toggleTheme: () => void;
|
|
7
|
-
isRTL: boolean;
|
|
8
|
-
setRTL: (rtl: boolean) => void;
|
|
9
8
|
}
|
|
10
|
-
export declare const ThemeContext: React.Context<
|
|
9
|
+
export declare const ThemeContext: React.Context<RelatedContext>;
|
|
11
10
|
interface RelatedProviderProps {
|
|
12
11
|
children: ReactNode;
|
|
13
12
|
customLightTheme?: Partial<ThemeType>;
|
|
14
13
|
customDarkTheme?: Partial<ThemeType>;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
dark?: boolean;
|
|
15
|
+
forceRTL?: boolean;
|
|
17
16
|
}
|
|
18
17
|
export declare const RelatedProvider: React.FC<RelatedProviderProps>;
|
|
19
|
-
export declare const useTheme: () =>
|
|
18
|
+
export declare const useTheme: () => RelatedContext;
|
|
20
19
|
export {};
|
|
21
20
|
//# sourceMappingURL=ThemeContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../../../src/theme/ThemeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,SAAS,
|
|
1
|
+
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../../../src/theme/ThemeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAKZ,SAAS,EACV,MAAM,OAAO,CAAC;AAGf,OAAO,EAAc,SAAS,EAAa,MAAM,UAAU,CAAC;AAE5D,UAAU,cAAc;IACtB,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB;AACD,eAAO,MAAM,YAAY,+BAKvB,CAAC;AAGH,UAAU,oBAAoB;IAC5B,QAAQ,EAAE,SAAS,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAGD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAkC1D,CAAC;AAGF,eAAO,MAAM,QAAQ,sBAAiC,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { StyleSheet } from 'react-native';
|
|
4
|
+
import type { ImageSourcePropType, StyleProp } from 'react-native';
|
|
5
|
+
import { Image, ImageStyle} from 'expo-image';
|
|
6
|
+
|
|
7
|
+
interface CustomIconProps {
|
|
8
|
+
source: ImageSourcePropType;
|
|
9
|
+
size?: number;
|
|
10
|
+
color?: string;
|
|
11
|
+
style?: StyleProp<ImageStyle>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const CustomIcon: React.FC<CustomIconProps> = ({
|
|
15
|
+
source,
|
|
16
|
+
size = 24,
|
|
17
|
+
color,
|
|
18
|
+
style,
|
|
19
|
+
}) => {
|
|
20
|
+
const combinedStyle = StyleSheet.flatten([
|
|
21
|
+
{
|
|
22
|
+
width: size,
|
|
23
|
+
height: size,
|
|
24
|
+
},
|
|
25
|
+
color && {tintColor: color},
|
|
26
|
+
style,
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Image
|
|
31
|
+
source={source}
|
|
32
|
+
style={combinedStyle}
|
|
33
|
+
contentFit="contain"
|
|
34
|
+
accessibilityRole="image"
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default CustomIcon;
|
|
40
|
+
|
package/src/components/index.ts
CHANGED
|
@@ -4,90 +4,61 @@ import React, {
|
|
|
4
4
|
useState,
|
|
5
5
|
useEffect,
|
|
6
6
|
ReactNode,
|
|
7
|
-
useCallback,
|
|
8
7
|
} from "react";
|
|
9
|
-
import { I18nManager, useColorScheme, Appearance } from "react-native"; // Added Appearance
|
|
10
|
-
import { lightTheme, ThemeType, darkTheme } from "./Colors"; // Assuming Colors.ts exists
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
import { I18nManager, useColorScheme } from "react-native";
|
|
10
|
+
import { lightTheme, ThemeType, darkTheme } from "./Colors";
|
|
11
|
+
|
|
12
|
+
interface RelatedContext {
|
|
13
13
|
theme: ThemeType;
|
|
14
|
-
isDark: boolean; // Expose isDark for components to know the mode
|
|
15
|
-
toggleTheme: () => void;
|
|
16
14
|
isRTL: boolean;
|
|
17
|
-
|
|
15
|
+
isDark: boolean,
|
|
16
|
+
toggleTheme: () => void;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
export const ThemeContext = createContext<RelatedContextValue>({
|
|
18
|
+
export const ThemeContext = createContext<RelatedContext>({
|
|
21
19
|
theme: lightTheme,
|
|
22
|
-
isDark: false,
|
|
23
|
-
toggleTheme: () => console.warn("toggleTheme called outside of ThemeProvider"),
|
|
24
20
|
isRTL: I18nManager.isRTL,
|
|
25
|
-
|
|
21
|
+
isDark: useColorScheme() === "dark",
|
|
22
|
+
toggleTheme: () => {}
|
|
26
23
|
});
|
|
27
24
|
|
|
25
|
+
// Define props for ThemeProvider
|
|
28
26
|
interface RelatedProviderProps {
|
|
29
27
|
children: ReactNode;
|
|
30
28
|
customLightTheme?: Partial<ThemeType>;
|
|
31
29
|
customDarkTheme?: Partial<ThemeType>;
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
dark?: boolean;
|
|
31
|
+
forceRTL?: boolean;
|
|
34
32
|
}
|
|
35
33
|
|
|
34
|
+
// Provider component
|
|
36
35
|
export const RelatedProvider: React.FC<RelatedProviderProps> = ({
|
|
37
36
|
children,
|
|
38
37
|
customLightTheme,
|
|
39
38
|
customDarkTheme,
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
dark,
|
|
40
|
+
forceRTL,
|
|
42
41
|
}) => {
|
|
43
|
-
const systemColorScheme = useColorScheme();
|
|
44
42
|
const [isDark, setIsDark] = useState<boolean>(
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const [isRTL, setIsRTLState] = useState<boolean>(
|
|
49
|
-
initialRTL ?? I18nManager.isRTL
|
|
43
|
+
dark || useColorScheme() === "dark"
|
|
50
44
|
);
|
|
45
|
+
const currentIsRTL = typeof forceRTL === "boolean" ? forceRTL : false;
|
|
51
46
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
setIsDark(initialDark);
|
|
55
|
-
}
|
|
56
|
-
}, [initialDark]);
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (typeof initialRTL === "boolean") {
|
|
60
|
-
setIsRTLState(initialRTL);
|
|
61
|
-
}
|
|
62
|
-
}, [initialRTL]);
|
|
63
|
-
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
if (initialDark === undefined) {
|
|
66
|
-
setIsDark(useColorScheme() === "dark");
|
|
67
|
-
}
|
|
68
|
-
}, [initialDark]);
|
|
69
|
-
|
|
70
|
-
const themes = React.useMemo(() => ({
|
|
47
|
+
// Allow custom themes to override defaults
|
|
48
|
+
const [themes, setThemes] = useState({
|
|
71
49
|
light: { ...lightTheme, ...customLightTheme } as ThemeType,
|
|
72
50
|
dark: { ...darkTheme, ...customDarkTheme } as ThemeType,
|
|
73
|
-
})
|
|
51
|
+
});
|
|
74
52
|
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const toggleTheme = useCallback(() => {
|
|
78
|
-
setIsDark(prevIsDark => !prevIsDark);
|
|
79
|
-
}, []);
|
|
53
|
+
const toggleTheme = () => setIsDark((prev) => !prev);
|
|
80
54
|
|
|
81
|
-
const
|
|
82
|
-
setIsRTLState(rtlValue);
|
|
83
|
-
}, []);
|
|
55
|
+
const currentTheme = isDark ? themes.dark : themes.light;
|
|
84
56
|
|
|
85
|
-
const contextValue:
|
|
57
|
+
const contextValue: RelatedContext = {
|
|
86
58
|
theme: currentTheme,
|
|
59
|
+
isRTL: currentIsRTL,
|
|
87
60
|
isDark,
|
|
88
|
-
toggleTheme
|
|
89
|
-
isRTL,
|
|
90
|
-
setRTL,
|
|
61
|
+
toggleTheme
|
|
91
62
|
};
|
|
92
63
|
|
|
93
64
|
return (
|
|
@@ -97,4 +68,5 @@ export const RelatedProvider: React.FC<RelatedProviderProps> = ({
|
|
|
97
68
|
);
|
|
98
69
|
};
|
|
99
70
|
|
|
100
|
-
|
|
71
|
+
// Hook for easy access
|
|
72
|
+
export const useTheme = () => useContext(ThemeContext);
|