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

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 (163) hide show
  1. package/DefaultTheme.d.ts +2 -0
  2. package/DefaultTheme.js +1 -0
  3. package/appearance/consts.d.ts +1 -0
  4. package/appearance/index.d.ts +8 -0
  5. package/appearance/index.js +18 -0
  6. package/appearance/init.d.ts +1 -0
  7. package/{src/appearance/init.ts → appearance/init.js} +1 -6
  8. package/context.d.ts +4 -0
  9. package/context.js +3 -0
  10. package/createEventEmitter.d.ts +8 -0
  11. package/createEventEmitter.js +11 -0
  12. package/dark-mode/consts.d.ts +1 -0
  13. package/dark-mode/index.d.ts +7 -0
  14. package/dark-mode/index.js +16 -0
  15. package/dark-mode/init.d.ts +1 -0
  16. package/dark-mode/init.js +13 -0
  17. package/dark-mode/state.d.ts +3 -0
  18. package/{src/dark-mode/state.ts → dark-mode/state.js} +1 -2
  19. package/dependencyRegistry.d.ts +5 -0
  20. package/dependencyRegistry.js +12 -0
  21. package/dependencyUsage.d.ts +7 -0
  22. package/dependencyUsage.js +10 -0
  23. package/dimensions/consts.d.ts +2 -0
  24. package/dimensions/index.d.ts +4 -0
  25. package/dimensions/index.js +13 -0
  26. package/dimensions/init.d.ts +1 -0
  27. package/dimensions/init.js +21 -0
  28. package/dimensions/utils.d.ts +1 -0
  29. package/dimensions/utils.js +7 -0
  30. package/i18n.d.ts +7 -0
  31. package/i18n.js +9 -0
  32. package/index.js +5 -0
  33. package/{src/makeUseStyles → makeUseStyles}/index.d.ts +1 -1
  34. package/{src/makeUseStyles → makeUseStyles}/utils.js +4 -4
  35. package/media-query/base.d.ts +12 -0
  36. package/media-query/base.js +18 -0
  37. package/media-query/breakpoints.d.ts +18 -0
  38. package/media-query/breakpoints.js +60 -0
  39. package/media-query/index.d.ts +2 -0
  40. package/media-query/index.js +2 -0
  41. package/orientation.d.ts +7 -0
  42. package/orientation.js +7 -0
  43. package/package.json +6 -37
  44. package/safe-area/SafeAreaProvider.d.ts +3 -0
  45. package/safe-area/SafeAreaProvider.js +9 -0
  46. package/safe-area/StylexSaveAreaConsumer.d.ts +2 -0
  47. package/safe-area/StylexSaveAreaConsumer.js +15 -0
  48. package/safe-area/consts.d.ts +1 -0
  49. package/safe-area/eventEmitter.d.ts +1 -0
  50. package/{src/safe-area/eventEmitter.ts → safe-area/eventEmitter.js} +0 -1
  51. package/safe-area/index.d.ts +5 -0
  52. package/{src/safe-area/index.tsx → safe-area/index.js} +3 -9
  53. package/safe-area/init.d.ts +1 -0
  54. package/{src/safe-area/init.tsx → safe-area/init.js} +1 -3
  55. package/safe-area/state.d.ts +8 -0
  56. package/{src/safe-area/state.ts → safe-area/state.js} +5 -7
  57. package/safe-area/types.d.ts +9 -0
  58. package/safe-area/types.js +1 -0
  59. package/useColorTransition.d.ts +5 -0
  60. package/useColorTransition.js +38 -0
  61. package/useTheme.d.ts +2 -0
  62. package/useTheme.js +9 -0
  63. package/withStyles.d.ts +7 -0
  64. package/withStyles.js +13 -0
  65. package/.eslintignore +0 -1
  66. package/.eslintrc.js +0 -31
  67. package/.github/workflows/nodejs.yml +0 -33
  68. package/.size-limit.json +0 -6
  69. package/babel.config.js +0 -3
  70. package/docs/api.md +0 -103
  71. package/docs/appearance.md +0 -54
  72. package/docs/dark-mode.md +0 -46
  73. package/docs/dimensions.md +0 -29
  74. package/docs/i18n.md +0 -67
  75. package/docs/logo.png +0 -0
  76. package/docs/media-query.md +0 -274
  77. package/docs/orientation.md +0 -44
  78. package/docs/safe-area.md +0 -62
  79. package/docs/testting.md +0 -51
  80. package/docs/ts.md +0 -127
  81. package/example/AppStyleX/.watchmanconfig +0 -1
  82. package/example/AppStyleX/android/build.gradle +0 -26
  83. package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  84. package/example/AppStyleX/android/gradle/wrapper/gradle-wrapper.properties +0 -7
  85. package/example/AppStyleX/android/gradle.properties +0 -53
  86. package/example/AppStyleX/android/gradlew +0 -249
  87. package/example/AppStyleX/android/gradlew.bat +0 -92
  88. package/example/AppStyleX/android/settings.gradle +0 -12
  89. package/example/AppStyleX/app.json +0 -28
  90. package/example/AppStyleX/babel.config.js +0 -3
  91. package/example/AppStyleX/index.js +0 -9
  92. package/example/AppStyleX/ios/Podfile +0 -7
  93. package/example/AppStyleX/ios/Podfile.lock +0 -1252
  94. package/example/AppStyleX/metro.config.js +0 -54
  95. package/example/AppStyleX/package.json +0 -43
  96. package/example/AppStyleX/react-native.config.js +0 -23
  97. package/example/AppStyleX/src/App.tsx +0 -25
  98. package/example/AppStyleX/src/BottomNav/index.tsx +0 -32
  99. package/example/AppStyleX/src/BottomNav/styles.ts +0 -42
  100. package/example/AppStyleX/src/Circle/index.tsx +0 -53
  101. package/example/AppStyleX/src/Circle/styles.ts +0 -22
  102. package/example/AppStyleX/src/Root/index.tsx +0 -41
  103. package/example/AppStyleX/src/Root/styles.ts +0 -18
  104. package/example/AppStyleX/src/ToggleButton/index.tsx +0 -66
  105. package/example/AppStyleX/src/ToggleButton/styles.ts +0 -69
  106. package/example/AppStyleX/src/style-system/hooks/useAnimatedBgColor.ts +0 -5
  107. package/example/AppStyleX/src/style-system/hooks/useAnimatedTextColor.ts +0 -5
  108. package/example/AppStyleX/src/style-system/hooks/useIsDark.ts +0 -8
  109. package/example/AppStyleX/src/style-system/palette.ts +0 -11
  110. package/example/AppStyleX/src/style-system/theme.ts +0 -14
  111. package/example/AppStyleX/src/style-system/utils.ts +0 -11
  112. package/example/AppStyleX/src/stylex.d.ts +0 -6
  113. package/example/AppStyleX/tsconfig.json +0 -3
  114. package/example/AppStyleX/yarn.lock +0 -6767
  115. package/jest.config.js +0 -19
  116. package/src/DefaultTheme.ts +0 -4
  117. package/src/__tests__/createBreakpoints.test.ts +0 -152
  118. package/src/__tests__/createBreakpointsMatcher.test.ts +0 -188
  119. package/src/__tests__/createBreakpointsMatcher.types-test.ts +0 -81
  120. package/src/__tests__/createEventEmitter.test.ts +0 -37
  121. package/src/__tests__/dark-mode.test.ts +0 -56
  122. package/src/__tests__/dependencyRegistry.test.ts +0 -16
  123. package/src/__tests__/dependencyUsage.test.ts +0 -13
  124. package/src/__tests__/dimensions.test.ts +0 -36
  125. package/src/__tests__/makeUseStyles.types-test.ts +0 -69
  126. package/src/__tests__/media-query.test.ts +0 -204
  127. package/src/__tests__/orientation.test.ts +0 -61
  128. package/src/__tests__/useTheme.test.ts +0 -26
  129. package/src/__tests__/withStyles.types-test.tsx +0 -173
  130. package/src/appearance/index.ts +0 -37
  131. package/src/context.ts +0 -9
  132. package/src/createEventEmitter.ts +0 -26
  133. package/src/dark-mode/index.ts +0 -29
  134. package/src/dark-mode/init.ts +0 -19
  135. package/src/dependencyRegistry.ts +0 -21
  136. package/src/dependencyUsage.ts +0 -31
  137. package/src/dimensions/index.ts +0 -20
  138. package/src/dimensions/init.ts +0 -37
  139. package/src/dimensions/utils.ts +0 -11
  140. package/src/i18n.ts +0 -18
  141. package/src/makeUseStyles/createUseStylesTheme.test.js +0 -137
  142. package/src/makeUseStyles/createUseStylesWithoutTheme.test.js +0 -63
  143. package/src/makeUseStyles/index.test.js +0 -28
  144. package/src/media-query/base.ts +0 -43
  145. package/src/media-query/breakpoints.ts +0 -121
  146. package/src/media-query/index.ts +0 -12
  147. package/src/orientation.ts +0 -17
  148. package/src/safe-area/SafeAreaProvider.tsx +0 -17
  149. package/src/safe-area/StylexSaveAreaConsumer.ts +0 -23
  150. package/src/safe-area/types.ts +0 -10
  151. package/src/useColorTransition.ts +0 -50
  152. package/src/useTheme.ts +0 -16
  153. package/src/withStyles.tsx +0 -35
  154. package/tsconfig.json +0 -30
  155. /package/{src/appearance/consts.ts → appearance/consts.js} +0 -0
  156. /package/{src/dark-mode/consts.ts → dark-mode/consts.js} +0 -0
  157. /package/{src/dimensions/consts.ts → dimensions/consts.js} +0 -0
  158. /package/{src/index.ts → index.d.ts} +0 -0
  159. /package/{src/makeUseStyles → makeUseStyles}/createUseStylesTheme.js +0 -0
  160. /package/{src/makeUseStyles → makeUseStyles}/createUseStylesWithoutTheme.js +0 -0
  161. /package/{src/makeUseStyles → makeUseStyles}/index.js +0 -0
  162. /package/{src/makeUseStyles → makeUseStyles}/test-type.js +0 -0
  163. /package/{src/safe-area/consts.ts → safe-area/consts.js} +0 -0
@@ -1,11 +0,0 @@
1
- import { SCREEN_DEPENDENCY_KEY, WINDOW_DEPENDENCY_KEY } from "./consts";
2
-
3
- export const optimizeDependencies = (
4
- keys: Record<string, boolean>
5
- ): Record<string, boolean> => {
6
- if (keys[WINDOW_DEPENDENCY_KEY] && keys[SCREEN_DEPENDENCY_KEY]) {
7
- delete keys[SCREEN_DEPENDENCY_KEY];
8
- }
9
-
10
- return keys;
11
- };
package/src/i18n.ts DELETED
@@ -1,18 +0,0 @@
1
- import { I18nManager } from "react-native";
2
-
3
- type LayoutDirectionType = "rtl" | "ltr";
4
-
5
- export function i18n<T>({
6
- rtl,
7
- ltr,
8
- }: { [direction in LayoutDirectionType]?: T }): T | undefined {
9
- if (I18nManager.isRTL) {
10
- return rtl;
11
- }
12
-
13
- return ltr;
14
- }
15
-
16
- export const rtl = <T>(styles: T): T | undefined => i18n<T>({ rtl: styles });
17
-
18
- export const ltr = <T>(styles: T): T | undefined => i18n<T>({ ltr: styles });
@@ -1,137 +0,0 @@
1
- import { renderHook, act } from "@testing-library/react-hooks";
2
- import { createUseStylesTheme } from "./createUseStylesTheme";
3
- import { ThemeProvider } from "../context";
4
- import { createEventEmitter } from "../createEventEmitter";
5
- import { addDependency } from "../dependencyRegistry";
6
- import { onUse } from "../dependencyUsage";
7
-
8
- it("should create styles using a theme", () => {
9
- const mockGetStyles = jest.fn(({ colors }) => ({
10
- root: { color: colors.red },
11
- }));
12
-
13
- const useStyles = createUseStylesTheme(mockGetStyles);
14
- const { result } = renderHook(() => useStyles(), {
15
- wrapper: ThemeProvider,
16
- initialProps: { value: { colors: { red: "red" } } },
17
- });
18
-
19
- expect(result.current).toEqual({
20
- root: { color: "red" },
21
- });
22
- });
23
-
24
- it("should create styles once", () => {
25
- const theme = { colors: { red: "red" } };
26
- const mockGetStyles = jest.fn(({ colors }) => ({
27
- root: { color: colors.red },
28
- }));
29
-
30
- const useStyles = createUseStylesTheme(mockGetStyles);
31
-
32
- renderHook(
33
- () => {
34
- useStyles();
35
- useStyles();
36
- useStyles();
37
- },
38
- {
39
- wrapper: ThemeProvider,
40
- initialProps: { value: theme },
41
- }
42
- );
43
-
44
- expect(mockGetStyles).toHaveBeenCalledTimes(1);
45
- });
46
-
47
- it("should not update styles when component rerender", () => {
48
- const theme = { colors: { red: "red" } };
49
- const mockGetStyles = jest.fn(({ colors }) => ({
50
- root: { color: colors.red },
51
- }));
52
-
53
- const useStyles = createUseStylesTheme(mockGetStyles);
54
- const { rerender } = renderHook(() => useStyles(), {
55
- wrapper: ThemeProvider,
56
- initialProps: { value: theme },
57
- });
58
-
59
- rerender({ value: theme, a: 1 });
60
- rerender({ value: theme, a: 2 });
61
- rerender({ value: theme, a: 3 });
62
-
63
- expect(mockGetStyles).toHaveBeenCalledTimes(1);
64
- });
65
-
66
- it("should use memoized styles when component rerender", () => {
67
- const theme = { colors: { red: "red" } };
68
- const mockGetStyles = jest.fn(({ colors }) => ({
69
- root: { color: colors.red },
70
- }));
71
-
72
- const useStyles = createUseStylesTheme(mockGetStyles);
73
- const { rerender, result } = renderHook(() => useStyles(), {
74
- wrapper: ThemeProvider,
75
- initialProps: { value: theme },
76
- });
77
-
78
- const initialStyles = result.current;
79
-
80
- rerender({ value: theme, a: 1 });
81
- rerender({ value: theme, a: 2 });
82
- rerender({ value: theme, a: 3 });
83
-
84
- const afterUpdateStyles = result.current;
85
-
86
- expect(afterUpdateStyles).toBe(initialStyles);
87
- });
88
-
89
- it("should update styles when theme was changed", () => {
90
- const initialTheme = { colors: { red: "red" } };
91
- const newTheme = { colors: { red: "white" } };
92
-
93
- const mockGetStyles = jest.fn(({ colors }) => ({
94
- root: { color: colors.red },
95
- }));
96
-
97
- const useStyles = createUseStylesTheme(mockGetStyles);
98
- const { rerender } = renderHook(() => useStyles(), {
99
- wrapper: ThemeProvider,
100
- initialProps: { value: initialTheme },
101
- });
102
-
103
- act(() => {
104
- rerender({ value: newTheme });
105
- });
106
-
107
- expect(mockGetStyles).toHaveBeenCalledTimes(2);
108
- });
109
-
110
- it("should update styles when dependency changed", () => {
111
- const theme = { colors: { red: "red" } };
112
- const TEST_DEPENDENCY_KEY = `test_${Math.random()}`;
113
- const { on, emit } = createEventEmitter(TEST_DEPENDENCY_KEY);
114
- const mockGetStyles = jest.fn(({ colors }) => {
115
- // simulate using a dependency
116
- onUse(TEST_DEPENDENCY_KEY);
117
-
118
- return {
119
- root: { color: colors.red },
120
- };
121
- });
122
-
123
- addDependency(TEST_DEPENDENCY_KEY, (handler) => on(handler));
124
-
125
- const useStyles = createUseStylesTheme(mockGetStyles);
126
-
127
- renderHook(() => useStyles(), {
128
- wrapper: ThemeProvider,
129
- initialProps: { value: theme },
130
- });
131
-
132
- act(() => {
133
- emit();
134
- });
135
-
136
- expect(mockGetStyles).toHaveBeenCalledTimes(2);
137
- });
@@ -1,63 +0,0 @@
1
- import { renderHook, act } from "@testing-library/react-hooks";
2
- import { createUseStylesWithoutTheme } from "./createUseStylesWithoutTheme";
3
-
4
- import { addDependency } from "../dependencyRegistry";
5
- import { onUse } from "../dependencyUsage";
6
- import { createEventEmitter } from "../createEventEmitter";
7
-
8
- const TEST_DEPENDENCY_KEY = `test_${Math.random()}`;
9
-
10
- const { on, emit } = createEventEmitter(TEST_DEPENDENCY_KEY);
11
-
12
- addDependency(TEST_DEPENDENCY_KEY, (handler) => on(handler));
13
-
14
- const useStyles = createUseStylesWithoutTheme(() => {
15
- // simulate using a dependency
16
- onUse(TEST_DEPENDENCY_KEY);
17
-
18
- return {
19
- root: { color: "red" },
20
- };
21
- });
22
-
23
- it("should use the same styles object to reduce memory usage", () => {
24
- const { result } = renderHook(() => ({
25
- stl1: useStyles(),
26
- stl2: useStyles(),
27
- }));
28
-
29
- expect(result.current.stl1).toBe(result.current.stl2);
30
- });
31
-
32
- it("should update styles when dependency changed", () => {
33
- const { result } = renderHook(() => ({
34
- stl1: useStyles(),
35
- stl2: useStyles(),
36
- }));
37
-
38
- const initialResult = { ...result.current };
39
-
40
- act(() => {
41
- emit();
42
- });
43
-
44
- const updatedResult = { ...result.current };
45
-
46
- expect(initialResult.stl1).not.toBe(updatedResult.stl1);
47
- expect(initialResult.stl2).not.toBe(updatedResult.stl2);
48
- });
49
-
50
- it("should return the same style when component rerender", () => {
51
- const mockUseStyles = jest.fn(useStyles);
52
-
53
- const { result, rerender } = renderHook(() => mockUseStyles());
54
-
55
- const initialResult = result.current;
56
-
57
- rerender({});
58
-
59
- const updatedResult = result.current;
60
-
61
- expect(mockUseStyles).toHaveBeenCalledTimes(2);
62
- expect(initialResult).toBe(updatedResult);
63
- });
@@ -1,28 +0,0 @@
1
- import { createUseStylesWithoutTheme } from "./createUseStylesWithoutTheme";
2
- import { createUseStylesTheme } from "./createUseStylesTheme";
3
- import { makeUseStyles } from "./index";
4
-
5
- jest.mock("./createUseStylesWithoutTheme");
6
- jest.mock("./createUseStylesTheme");
7
-
8
- afterEach(() => {
9
- jest.clearAllMocks();
10
- });
11
-
12
- it("should invoke 'createUseStylesWithoutTheme' when pass function without first argument", () => {
13
- const withoutThemeDeps = () => ({});
14
-
15
- makeUseStyles(withoutThemeDeps);
16
-
17
- expect(createUseStylesWithoutTheme).toHaveBeenCalledTimes(1);
18
- expect(createUseStylesTheme).toHaveBeenCalledTimes(0);
19
- });
20
-
21
- it("should invoke 'createUseStylesTheme' when pass function with first argument", () => {
22
- const withThemeDeps = (theme) => ({});
23
-
24
- makeUseStyles(withThemeDeps);
25
-
26
- expect(createUseStylesWithoutTheme).toHaveBeenCalledTimes(0);
27
- expect(createUseStylesTheme).toHaveBeenCalledTimes(1);
28
- });
@@ -1,43 +0,0 @@
1
- import { ScaledSize } from "react-native";
2
-
3
- import { getWindowDimensions } from "../dimensions";
4
-
5
- export const createDimensionQueryHelper = <Value>(
6
- queryFunction: (options: { value: Value; dimensions: ScaledSize }) => boolean
7
- ) => <T>(value: Value, styles: T): null | T => {
8
- const isMatched = queryFunction({ value, dimensions: getWindowDimensions() });
9
-
10
- if (isMatched) {
11
- return styles;
12
- }
13
-
14
- return null;
15
- };
16
-
17
- export const maxHeight = createDimensionQueryHelper<number>(
18
- ({ value, dimensions }) => value >= dimensions.height
19
- );
20
-
21
- export const maxWidth = createDimensionQueryHelper<number>(
22
- ({ value, dimensions }) => value >= dimensions.width
23
- );
24
-
25
- export const minHeight = createDimensionQueryHelper<number>(
26
- ({ value, dimensions }) => value <= dimensions.height
27
- );
28
-
29
- export const minWidth = createDimensionQueryHelper<number>(
30
- ({ value, dimensions }) => value <= dimensions.width
31
- );
32
-
33
- export const minAspectRatio = createDimensionQueryHelper<number>(
34
- ({ value, dimensions: { width, height } }) => value <= width / height
35
- );
36
-
37
- export const maxAspectRatio = createDimensionQueryHelper<number>(
38
- ({ value, dimensions: { width, height } }) => value >= width / height
39
- );
40
-
41
- export const aspectRatio = createDimensionQueryHelper<number>(
42
- ({ value, dimensions: { width, height } }) => value === width / height
43
- );
@@ -1,121 +0,0 @@
1
- import { minAspectRatio, minWidth, minHeight, maxWidth } from "./base";
2
-
3
- interface BreakpointsMatcher<TBreakpoints> {
4
- <T>(values: { [mode in keyof TBreakpoints]?: T }): T | undefined;
5
- <T>(values: { [mode in keyof TBreakpoints]?: T } & { default: T }): T;
6
- }
7
-
8
- const orderByMin = [minWidth, minAspectRatio, minHeight];
9
-
10
- const toOrderedBreakpointNames = <TBreakpoints extends Record<string, number>>(
11
- values: any,
12
- breakpoints: any,
13
- matchFunction: any
14
- ): Array<keyof TBreakpoints> => {
15
- const result = Object.keys(values)
16
- .filter((e) => e !== "default")
17
- .sort((a, b) => breakpoints[a] - breakpoints[b]);
18
-
19
- if (orderByMin.includes(matchFunction)) {
20
- return result.slice().reverse();
21
- }
22
-
23
- return result;
24
- };
25
-
26
- /*
27
- * To debug use analog on CSS: https://codepen.io/retyui/pen/dyOzKzV
28
- */
29
- export function createBreakpointsMatcher<
30
- TBreakpoints extends Record<string, number>
31
- >(
32
- breakpoints: TBreakpoints,
33
- matchFunction = minWidth
34
- ): BreakpointsMatcher<TBreakpoints> {
35
- return function breakpointsMatcher(values: any) {
36
- /* istanbul ignore next */
37
- // @ts-expect-error: was removed
38
- if (process.env.NODE_ENV !== "production") {
39
- const invalidKeys = Object.keys(values).filter((key) => {
40
- return key !== "default" && breakpoints[key] === undefined;
41
- });
42
-
43
- if (invalidKeys.length > 0) {
44
- console.warn(
45
- `[react-native-stylex]: Invalid values was passed to 'breakpointsMatcher' function
46
-
47
- allowed keys: ${Object.keys(breakpoints).join(", ")}
48
- unexpected keys: ${invalidKeys.join(", ")}
49
- `
50
- );
51
- }
52
- }
53
-
54
- const orderedBreakpointNames = toOrderedBreakpointNames<TBreakpoints>(
55
- values,
56
- breakpoints,
57
- matchFunction
58
- );
59
-
60
- const key =
61
- orderedBreakpointNames.find((breakpointName) =>
62
- matchFunction(
63
- breakpoints[breakpointName] as number,
64
- values[breakpointName]
65
- )
66
- ) || "default";
67
-
68
- return values[key] || null;
69
- };
70
- }
71
-
72
- function getNextByKey<TBreakpoints extends Record<string, number>>(
73
- breakpoints: TBreakpoints,
74
- key: keyof TBreakpoints
75
- ) {
76
- type Keys = keyof TBreakpoints;
77
-
78
- const breakpointsKeys: Array<Keys> = Object.keys(breakpoints).sort(
79
- (a: Keys, b: Keys) => breakpoints[a]! - breakpoints[b]!
80
- );
81
- const index = breakpointsKeys.indexOf(key);
82
- const nextKey: Keys | undefined = breakpointsKeys[index + 1];
83
-
84
- return nextKey;
85
- }
86
-
87
- export function createBreakpoints<TBreakpoints extends Record<string, number>>(
88
- breakpoints: TBreakpoints
89
- ) {
90
- type Keys = keyof TBreakpoints;
91
-
92
- function up<T>(key: Keys, value: T): T | null {
93
- return minWidth<T>(breakpoints[key] as number, value);
94
- }
95
-
96
- function down<T>(key: Keys, value: T): T | null {
97
- return maxWidth<T>(breakpoints[key] as number, value);
98
- }
99
-
100
- function only<T>(key: Keys, value: T): T | null {
101
- const nextKey = getNextByKey<TBreakpoints>(breakpoints, key);
102
-
103
- if (nextKey !== undefined) {
104
- return minWidth(
105
- breakpoints[key] as number,
106
- maxWidth(breakpoints[nextKey]! - 0.05, value)
107
- );
108
- }
109
-
110
- return minWidth(breakpoints[key] as number, value);
111
- }
112
-
113
- function between<T>(start: Keys, end: Keys, value: T): T | null {
114
- return minWidth(
115
- breakpoints[start] as number,
116
- maxWidth(breakpoints[end]! - 0.05, value)
117
- );
118
- }
119
-
120
- return { up, down, only, between };
121
- }
@@ -1,12 +0,0 @@
1
- export {
2
- minWidth,
3
- minAspectRatio,
4
- maxWidth,
5
- aspectRatio,
6
- createDimensionQueryHelper,
7
- maxAspectRatio,
8
- maxHeight,
9
- minHeight,
10
- } from "./base";
11
-
12
- export { createBreakpointsMatcher, createBreakpoints } from "./breakpoints";
@@ -1,17 +0,0 @@
1
- import { getScreenDimensions } from "./dimensions";
2
-
3
- type OrientationType = "portrait" | "landscape";
4
-
5
- export function orientation<T>(
6
- spec: { [orientation in OrientationType]?: T }
7
- ): T | undefined {
8
- const { height, width } = getScreenDimensions();
9
-
10
- return width <= height ? spec.portrait : spec.landscape;
11
- }
12
-
13
- export const portraitOrientation = <T>(portraitStyles: T): T | undefined =>
14
- orientation<T>({ portrait: portraitStyles });
15
-
16
- export const landscapeOrientation = <T>(landscapeStyles: T): T | undefined =>
17
- orientation<T>({ landscape: landscapeStyles });
@@ -1,17 +0,0 @@
1
- import React from "react";
2
- import { SafeAreaProvider as CoreSafeAreaProvider, initialWindowMetrics,initialWindowSafeAreaInsets } from "react-native-safe-area-context";
3
-
4
- import { StylexSaveAreaConsumer } from "./StylexSaveAreaConsumer";
5
- import { SafeAreaViewProps } from "./types";
6
-
7
- export function SafeAreaProvider(props: SafeAreaViewProps): JSX.Element | null {
8
- return (
9
- <CoreSafeAreaProvider
10
- initialSafeAreaInsets={props.initialSafeAreaInsets || initialWindowSafeAreaInsets}
11
- initialMetrics={props.initialMetrics || initialWindowMetrics}
12
- {...props}>
13
- {props.children}
14
- <StylexSaveAreaConsumer />
15
- </CoreSafeAreaProvider>
16
- );
17
- }
@@ -1,23 +0,0 @@
1
- import { useSafeAreaInsets } from "react-native-safe-area-context";
2
- import { EdgeInsets } from "./types";
3
-
4
- import { emit } from "./eventEmitter";
5
- import { state } from "./state";
6
- import { useLayoutEffect } from "react";
7
-
8
- export function StylexSaveAreaConsumer(): JSX.Element | null {
9
- const insets: EdgeInsets = useSafeAreaInsets();
10
-
11
- useLayoutEffect(() => {
12
- const isChanged = Object.entries(insets).some(
13
- ([key, value]) => state.insets[key as keyof EdgeInsets] !== value
14
- );
15
-
16
- if (isChanged) {
17
- state.insets = insets;
18
- emit();
19
- }
20
- }, [insets]);
21
-
22
- return null;
23
- }
@@ -1,10 +0,0 @@
1
- import {SafeAreaProviderProps} from "react-native-safe-area-context";
2
-
3
- export interface EdgeInsets {
4
- top: number;
5
- right: number;
6
- bottom: number;
7
- left: number;
8
- }
9
-
10
- export interface SafeAreaViewProps extends SafeAreaProviderProps { }
@@ -1,50 +0,0 @@
1
- import { useEffect, useMemo, useRef } from "react";
2
- import { Animated } from "react-native";
3
- import { DefaultTheme } from "./DefaultTheme";
4
- import { useTheme } from "./useTheme";
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
- }
package/src/useTheme.ts DELETED
@@ -1,16 +0,0 @@
1
- import { useContext } from "react";
2
-
3
- import { themeContext } from "./context";
4
- import type { DefaultTheme } from "./DefaultTheme";
5
-
6
- export const useTheme = <Theme = DefaultTheme>(): Theme => {
7
- const contextValue = useContext(themeContext);
8
-
9
- if (!contextValue) {
10
- throw new Error(
11
- "[react-native-stylex]: Please make sure that you wrapped your component with <ThemeProvider/>."
12
- );
13
- }
14
-
15
- return contextValue as Theme;
16
- };
@@ -1,35 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import React, {
3
- ComponentProps,
4
- ComponentType,
5
- forwardRef,
6
- Ref,
7
- ElementRef
8
- } from "react";
9
-
10
- interface InjectedStyledProps<Styles> {
11
- styles: Styles;
12
- }
13
-
14
- export type InferInjectedStyledProps<
15
- Fn extends (...args: any) => any
16
- > = InjectedStyledProps<ReturnType<Fn>>;
17
-
18
- export function withStyles<Styles>(useStyles: () => Styles) {
19
- function WithStyles<TComponent extends ComponentType<any>>(
20
- Component: TComponent
21
- ) {
22
- const renderComponent = (
23
- props: Omit<ComponentProps<TComponent>, "styles">,
24
- ref: Ref<ElementRef<TComponent>>
25
- ) => {
26
- const styles = useStyles();
27
- // @ts-expect-error: 'ref' as never
28
- return <Component {...props} ref={ref} styles={styles} />;
29
- };
30
-
31
- return forwardRef(renderComponent);
32
- }
33
-
34
- return WithStyles;
35
- }
package/tsconfig.json DELETED
@@ -1,30 +0,0 @@
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
- }
File without changes
File without changes