@codeandmoney/soelma 0.0.0-dev.1 → 0.0.0-dev.10

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 (170) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +27 -0
  3. package/.github/workflows/nodejs.yml +33 -0
  4. package/.size-limit.json +6 -0
  5. package/babel.config.js +3 -0
  6. package/biome.jsonc +73 -0
  7. package/docs/api.md +103 -0
  8. package/docs/appearance.md +54 -0
  9. package/docs/dark-mode.md +46 -0
  10. package/docs/dimensions.md +29 -0
  11. package/docs/i18n.md +67 -0
  12. package/docs/logo.png +0 -0
  13. package/docs/media-query.md +274 -0
  14. package/docs/orientation.md +44 -0
  15. package/docs/safe-area.md +62 -0
  16. package/docs/testting.md +51 -0
  17. package/docs/ts.md +127 -0
  18. package/example/AppStyleX/.watchmanconfig +1 -0
  19. package/example/AppStyleX/android/build.gradle +26 -0
  20. package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  21. package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.properties +7 -0
  22. package/example/AppStyleX/android/gradle.properties +53 -0
  23. package/example/AppStyleX/android/gradlew +249 -0
  24. package/example/AppStyleX/android/gradlew.bat +92 -0
  25. package/example/AppStyleX/android/settings.gradle +12 -0
  26. package/example/AppStyleX/app.json +16 -0
  27. package/example/AppStyleX/babel.config.js +3 -0
  28. package/example/AppStyleX/index.js +9 -0
  29. package/example/AppStyleX/ios/Podfile +7 -0
  30. package/example/AppStyleX/ios/Podfile.lock +1252 -0
  31. package/example/AppStyleX/metro.config.js +51 -0
  32. package/example/AppStyleX/package.json +43 -0
  33. package/example/AppStyleX/react-native.config.js +23 -0
  34. package/example/AppStyleX/src/App.tsx +22 -0
  35. package/example/AppStyleX/src/BottomNav/index.tsx +26 -0
  36. package/example/AppStyleX/src/BottomNav/styles.ts +42 -0
  37. package/example/AppStyleX/src/Circle/index.tsx +53 -0
  38. package/example/AppStyleX/src/Circle/styles.ts +22 -0
  39. package/example/AppStyleX/src/Root/index.tsx +35 -0
  40. package/example/AppStyleX/src/Root/styles.ts +18 -0
  41. package/example/AppStyleX/src/ToggleButton/index.tsx +52 -0
  42. package/example/AppStyleX/src/ToggleButton/styles.ts +67 -0
  43. package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +5 -0
  44. package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +5 -0
  45. package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +8 -0
  46. package/example/AppStyleX/src/style-system/palette.ts +11 -0
  47. package/example/AppStyleX/src/style-system/theme.ts +14 -0
  48. package/example/AppStyleX/src/style-system/utils.ts +8 -0
  49. package/example/AppStyleX/src/stylex.d.ts +6 -0
  50. package/example/AppStyleX/tsconfig.json +3 -0
  51. package/example/AppStyleX/yarn.lock +6767 -0
  52. package/jest.config.js +19 -0
  53. package/package.json +38 -3
  54. package/src/appearance/index.ts +30 -0
  55. package/src/appearance/init.ts +12 -0
  56. package/{context.js → src/context.ts} +4 -1
  57. package/src/create-event-emitter.ts +26 -0
  58. package/src/dark-mode/index.ts +26 -0
  59. package/src/dark-mode/init.ts +19 -0
  60. package/{dark-mode/state.js → src/dark-mode/state.ts} +2 -1
  61. package/src/default-theme.ts +4 -0
  62. package/src/dependency-registry.ts +21 -0
  63. package/src/dependency-usage.ts +21 -0
  64. package/src/dimensions/index.ts +20 -0
  65. package/src/dimensions/init.ts +32 -0
  66. package/src/dimensions/utils.ts +9 -0
  67. package/src/i18n.ts +15 -0
  68. package/src/index.ts +7 -0
  69. package/{makeUseStyles/createUseStylesTheme.js → src/make-use-styles/create-use-styles-theme.js} +23 -6
  70. package/src/make-use-styles/create-use-styles-theme.test.js +137 -0
  71. package/{makeUseStyles/createUseStylesWithoutTheme.js → src/make-use-styles/create-use-styles-without-theme.js} +20 -4
  72. package/src/make-use-styles/create-use-styles-without-theme.test.js +63 -0
  73. package/src/make-use-styles/index.d.ts +20 -0
  74. package/src/make-use-styles/index.js +12 -0
  75. package/src/make-use-styles/index.test.js +28 -0
  76. package/src/make-use-styles/types.ts +43 -0
  77. package/{makeUseStyles → src/make-use-styles}/utils.js +5 -10
  78. package/src/media-query/base.ts +32 -0
  79. package/src/media-query/breakpoints.ts +96 -0
  80. package/src/media-query/index.ts +12 -0
  81. package/src/orientation.ts +13 -0
  82. package/{safe-area/eventEmitter.js → src/safe-area/event-emitter.ts} +2 -1
  83. package/src/safe-area/index.tsx +16 -0
  84. package/src/safe-area/init.tsx +6 -0
  85. package/src/safe-area/safe-area-provider.tsx +18 -0
  86. package/{safe-area/state.js → src/safe-area/state.ts} +7 -5
  87. package/src/safe-area/stylex-save-area-consumer.ts +22 -0
  88. package/{safe-area/types.d.ts → src/safe-area/types.ts} +7 -6
  89. package/src/tests/createBreakpoints.test.ts +152 -0
  90. package/src/tests/createBreakpointsMatcher.test.ts +188 -0
  91. package/src/tests/createBreakpointsMatcher.types-test.ts +81 -0
  92. package/src/tests/createEventEmitter.test.ts +37 -0
  93. package/src/tests/dark-mode.test.ts +56 -0
  94. package/src/tests/dependencyRegistry.test.ts +16 -0
  95. package/src/tests/dependencyUsage.test.ts +13 -0
  96. package/src/tests/dimensions.test.ts +33 -0
  97. package/src/tests/makeUseStyles.types-test.ts +69 -0
  98. package/src/tests/media-query.test.ts +196 -0
  99. package/src/tests/orientation.test.ts +61 -0
  100. package/src/tests/useTheme.test.ts +26 -0
  101. package/src/tests/withStyles.types-test.tsx +172 -0
  102. package/src/use-color-transition.ts +50 -0
  103. package/src/use-theme.ts +14 -0
  104. package/src/with-styles.tsx +22 -0
  105. package/tsconfig.build.json +31 -0
  106. package/tsconfig.json +30 -0
  107. package/DefaultTheme.d.ts +0 -2
  108. package/DefaultTheme.js +0 -1
  109. package/appearance/consts.d.ts +0 -1
  110. package/appearance/index.d.ts +0 -8
  111. package/appearance/index.js +0 -18
  112. package/appearance/init.d.ts +0 -1
  113. package/appearance/init.js +0 -7
  114. package/context.d.ts +0 -4
  115. package/createEventEmitter.d.ts +0 -8
  116. package/createEventEmitter.js +0 -11
  117. package/dark-mode/consts.d.ts +0 -1
  118. package/dark-mode/index.d.ts +0 -7
  119. package/dark-mode/index.js +0 -16
  120. package/dark-mode/init.d.ts +0 -1
  121. package/dark-mode/init.js +0 -13
  122. package/dark-mode/state.d.ts +0 -3
  123. package/dependencyRegistry.d.ts +0 -5
  124. package/dependencyRegistry.js +0 -12
  125. package/dependencyUsage.d.ts +0 -7
  126. package/dependencyUsage.js +0 -10
  127. package/dimensions/consts.d.ts +0 -2
  128. package/dimensions/index.d.ts +0 -4
  129. package/dimensions/index.js +0 -13
  130. package/dimensions/init.d.ts +0 -1
  131. package/dimensions/init.js +0 -21
  132. package/dimensions/utils.d.ts +0 -1
  133. package/dimensions/utils.js +0 -7
  134. package/i18n.d.ts +0 -7
  135. package/i18n.js +0 -9
  136. package/index.d.ts +0 -7
  137. package/index.js +0 -5
  138. package/makeUseStyles/index.d.ts +0 -7
  139. package/makeUseStyles/index.js +0 -12
  140. package/media-query/base.d.ts +0 -12
  141. package/media-query/base.js +0 -18
  142. package/media-query/breakpoints.d.ts +0 -18
  143. package/media-query/breakpoints.js +0 -60
  144. package/media-query/index.d.ts +0 -2
  145. package/media-query/index.js +0 -2
  146. package/orientation.d.ts +0 -7
  147. package/orientation.js +0 -7
  148. package/safe-area/SafeAreaProvider.d.ts +0 -3
  149. package/safe-area/SafeAreaProvider.js +0 -9
  150. package/safe-area/StylexSaveAreaConsumer.d.ts +0 -2
  151. package/safe-area/StylexSaveAreaConsumer.js +0 -15
  152. package/safe-area/consts.d.ts +0 -1
  153. package/safe-area/eventEmitter.d.ts +0 -1
  154. package/safe-area/index.d.ts +0 -5
  155. package/safe-area/index.js +0 -10
  156. package/safe-area/init.d.ts +0 -1
  157. package/safe-area/init.js +0 -4
  158. package/safe-area/state.d.ts +0 -8
  159. package/safe-area/types.js +0 -1
  160. package/useColorTransition.d.ts +0 -5
  161. package/useColorTransition.js +0 -38
  162. package/useTheme.d.ts +0 -2
  163. package/useTheme.js +0 -9
  164. package/withStyles.d.ts +0 -7
  165. package/withStyles.js +0 -13
  166. /package/{appearance/consts.js → src/appearance/consts.ts} +0 -0
  167. /package/{dark-mode/consts.js → src/dark-mode/consts.ts} +0 -0
  168. /package/{dimensions/consts.js → src/dimensions/consts.ts} +0 -0
  169. /package/{makeUseStyles → src/make-use-styles}/test-type.js +0 -0
  170. /package/{safe-area/consts.js → src/safe-area/consts.ts} +0 -0
@@ -0,0 +1,61 @@
1
+ import { landscapeOrientation, portraitOrientation } from "../orientation";
2
+
3
+ import { Dimensions } from "react-native";
4
+
5
+ const mockStyle = { color: "black" };
6
+
7
+ const mockGetDimensions = (dimensions: any) => {
8
+ Dimensions.get = () => dimensions;
9
+ };
10
+
11
+ describe("landscapeOrientation", () => {
12
+ it("should return style when screen height less than width", () => {
13
+ const dimensions = { height: 1, width: 2 };
14
+
15
+ mockGetDimensions(dimensions);
16
+
17
+ expect(landscapeOrientation(mockStyle)).toEqual(mockStyle);
18
+ });
19
+
20
+ it("should return 'undefined' when screen height equal width", () => {
21
+ const dimensions = { height: 1, width: 1 };
22
+
23
+ mockGetDimensions(dimensions);
24
+
25
+ expect(landscapeOrientation(mockStyle)).toBeUndefined();
26
+ });
27
+
28
+ it("should return 'null' when screen height more than width", () => {
29
+ const dimensions = { height: 2, width: 1 };
30
+
31
+ mockGetDimensions(dimensions);
32
+
33
+ expect(landscapeOrientation(mockStyle)).toBeUndefined();
34
+ });
35
+ });
36
+
37
+ describe("portraitOrientation", () => {
38
+ it("should return 'undefined' when screen height less than width", () => {
39
+ const dimensions = { height: 1, width: 2 };
40
+
41
+ mockGetDimensions(dimensions);
42
+
43
+ expect(portraitOrientation(mockStyle)).toBeUndefined();
44
+ });
45
+
46
+ it("should return 'mockStyle' when screen height equal width", () => {
47
+ const dimensions = { height: 1, width: 1 };
48
+
49
+ mockGetDimensions(dimensions);
50
+
51
+ expect(portraitOrientation(mockStyle)).toEqual(mockStyle);
52
+ });
53
+
54
+ it("should return 'mockStyle' when screen height more than width", () => {
55
+ const dimensions = { height: 2, width: 1 };
56
+
57
+ mockGetDimensions(dimensions);
58
+
59
+ expect(portraitOrientation(mockStyle)).toEqual(mockStyle);
60
+ });
61
+ });
@@ -0,0 +1,26 @@
1
+ import { renderHook } from "@testing-library/react-hooks";
2
+ import { useTheme } from "../use-theme";
3
+ import { ThemeProvider } from "../context";
4
+
5
+ it("should throw an error when context value wasn't passed", () => {
6
+ expect(() => {
7
+ const { result } = renderHook(() => useTheme());
8
+
9
+ // trigger invoking passed hook
10
+ result.current;
11
+ }).toThrow();
12
+ });
13
+
14
+ it("should not throw an error", () => {
15
+ const theme = { test: "theme" };
16
+
17
+ expect(() => {
18
+ const { result } = renderHook(() => useTheme(), {
19
+ wrapper: ThemeProvider,
20
+ initialProps: { value: theme },
21
+ });
22
+
23
+ // trigger invoking passed hook
24
+ result.current;
25
+ }).not.toThrow();
26
+ });
@@ -0,0 +1,172 @@
1
+ // @ts-nocheck
2
+
3
+ import { FC, forwardRef } from "react";
4
+ import { TextInput } from "react-native";
5
+ import { InferInjectedStyledProps, withStyles } from "../with-styles";
6
+ import { makeUseStyles } from "../make-use-styles";
7
+
8
+ {
9
+ const useStyles = makeUseStyles(() => ({
10
+ root: {
11
+ color: "red",
12
+ },
13
+ }));
14
+
15
+ interface Props extends InferInjectedStyledProps<typeof useStyles> {
16
+ a: boolean;
17
+ }
18
+
19
+ function Component(props: Props): React.JSX.Element | null {
20
+ props.styles.root.color = "";
21
+
22
+ // @ts-expect-error 'a' not exists
23
+ props.styles.a = {};
24
+
25
+ return null;
26
+ }
27
+
28
+ const ComponentWithStyles = withStyles(useStyles)(Component);
29
+
30
+ <ComponentWithStyles a={false} />;
31
+ <ComponentWithStyles
32
+ // @ts-expect-error: string is not a boolean
33
+ a={"not bool"}
34
+ />;
35
+
36
+ <ComponentWithStyles
37
+ a
38
+ // @ts-expect-error: already ibjected by hook
39
+ styles={{
40
+ root: {},
41
+ }}
42
+ />;
43
+ }
44
+
45
+ {
46
+ interface MyTheme {
47
+ colors: {
48
+ red: string;
49
+ };
50
+ }
51
+
52
+ const useStyles = makeUseStyles((theme: MyTheme) => ({
53
+ root: {
54
+ color: theme.colors.red,
55
+ // @ts-expect-error: 'gold' not exists
56
+ borderColor: theme.colors.gold,
57
+ },
58
+ }));
59
+
60
+ interface Props extends InferInjectedStyledProps<typeof useStyles> {
61
+ a: boolean;
62
+ }
63
+
64
+ const WithRef = forwardRef<TextInput, Props>(function Component(props, ref): React.JSX.Element | null {
65
+ props.styles.root.color = "";
66
+
67
+ // @ts-expect-error 'a' not exists
68
+ props.styles.a = {};
69
+
70
+ return <TextInput ref={ref} />;
71
+ });
72
+
73
+ const ComponentWithStylesAndRef = withStyles(useStyles)(WithRef);
74
+
75
+ <ComponentWithStylesAndRef a={false} />;
76
+
77
+ <ComponentWithStylesAndRef
78
+ a={false}
79
+ ref={(instance) => {
80
+ instance?.focus();
81
+
82
+ // @ts-expect-error 'abc' not exists
83
+ instance?.abc();
84
+ }}
85
+ />;
86
+ <ComponentWithStylesAndRef
87
+ // @ts-expect-error: string is not a boolean
88
+ a={"not bool"}
89
+ />;
90
+
91
+ <ComponentWithStylesAndRef
92
+ a
93
+ // @ts-expect-error: already ibjected by hook
94
+ styles={{
95
+ root: {},
96
+ }}
97
+ />;
98
+ }
99
+
100
+ {
101
+ interface MyTheme {
102
+ colors: {
103
+ red: string;
104
+ };
105
+ }
106
+
107
+ const useStyles = makeUseStyles((theme: MyTheme) => ({
108
+ root: {
109
+ color: theme.colors.red,
110
+ // @ts-expect-error: 'gold' not exists
111
+ borderColor: theme.colors.gold,
112
+ },
113
+ }));
114
+
115
+ interface Props extends InferInjectedStyledProps<typeof useStyles> {
116
+ a: boolean;
117
+ }
118
+
119
+ class MyCls extends React.Component<Props> {
120
+ focus() {}
121
+ render() {
122
+ return null;
123
+ }
124
+ }
125
+
126
+ const ComponentWithStylesAndRef = withStyles(useStyles)(MyCls);
127
+
128
+ <ComponentWithStylesAndRef a={false} />;
129
+
130
+ <ComponentWithStylesAndRef
131
+ a={false}
132
+ ref={(instance) => {
133
+ instance?.focus();
134
+
135
+ // @ts-expect-error 'abc' not exists
136
+ instance?.abc();
137
+ }}
138
+ />;
139
+ <ComponentWithStylesAndRef
140
+ // @ts-expect-error: string is not a boolean
141
+ a={"not bool"}
142
+ />;
143
+
144
+ <ComponentWithStylesAndRef
145
+ a
146
+ // @ts-expect-error: already ibjected by hook
147
+ styles={{
148
+ root: {},
149
+ }}
150
+ />;
151
+ }
152
+
153
+ {
154
+ const useStyles = makeUseStyles(() => ({
155
+ root: {
156
+ color: "red",
157
+ },
158
+ }));
159
+
160
+ interface Props extends InferInjectedStyledProps<typeof useStyles> {}
161
+
162
+ const MyCmp: FC<Props> = () => null;
163
+
164
+ const StyledMyCmp = withStyles(useStyles)(MyCmp);
165
+
166
+ <StyledMyCmp
167
+ ref={(e) => {
168
+ // @ts-expect-error: StyledMyCmp doesn't have 'ref' type
169
+ e?.aa();
170
+ }}
171
+ />;
172
+ }
@@ -0,0 +1,50 @@
1
+ import { useEffect, useMemo, useRef } from "react";
2
+ import { Animated } from "react-native";
3
+ import { DefaultTheme } from "./default-theme";
4
+ import { useTheme } from "./use-theme";
5
+
6
+ const { Value, timing } = Animated;
7
+
8
+ const INITIAL_VALUE = 0;
9
+ const defaultOptions = { duration: 250 };
10
+
11
+ export function useColorTransition<Theme = DefaultTheme>(
12
+ colorGetterFn: (theme: Theme) => string,
13
+ options = defaultOptions,
14
+ ): Animated.AnimatedInterpolation<string> {
15
+ const theme = useTheme<Theme>();
16
+ const currentColor = colorGetterFn(theme);
17
+ const animatedValue = useRef(new Value(INITIAL_VALUE));
18
+ const colors = useRef({
19
+ toValue: INITIAL_VALUE,
20
+ prev: currentColor,
21
+ current: currentColor,
22
+ });
23
+
24
+ if (currentColor !== colors.current.current) {
25
+ colors.current = {
26
+ toValue: colors.current.toValue === 0 ? 1 : 0,
27
+ prev: colors.current.current,
28
+ current: currentColor,
29
+ };
30
+ }
31
+
32
+ const { toValue, prev, current } = colors.current;
33
+
34
+ useEffect(() => {
35
+ timing(animatedValue.current, {
36
+ toValue,
37
+ useNativeDriver: false,
38
+ ...options,
39
+ }).start();
40
+ }, [toValue]);
41
+
42
+ return useMemo(() => {
43
+ const outputRange = toValue === 1 ? [prev, current] : [current, prev];
44
+
45
+ return animatedValue.current.interpolate({
46
+ inputRange: [0, 1],
47
+ outputRange,
48
+ });
49
+ }, [prev, current]);
50
+ }
@@ -0,0 +1,14 @@
1
+ import { useContext } from "react";
2
+
3
+ import { themeContext } from "./context";
4
+ import type { DefaultTheme } from "./default-theme";
5
+
6
+ export const useTheme = <Theme = DefaultTheme>(): Theme => {
7
+ const contextValue = useContext(themeContext);
8
+
9
+ if (!contextValue) {
10
+ throw new Error("[react-native-stylex]: Please make sure that you wrapped your component with <ThemeProvider/>.");
11
+ }
12
+
13
+ return contextValue as Theme;
14
+ };
@@ -0,0 +1,22 @@
1
+ import React, { ComponentProps, ComponentType, forwardRef, Ref, ComponentRef } from "react";
2
+
3
+ interface InjectedStyledProps<Styles> {
4
+ styles: Styles;
5
+ }
6
+
7
+ export type InferInjectedStyledProps<Fn extends (...args: any) => any> = InjectedStyledProps<ReturnType<Fn>>;
8
+
9
+ export function withStyles<Styles>(useStyles: () => Styles) {
10
+ function WithStyles<TComponent extends ComponentType<any>>(Component: TComponent) {
11
+ const renderComponent = (props: Omit<ComponentProps<TComponent>, "styles">, ref: Ref<ComponentRef<TComponent>>) => {
12
+ const styles = useStyles();
13
+ // @ts-expect-error: 'ref' as never
14
+ return <Component {...props} ref={ref} styles={styles} />;
15
+ };
16
+
17
+ // @ts-expect-error
18
+ return forwardRef(renderComponent);
19
+ }
20
+
21
+ return WithStyles;
22
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ESNext",
4
+ "target": "ESNext",
5
+ "lib": ["ESNext"],
6
+ "skipLibCheck": true,
7
+ "declaration": true,
8
+ "rootDir": "./src",
9
+ "jsx": "react-native",
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "isolatedModules": true,
13
+ "noImplicitAny": true,
14
+ "strictNullChecks": true,
15
+ "strictFunctionTypes": true,
16
+ "strictBindCallApply": true,
17
+ "strictPropertyInitialization": true,
18
+ "noImplicitThis": true,
19
+ "alwaysStrict": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": true,
22
+ "noImplicitReturns": true,
23
+ "noFallthroughCasesInSwitch": true,
24
+ "noUncheckedIndexedAccess": true,
25
+ "forceConsistentCasingInFileNames": true,
26
+ "moduleResolution": "node",
27
+ "outDir": "./lib"
28
+ },
29
+ "include": ["./src"],
30
+ "exclude": ["./src/tests"]
31
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ESNext",
4
+ "target": "ESNext",
5
+ "lib": ["ESNext"],
6
+ "skipLibCheck": true,
7
+ "declaration": true,
8
+ "rootDir": "./src",
9
+ "jsx": "react-native",
10
+ "strict": true,
11
+ "esModuleInterop": true,
12
+ "isolatedModules": true,
13
+ "noImplicitAny": true,
14
+ "strictNullChecks": true,
15
+ "strictFunctionTypes": true,
16
+ "strictBindCallApply": true,
17
+ "strictPropertyInitialization": true,
18
+ "noImplicitThis": true,
19
+ "alwaysStrict": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": true,
22
+ "noImplicitReturns": true,
23
+ "noFallthroughCasesInSwitch": true,
24
+ "noUncheckedIndexedAccess": true,
25
+ "forceConsistentCasingInFileNames": true,
26
+ "moduleResolution": "node",
27
+ "outDir": "./lib"
28
+ },
29
+ "include": ["./src"]
30
+ }
package/DefaultTheme.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export interface DefaultTheme {
2
- }
package/DefaultTheme.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare const UI_MODE_DEPENDENCY_KEY = "react-native-appearance";
@@ -1,8 +0,0 @@
1
- import "./init";
2
- export type ColorSchemeName = "light" | "dark" | "default";
3
- export declare function appearance<T>({ dark, light, default: defaultScheme, }: {
4
- [mode in ColorSchemeName]?: T;
5
- }): T | undefined;
6
- export declare const darkAppearance: <T>(dark: T) => T | undefined;
7
- export declare const lightAppearance: <T>(light: T) => T | undefined;
8
- export declare const noPreferenceAppearance: <T>(defaultScheme: T) => T | undefined;
@@ -1,18 +0,0 @@
1
- import "./init";
2
- import { Appearance } from "react-native";
3
- import { onUse } from "../dependencyUsage";
4
- import { UI_MODE_DEPENDENCY_KEY } from "./consts";
5
- export function appearance({ dark, light, default: defaultScheme, }) {
6
- onUse(UI_MODE_DEPENDENCY_KEY);
7
- // Note: getColorScheme() will always return light when debugging with Chrome.
8
- if (Appearance.getColorScheme() === "light") {
9
- return light;
10
- }
11
- if (Appearance.getColorScheme() === "dark") {
12
- return dark;
13
- }
14
- return defaultScheme;
15
- }
16
- export const darkAppearance = (dark) => appearance({ dark });
17
- export const lightAppearance = (light) => appearance({ light });
18
- export const noPreferenceAppearance = (defaultScheme) => appearance({ default: defaultScheme });
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- import { Appearance } from "react-native";
2
- import { addDependency } from "../dependencyRegistry";
3
- import { createEventEmitter } from "../createEventEmitter";
4
- import { UI_MODE_DEPENDENCY_KEY } from "./consts";
5
- const { on, emit } = createEventEmitter(UI_MODE_DEPENDENCY_KEY);
6
- addDependency(UI_MODE_DEPENDENCY_KEY, (handler) => on(handler));
7
- Appearance.addChangeListener(emit);
package/context.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- import { DefaultTheme } from "./DefaultTheme";
3
- export declare const themeContext: import("react").Context<DefaultTheme | null>;
4
- export declare const ThemeProvider: import("react").Provider<DefaultTheme | null>, ThemeConsumer: import("react").Consumer<DefaultTheme | null>;
@@ -1,8 +0,0 @@
1
- type Handler = () => void;
2
- type UnSubscribe = () => void;
3
- interface Result {
4
- on: (callback: Handler) => UnSubscribe;
5
- emit: () => void;
6
- }
7
- export declare function createEventEmitter(event: string): Result;
8
- export {};
@@ -1,11 +0,0 @@
1
- const events = {};
2
- export function createEventEmitter(event) {
3
- const emit = () => (events[event] || []).forEach((fn) => fn());
4
- const on = (cb) => {
5
- (events[event] = events[event] || []).push(cb);
6
- return () => {
7
- events[event] = events[event].filter((fn) => fn !== cb);
8
- };
9
- };
10
- return { on, emit };
11
- }
@@ -1 +0,0 @@
1
- export declare const UI_MODE_DEPENDENCY_KEY = "react-native-dark-mode";
@@ -1,7 +0,0 @@
1
- import "./init";
2
- export type UiType = "dark" | "light";
3
- export declare function uiMode<T>({ dark, light, }: {
4
- [mode in UiType]?: T;
5
- }): T | undefined;
6
- export declare const darkUiMode: <T>(dark: T) => T | undefined;
7
- export declare const lightUiMode: <T>(light: T) => T | undefined;
@@ -1,16 +0,0 @@
1
- import "./init";
2
- import { onUse } from "../dependencyUsage";
3
- import { UI_MODE_DEPENDENCY_KEY } from "./consts";
4
- import { state } from "./state";
5
- export function uiMode({ dark, light, }) {
6
- onUse(UI_MODE_DEPENDENCY_KEY);
7
- if (state.mode === "dark") {
8
- return dark;
9
- }
10
- if (state.mode === "light") {
11
- return light;
12
- }
13
- return undefined;
14
- }
15
- export const darkUiMode = (dark) => uiMode({ dark });
16
- export const lightUiMode = (light) => uiMode({ light });
@@ -1 +0,0 @@
1
- export {};
package/dark-mode/init.js DELETED
@@ -1,13 +0,0 @@
1
- import { eventEmitter } from "react-native-dark-mode";
2
- import { addDependency } from "../dependencyRegistry";
3
- import { createEventEmitter } from "../createEventEmitter";
4
- import { UI_MODE_DEPENDENCY_KEY } from "./consts";
5
- import { state } from "./state";
6
- const { on, emit } = createEventEmitter(UI_MODE_DEPENDENCY_KEY);
7
- addDependency(UI_MODE_DEPENDENCY_KEY, (handler) => on(handler));
8
- eventEmitter.on("currentModeChanged", (newMode) => {
9
- if (state.mode !== newMode) {
10
- state.mode = newMode;
11
- emit();
12
- }
13
- });
@@ -1,3 +0,0 @@
1
- export declare const state: {
2
- mode: import("react-native-dark-mode").Mode;
3
- };
@@ -1,5 +0,0 @@
1
- type UnSubscribeFn = () => void;
2
- type SubscribeFn = (handler: () => void) => UnSubscribeFn;
3
- export declare function addDependency(name: string, onChange: SubscribeFn): void;
4
- export declare function getDependency(name: string): SubscribeFn | undefined;
5
- export {};
@@ -1,12 +0,0 @@
1
- const registry = {};
2
- export function addDependency(name, onChange) {
3
- if (!registry[name]) {
4
- Object.defineProperty(registry, name, {
5
- value: onChange,
6
- writable: false,
7
- });
8
- }
9
- }
10
- export function getDependency(name) {
11
- return registry[name];
12
- }
@@ -1,7 +0,0 @@
1
- interface UsingSpec {
2
- [dependencyName: string]: boolean;
3
- }
4
- export declare function resetUsing(): void;
5
- export declare function getUsing(): UsingSpec;
6
- export declare function onUse(name: string): void;
7
- export {};
@@ -1,10 +0,0 @@
1
- const ref = { current: {} };
2
- export function resetUsing() {
3
- ref.current = {};
4
- }
5
- export function getUsing() {
6
- return { ...ref.current };
7
- }
8
- export function onUse(name) {
9
- ref.current[name] = true;
10
- }
@@ -1,2 +0,0 @@
1
- export declare const WINDOW_DEPENDENCY_KEY = "Dimensions.window";
2
- export declare const SCREEN_DEPENDENCY_KEY = "Dimensions.screen";
@@ -1,4 +0,0 @@
1
- import "./init";
2
- import { ScaledSize } from "react-native";
3
- export declare function getWindowDimensions(): ScaledSize;
4
- export declare function getScreenDimensions(): ScaledSize;
@@ -1,13 +0,0 @@
1
- import "./init";
2
- import { Dimensions } from "react-native";
3
- import { onUse } from "../dependencyUsage";
4
- import { WINDOW_DEPENDENCY_KEY, SCREEN_DEPENDENCY_KEY } from "./consts";
5
- const get = (dim) => Dimensions.get(dim);
6
- export function getWindowDimensions() {
7
- onUse(WINDOW_DEPENDENCY_KEY);
8
- return get("window");
9
- }
10
- export function getScreenDimensions() {
11
- onUse(SCREEN_DEPENDENCY_KEY);
12
- return get("screen");
13
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- import { Dimensions } from "react-native";
2
- import { createEventEmitter } from "../createEventEmitter";
3
- import { addDependency } from "../dependencyRegistry";
4
- import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
5
- const { get, addEventListener } = Dimensions;
6
- const state = { window: get("window"), screen: get("screen") };
7
- const windowEventEmitter = createEventEmitter(WINDOW_DEPENDENCY_KEY);
8
- const screenEventEmitter = createEventEmitter(SCREEN_DEPENDENCY_KEY);
9
- const isNotEqual = (a, b) => a.width !== b.width || a.height !== b.height;
10
- addDependency(WINDOW_DEPENDENCY_KEY, (handler) => windowEventEmitter.on(handler));
11
- addDependency(SCREEN_DEPENDENCY_KEY, (handler) => screenEventEmitter.on(handler));
12
- addEventListener("change", ({ window, screen }) => {
13
- if (isNotEqual(screen, state.screen)) {
14
- state.screen = screen;
15
- screenEventEmitter.emit();
16
- }
17
- if (isNotEqual(window, state.window)) {
18
- state.window = window;
19
- windowEventEmitter.emit();
20
- }
21
- });
@@ -1 +0,0 @@
1
- export declare const optimizeDependencies: (keys: Record<string, boolean>) => Record<string, boolean>;
@@ -1,7 +0,0 @@
1
- import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
2
- export const optimizeDependencies = (keys) => {
3
- if (keys[WINDOW_DEPENDENCY_KEY] && keys[SCREEN_DEPENDENCY_KEY]) {
4
- delete keys[SCREEN_DEPENDENCY_KEY];
5
- }
6
- return keys;
7
- };
package/i18n.d.ts DELETED
@@ -1,7 +0,0 @@
1
- type LayoutDirectionType = "rtl" | "ltr";
2
- export declare function i18n<T>({ rtl, ltr, }: {
3
- [direction in LayoutDirectionType]?: T;
4
- }): T | undefined;
5
- export declare const rtl: <T>(styles: T) => T | undefined;
6
- export declare const ltr: <T>(styles: T) => T | undefined;
7
- export {};
package/i18n.js DELETED
@@ -1,9 +0,0 @@
1
- import { I18nManager } from "react-native";
2
- export function i18n({ rtl, ltr, }) {
3
- if (I18nManager.isRTL) {
4
- return rtl;
5
- }
6
- return ltr;
7
- }
8
- export const rtl = (styles) => i18n({ rtl: styles });
9
- export const ltr = (styles) => i18n({ ltr: styles });