react-native-unistyles 3.0.0-alpha.32 → 3.0.0-alpha.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. package/cxx/common/Helpers.h +24 -2
  2. package/cxx/core/HostStyle.cpp +1 -1
  3. package/cxx/core/UnistyleWrapper.h +31 -1
  4. package/cxx/core/UnistylesMountHook.cpp +1 -1
  5. package/cxx/core/UnistylesMountHook.h +4 -2
  6. package/cxx/core/UnistylesRegistry.cpp +7 -2
  7. package/cxx/hybridObjects/HybridShadowRegistry.cpp +1 -2
  8. package/cxx/hybridObjects/HybridStyleSheet.cpp +4 -1
  9. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +12 -0
  10. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  11. package/cxx/parser/Parser.cpp +6 -6
  12. package/cxx/parser/Parser.h +1 -1
  13. package/cxx/shadowTree/ShadowTrafficController.h +5 -8
  14. package/lib/commonjs/components/Display.js +18 -0
  15. package/lib/commonjs/components/Display.js.map +1 -0
  16. package/lib/commonjs/components/Hide.js +18 -0
  17. package/lib/commonjs/components/Hide.js.map +1 -0
  18. package/lib/commonjs/components/index.js +20 -0
  19. package/lib/commonjs/components/index.js.map +1 -0
  20. package/lib/commonjs/components/useMedia.js +59 -0
  21. package/lib/commonjs/components/useMedia.js.map +1 -0
  22. package/lib/commonjs/core/createUnistylesComponent.js +2 -1
  23. package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
  24. package/lib/commonjs/core/createUnistylesComponent.native.js +43 -4
  25. package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -1
  26. package/lib/commonjs/core/index.js +0 -14
  27. package/lib/commonjs/core/index.js.map +1 -1
  28. package/lib/commonjs/global.js +0 -4
  29. package/lib/commonjs/global.js.map +1 -1
  30. package/lib/commonjs/index.js +12 -14
  31. package/lib/commonjs/index.js.map +1 -1
  32. package/lib/commonjs/mq.js +25 -12
  33. package/lib/commonjs/mq.js.map +1 -1
  34. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +4 -5
  35. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +0 -1
  36. package/lib/commonjs/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -1
  37. package/lib/commonjs/specs/ShadowRegistry/types.js +0 -4
  38. package/lib/commonjs/specs/ShadowRegistry/types.js.map +1 -1
  39. package/lib/commonjs/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -1
  40. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js +4 -2
  41. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -1
  42. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +3 -1
  43. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -2
  44. package/lib/commonjs/specs/types.js.map +0 -1
  45. package/lib/commonjs/types/accessibility.js +1 -1
  46. package/lib/commonjs/types/accessibility.js.map +0 -1
  47. package/lib/commonjs/types/common.js +0 -3
  48. package/lib/commonjs/types/stylesheet.js +2 -1
  49. package/lib/commonjs/web/convert/index.js +7 -1
  50. package/lib/commonjs/web/convert/index.js.map +1 -2
  51. package/lib/commonjs/web/convert/pseudo.js.map +1 -2
  52. package/lib/commonjs/web/convert/shadow.js +5 -1
  53. package/lib/commonjs/web/convert/shadow.js.map +1 -2
  54. package/lib/commonjs/web/convert/style.js.map +1 -2
  55. package/lib/commonjs/web/convert/textShadow.js +4 -1
  56. package/lib/commonjs/web/convert/textShadow.js.map +1 -2
  57. package/lib/commonjs/web/convert/transform.js.map +1 -2
  58. package/lib/commonjs/web/convert/types.js.map +1 -1
  59. package/lib/commonjs/web/convert/utils.js +2 -1
  60. package/lib/commonjs/web/convert/utils.js.map +1 -2
  61. package/lib/commonjs/web/listener.js.map +1 -2
  62. package/lib/commonjs/web/mock.js.map +1 -2
  63. package/lib/commonjs/web/shadowRegistry.js +9 -1
  64. package/lib/commonjs/web/shadowRegistry.js.map +1 -2
  65. package/lib/commonjs/web/utils/unistyle.js +1 -1
  66. package/lib/commonjs/web/variants/index.js.map +1 -1
  67. package/lib/commonjs/web/variants/useVariants.js +2 -1
  68. package/lib/commonjs/web/variants/useVariants.js.map +1 -2
  69. package/lib/module/common.js.map +1 -1
  70. package/lib/module/components/Display.js +13 -0
  71. package/lib/module/components/Display.js.map +1 -0
  72. package/lib/module/components/Hide.js +13 -0
  73. package/lib/module/components/Hide.js.map +1 -0
  74. package/lib/module/components/index.js +5 -0
  75. package/lib/module/components/index.js.map +1 -0
  76. package/lib/module/components/useMedia.js +54 -0
  77. package/lib/module/components/useMedia.js.map +1 -0
  78. package/lib/module/core/createUnistylesComponent.js +2 -1
  79. package/lib/module/core/createUnistylesComponent.js.map +1 -1
  80. package/lib/module/core/createUnistylesComponent.native.js +41 -3
  81. package/lib/module/core/createUnistylesComponent.native.js.map +1 -1
  82. package/lib/module/core/index.js +0 -2
  83. package/lib/module/core/index.js.map +1 -1
  84. package/lib/module/global.js +1 -1
  85. package/lib/module/global.js.map +0 -1
  86. package/lib/module/index.js +2 -1
  87. package/lib/module/index.js.map +1 -1
  88. package/lib/module/mq.js +21 -11
  89. package/lib/module/mq.js.map +1 -1
  90. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +6 -5
  91. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +0 -1
  92. package/lib/module/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +1 -1
  93. package/lib/module/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +0 -1
  94. package/lib/module/specs/ShadowRegistry/types.js +0 -2
  95. package/lib/module/specs/ShadowRegistry/types.js.map +0 -1
  96. package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +0 -1
  97. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -1
  98. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +0 -1
  99. package/lib/module/specs/StyleSheet/index.js.map +1 -2
  100. package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -2
  101. package/lib/module/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +0 -1
  102. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -2
  103. package/lib/module/specs/types.js.map +0 -1
  104. package/lib/module/types/accessibility.js +9 -9
  105. package/lib/module/types/accessibility.js.map +1 -1
  106. package/lib/module/types/breakpoints.js.map +0 -1
  107. package/lib/module/types/common.js +0 -2
  108. package/lib/module/types/common.js.map +1 -1
  109. package/lib/module/types/core.js.map +1 -1
  110. package/lib/module/types/stylesheet.js +2 -2
  111. package/lib/module/types/variants.js.map +1 -1
  112. package/lib/module/web/convert/boxShadow.js +4 -1
  113. package/lib/module/web/convert/boxShadow.js.map +1 -2
  114. package/lib/module/web/convert/pseudo.js.map +1 -2
  115. package/lib/module/web/convert/textShadow.js +4 -1
  116. package/lib/module/web/convert/transform.js.map +1 -2
  117. package/lib/module/web/convert/types.js.map +1 -1
  118. package/lib/module/web/convert/utils.js +2 -1
  119. package/lib/module/web/registry.js +3 -1
  120. package/lib/module/web/registry.js.map +1 -2
  121. package/lib/module/web/runtime.js.map +1 -2
  122. package/lib/module/web/shadowRegistry.js +9 -1
  123. package/lib/module/web/utils/common.js +3 -1
  124. package/lib/module/web/utils/common.js.map +1 -2
  125. package/lib/module/web/utils/index.js.map +1 -1
  126. package/lib/module/web/utils/unistyle.js +1 -1
  127. package/lib/module/web/utils/unistyle.js.map +1 -1
  128. package/lib/module/web/variants/index.js.map +1 -1
  129. package/lib/module/web/variants/useVariants.js +2 -1
  130. package/lib/module/web/variants/useVariants.js.map +1 -2
  131. package/lib/typescript/src/components/Display.d.ts +7 -0
  132. package/lib/typescript/src/components/Display.d.ts.map +1 -0
  133. package/lib/typescript/src/components/Hide.d.ts +7 -0
  134. package/lib/typescript/src/components/Hide.d.ts.map +1 -0
  135. package/lib/typescript/src/components/index.d.ts +3 -0
  136. package/lib/typescript/src/components/index.d.ts.map +1 -0
  137. package/lib/typescript/src/components/useMedia.d.ts +6 -0
  138. package/lib/typescript/src/components/useMedia.d.ts.map +1 -0
  139. package/lib/typescript/src/core/createUnistylesComponent.d.ts +3 -2
  140. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
  141. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +3 -2
  142. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -1
  143. package/lib/typescript/src/core/index.d.ts +0 -2
  144. package/lib/typescript/src/core/index.d.ts.map +1 -1
  145. package/lib/typescript/src/index.d.ts +2 -1
  146. package/lib/typescript/src/index.d.ts.map +1 -1
  147. package/lib/typescript/src/mq.d.ts +8 -0
  148. package/lib/typescript/src/mq.d.ts.map +1 -1
  149. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +1 -0
  150. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  151. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -0
  152. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
  153. package/package.json +1 -1
  154. package/plugin/ref.js +4 -4
  155. package/plugin/style.js +15 -3
  156. package/src/components/Display.tsx +12 -0
  157. package/src/components/Hide.tsx +12 -0
  158. package/src/components/index.ts +2 -0
  159. package/src/components/useMedia.ts +64 -0
  160. package/src/core/createUnistylesComponent.native.tsx +48 -4
  161. package/src/core/createUnistylesComponent.tsx +4 -2
  162. package/src/core/index.ts +0 -2
  163. package/src/index.ts +2 -1
  164. package/src/mq.ts +27 -9
  165. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -0
  166. package/src/web/utils/unistyle.ts +1 -1
  167. package/lib/commonjs/core/useBreakpoint.js +0 -22
  168. package/lib/commonjs/core/useBreakpoint.js.map +0 -1
  169. package/lib/commonjs/core/useBreakpoint.native.js +0 -24
  170. package/lib/commonjs/core/useBreakpoint.native.js.map +0 -2
  171. package/lib/commonjs/core/useTheme.js +0 -22
  172. package/lib/commonjs/core/useTheme.js.map +0 -1
  173. package/lib/commonjs/core/useTheme.native.js +0 -24
  174. package/lib/commonjs/core/useTheme.native.js.map +0 -2
  175. package/lib/commonjs/web/mq.js +0 -23
  176. package/lib/commonjs/web/mq.js.map +0 -1
  177. package/lib/module/core/useBreakpoint.js +0 -17
  178. package/lib/module/core/useBreakpoint.js.map +0 -1
  179. package/lib/module/core/useBreakpoint.native.js +0 -19
  180. package/lib/module/core/useBreakpoint.native.js.map +0 -1
  181. package/lib/module/core/useTheme.js +0 -17
  182. package/lib/module/core/useTheme.js.map +0 -2
  183. package/lib/module/core/useTheme.native.js +0 -19
  184. package/lib/module/core/useTheme.native.js.map +0 -1
  185. package/lib/module/web/mq.js +0 -17
  186. package/lib/module/web/mq.js.map +0 -1
  187. package/lib/typescript/src/core/useBreakpoint.d.ts +0 -2
  188. package/lib/typescript/src/core/useBreakpoint.d.ts.map +0 -1
  189. package/lib/typescript/src/core/useBreakpoint.native.d.ts +0 -2
  190. package/lib/typescript/src/core/useBreakpoint.native.d.ts.map +0 -1
  191. package/lib/typescript/src/core/useTheme.d.ts +0 -3
  192. package/lib/typescript/src/core/useTheme.d.ts.map +0 -1
  193. package/lib/typescript/src/core/useTheme.native.d.ts +0 -3
  194. package/lib/typescript/src/core/useTheme.native.d.ts.map +0 -1
  195. package/lib/typescript/src/web/mq.d.ts +0 -8
  196. package/lib/typescript/src/web/mq.d.ts.map +0 -1
  197. package/src/common.js +0 -4
  198. package/src/core/createUnistylesComponent.js +0 -6
  199. package/src/core/createUnistylesComponent.native.js +0 -31
  200. package/src/core/index.js +0 -3
  201. package/src/core/useBreakpoint.js +0 -14
  202. package/src/core/useBreakpoint.native.js +0 -16
  203. package/src/core/useBreakpoint.native.ts +0 -21
  204. package/src/core/useBreakpoint.ts +0 -18
  205. package/src/core/useTheme.js +0 -14
  206. package/src/core/useTheme.native.js +0 -16
  207. package/src/core/useTheme.native.ts +0 -22
  208. package/src/core/useTheme.ts +0 -19
  209. package/src/global.js +0 -1
  210. package/src/index.js +0 -3
  211. package/src/mq.js +0 -38
  212. package/src/specs/NativePlatform/NativePlatform.nitro.js +0 -19
  213. package/src/specs/NativePlatform/index.js +0 -1
  214. package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.js +0 -1
  215. package/src/specs/NavigtionBar/index.js +0 -9
  216. package/src/specs/ShadowRegistry/ShadowRegistry.nitro.js +0 -1
  217. package/src/specs/ShadowRegistry/index.js +0 -26
  218. package/src/specs/ShadowRegistry/types.js +0 -1
  219. package/src/specs/StatusBar/UnistylesStatusBar.nitro.js +0 -1
  220. package/src/specs/StatusBar/index.js +0 -25
  221. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.js +0 -1
  222. package/src/specs/StyleSheet/index.js +0 -13
  223. package/src/specs/TurboUnistyles/NativeTurboUnistyles.js +0 -2
  224. package/src/specs/TurboUnistyles/index.js +0 -1
  225. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.js +0 -1
  226. package/src/specs/UnistylesRuntime/index.js +0 -20
  227. package/src/specs/index.js +0 -8
  228. package/src/specs/index.web.js +0 -2
  229. package/src/specs/types.js +0 -17
  230. package/src/types/accessibility.js +0 -30
  231. package/src/types/breakpoints.js +0 -1
  232. package/src/types/common.js +0 -1
  233. package/src/types/core.js +0 -1
  234. package/src/types/index.js +0 -1
  235. package/src/types/stylesheet.js +0 -2
  236. package/src/types/variants.js +0 -1
  237. package/src/web/convert/boxShadow.js +0 -59
  238. package/src/web/convert/index.js +0 -56
  239. package/src/web/convert/pseudo.js +0 -131
  240. package/src/web/convert/shadow.js +0 -50
  241. package/src/web/convert/style.js +0 -137
  242. package/src/web/convert/textShadow.js +0 -56
  243. package/src/web/convert/transform.js +0 -65
  244. package/src/web/convert/types.js +0 -2
  245. package/src/web/convert/utils.js +0 -39
  246. package/src/web/create.js +0 -36
  247. package/src/web/index.js +0 -22
  248. package/src/web/listener.js +0 -26
  249. package/src/web/mock.js +0 -21
  250. package/src/web/mq.js +0 -14
  251. package/src/web/mq.ts +0 -17
  252. package/src/web/registry.js +0 -165
  253. package/src/web/runtime.js +0 -160
  254. package/src/web/shadowRegistry.js +0 -96
  255. package/src/web/state.js +0 -68
  256. package/src/web/utils/common.js +0 -79
  257. package/src/web/utils/index.js +0 -2
  258. package/src/web/utils/unistyle.js +0 -72
  259. package/src/web/variants/getVariants.js +0 -26
  260. package/src/web/variants/index.js +0 -2
  261. package/src/web/variants/useVariants.js +0 -50
@@ -1,3 +0,0 @@
1
- import type { UnistylesTheme } from '../types';
2
- export declare const useTheme: () => UnistylesTheme;
3
- //# sourceMappingURL=useTheme.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../../../src/core/useTheme.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,eAAO,MAAM,QAAQ,QAAO,cAY3B,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { UnistylesTheme } from '../types';
2
- export declare const useTheme: () => UnistylesTheme;
3
- //# sourceMappingURL=useTheme.native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTheme.native.d.ts","sourceRoot":"","sources":["../../../../src/core/useTheme.native.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAE9C,eAAO,MAAM,QAAQ,QAAO,cAgB3B,CAAA"}
@@ -1,8 +0,0 @@
1
- export declare const parseMq: (mq: string) => {
2
- minWidth: number | undefined;
3
- maxWidth: number | undefined;
4
- minHeight: number | undefined;
5
- maxHeight: number | undefined;
6
- };
7
- export declare const isUnistylesMq: (mq: string) => boolean;
8
- //# sourceMappingURL=mq.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../../../src/web/mq.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,OAAQ,MAAM;;;;;CAUjC,CAAA;AAED,eAAO,MAAM,aAAa,OAAQ,MAAM,YAAgC,CAAA"}
package/src/common.js DELETED
@@ -1,4 +0,0 @@
1
- import { Platform } from 'react-native';
2
- export const isWeb = Platform.OS === 'web';
3
- export const isIOS = Platform.OS === 'ios';
4
- export const isAndroid = Platform.OS === 'android';
@@ -1,6 +0,0 @@
1
- import React, {} from 'react';
2
- export const createUnistylesComponent = (Component, mappings) => {
3
- return (props) => {
4
- return React.createElement(Component, { ...props });
5
- };
6
- };
@@ -1,31 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
3
- export const createUnistylesComponent = (Component, mappings) => {
4
- return (props) => {
5
- const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
6
- const [, setRt] = useState(0);
7
- useEffect(() => {
8
- const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
9
- const componentDependencies = (props.style?.uni__dependencies || mappings(theme).style?.uni__dependencies);
10
- if (dependencies.includes(UnistyleDependency.Theme) && (!componentDependencies || componentDependencies.includes(UnistyleDependency.Theme))) {
11
- setTheme(UnistylesRuntime.getTheme());
12
- }
13
- if (dependencies.some(dependency => dependency >= 2) && (!componentDependencies || componentDependencies.some(dependency => dependency >= 2))) {
14
- setRt(prevState => prevState + 1);
15
- }
16
- });
17
- return () => {
18
- removeChangeListener();
19
- };
20
- }, []);
21
- const mergedProps = { ...mappings(theme) };
22
- Object.keys(props).forEach(key => {
23
- if (key in mergedProps) {
24
- mergedProps[key] = Object.assign(props[key], mergedProps[key]);
25
- return;
26
- }
27
- mergedProps[key] = props[key];
28
- });
29
- return React.createElement(Component, { ...mergedProps });
30
- };
31
- };
package/src/core/index.js DELETED
@@ -1,3 +0,0 @@
1
- export { useBreakpoint } from './useBreakpoint';
2
- export { useTheme } from './useTheme';
3
- export { createUnistylesComponent } from './createUnistylesComponent';
@@ -1,14 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { UnistylesRuntime } from '../web';
3
- import { UnistylesListener } from '../web/listener';
4
- import { UnistyleDependency } from '../specs/NativePlatform';
5
- export const useBreakpoint = () => {
6
- const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
7
- useEffect(() => {
8
- const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Breakpoints], () => setBreakpoint(UnistylesRuntime.breakpoint));
9
- return () => {
10
- removeChangeListener();
11
- };
12
- }, []);
13
- return breakpoint;
14
- };
@@ -1,16 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
3
- export const useBreakpoint = () => {
4
- const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint);
5
- useEffect(() => {
6
- const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
7
- if (dependencies.includes(UnistyleDependency.Breakpoints)) {
8
- setBreakpoint(UnistylesRuntime.breakpoint);
9
- }
10
- });
11
- return () => {
12
- removeChangeListener();
13
- };
14
- }, []);
15
- return breakpoint;
16
- };
@@ -1,21 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
- import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
3
- import type { UnistylesStyleSheet } from '../specs'
4
-
5
- export const useBreakpoint = () => {
6
- const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint)
7
-
8
- useEffect(() => {
9
- const removeChangeListener = (StyleSheet as UnistylesStyleSheet).addChangeListener(dependencies => {
10
- if (dependencies.includes(UnistyleDependency.Breakpoints)) {
11
- setBreakpoint(UnistylesRuntime.breakpoint)
12
- }
13
- })
14
-
15
- return () => {
16
- removeChangeListener()
17
- }
18
- }, [])
19
-
20
- return breakpoint
21
- }
@@ -1,18 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
- import { UnistylesRuntime } from '../web'
3
- import { UnistylesListener } from '../web/listener'
4
- import { UnistyleDependency } from '../specs/NativePlatform'
5
-
6
- export const useBreakpoint = () => {
7
- const [breakpoint, setBreakpoint] = useState(UnistylesRuntime.breakpoint)
8
-
9
- useEffect(() => {
10
- const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Breakpoints], () => setBreakpoint(UnistylesRuntime.breakpoint))
11
-
12
- return () => {
13
- removeChangeListener()
14
- }
15
- }, [])
16
-
17
- return breakpoint
18
- }
@@ -1,14 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { UnistylesRuntime } from '../web';
3
- import { UnistylesListener } from '../web/listener';
4
- import { UnistyleDependency } from '../specs/NativePlatform';
5
- export const useTheme = () => {
6
- const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
7
- useEffect(() => {
8
- const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Theme], () => setTheme(UnistylesRuntime.getTheme()));
9
- return () => {
10
- removeChangeListener();
11
- };
12
- }, []);
13
- return theme;
14
- };
@@ -1,16 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs';
3
- export const useTheme = () => {
4
- const [theme, setTheme] = useState(UnistylesRuntime.getTheme());
5
- useEffect(() => {
6
- const removeChangeListener = StyleSheet.addChangeListener(dependencies => {
7
- if (dependencies.includes(UnistyleDependency.Theme)) {
8
- setTheme(UnistylesRuntime.getTheme());
9
- }
10
- });
11
- return () => {
12
- removeChangeListener();
13
- };
14
- }, []);
15
- return theme;
16
- };
@@ -1,22 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
- import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
3
- import type { UnistylesStyleSheet } from '../specs'
4
- import type { UnistylesTheme } from '../types'
5
-
6
- export const useTheme = (): UnistylesTheme => {
7
- const [theme, setTheme] = useState(UnistylesRuntime.getTheme())
8
-
9
- useEffect(() => {
10
- const removeChangeListener = (StyleSheet as UnistylesStyleSheet).addChangeListener(dependencies => {
11
- if (dependencies.includes(UnistyleDependency.Theme)) {
12
- setTheme(UnistylesRuntime.getTheme())
13
- }
14
- })
15
-
16
- return () => {
17
- removeChangeListener()
18
- }
19
- }, [])
20
-
21
- return theme
22
- }
@@ -1,19 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
- import { UnistylesRuntime } from '../web'
3
- import { UnistylesListener } from '../web/listener'
4
- import { UnistyleDependency } from '../specs/NativePlatform'
5
- import type { UnistylesTheme } from '../types'
6
-
7
- export const useTheme = (): UnistylesTheme => {
8
- const [theme, setTheme] = useState(UnistylesRuntime.getTheme())
9
-
10
- useEffect(() => {
11
- const removeChangeListener = UnistylesListener.addListeners([UnistyleDependency.Theme], () => setTheme(UnistylesRuntime.getTheme()))
12
-
13
- return () => {
14
- removeChangeListener()
15
- }
16
- }, [])
17
-
18
- return theme
19
- }
package/src/global.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/src/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from './specs';
2
- export { mq } from './mq';
3
- export { useTheme, useBreakpoint, createUnistylesComponent } from './core';
package/src/mq.js DELETED
@@ -1,38 +0,0 @@
1
- const getMQValue = (value) => {
2
- if (typeof value === 'number') {
3
- return value;
4
- }
5
- if (value === null) {
6
- return 0;
7
- }
8
- // todo take it from js
9
- const breakpoints = {
10
- xs: 0,
11
- sm: 300,
12
- md: 500,
13
- lg: 800,
14
- xl: 1200
15
- };
16
- // @ts-ignore
17
- return breakpoints[value] ?? 0;
18
- };
19
- /**
20
- * Utility to create cross-platform media queries
21
- * @returns - JavaScript symbol to be used in your stylesheet
22
- */
23
- export const mq = {
24
- only: {
25
- width: (wMin = 0, wMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]`,
26
- height: (hMin = 0, hMax = Infinity) => `:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
27
- },
28
- width: (wMin = 0, wMax = Infinity) => ({
29
- and: {
30
- height: (hMin = 0, hMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
31
- }
32
- }),
33
- height: (hMin = 0, hMax = Infinity) => ({
34
- and: {
35
- width: (wMin = 0, wMax = Infinity) => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`
36
- }
37
- })
38
- };
@@ -1,19 +0,0 @@
1
- import {} from '../types';
2
- export var UnistyleDependency;
3
- (function (UnistyleDependency) {
4
- UnistyleDependency[UnistyleDependency["Theme"] = 0] = "Theme";
5
- UnistyleDependency[UnistyleDependency["ThemeName"] = 1] = "ThemeName";
6
- UnistyleDependency[UnistyleDependency["AdaptiveThemes"] = 2] = "AdaptiveThemes";
7
- UnistyleDependency[UnistyleDependency["Breakpoints"] = 3] = "Breakpoints";
8
- UnistyleDependency[UnistyleDependency["Variants"] = 4] = "Variants";
9
- UnistyleDependency[UnistyleDependency["ColorScheme"] = 5] = "ColorScheme";
10
- UnistyleDependency[UnistyleDependency["Dimensions"] = 6] = "Dimensions";
11
- UnistyleDependency[UnistyleDependency["Orientation"] = 7] = "Orientation";
12
- UnistyleDependency[UnistyleDependency["ContentSizeCategory"] = 8] = "ContentSizeCategory";
13
- UnistyleDependency[UnistyleDependency["Insets"] = 9] = "Insets";
14
- UnistyleDependency[UnistyleDependency["PixelRatio"] = 10] = "PixelRatio";
15
- UnistyleDependency[UnistyleDependency["FontScale"] = 11] = "FontScale";
16
- UnistyleDependency[UnistyleDependency["StatusBar"] = 12] = "StatusBar";
17
- UnistyleDependency[UnistyleDependency["NavigationBar"] = 13] = "NavigationBar";
18
- UnistyleDependency[UnistyleDependency["Ime"] = 14] = "Ime";
19
- })(UnistyleDependency || (UnistyleDependency = {}));
@@ -1 +0,0 @@
1
- export { UnistyleDependency } from './NativePlatform.nitro';
@@ -1,9 +0,0 @@
1
- import { processColor } from 'react-native';
2
- export const attachNavigationBarJSMethods = (hybridObject) => {
3
- const privateHybrid = hybridObject;
4
- privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor;
5
- hybridObject.setBackgroundColor = (color) => {
6
- const parsedColor = processColor(color) ?? 0;
7
- privateHybrid._setBackgroundColor(parsedColor);
8
- };
9
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- import { NitroModules } from 'react-native-nitro-modules';
2
- const HybridShadowRegistry = NitroModules.createHybridObject('UnistylesShadowRegistry');
3
- const findShadowNodeForHandle = (handle) => {
4
- const node = handle?.__internalInstanceHandle?.stateNode?.node
5
- ?? handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node
6
- ?? handle?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node;
7
- if (!node) {
8
- // todo extend log with file name / component name
9
- throw new Error('Could not find shadow node for one of your components');
10
- }
11
- return node;
12
- };
13
- HybridShadowRegistry.add = (handle, style, variants, args) => {
14
- // virtualized nodes can be null
15
- if (!handle || !style) {
16
- return;
17
- }
18
- HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
19
- };
20
- HybridShadowRegistry.remove = handle => {
21
- if (!handle) {
22
- return;
23
- }
24
- HybridShadowRegistry.unlink(findShadowNodeForHandle(handle));
25
- };
26
- export const UnistylesShadowRegistry = HybridShadowRegistry;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,25 +0,0 @@
1
- import { processColor, StatusBar as NativeStatusBar } from 'react-native';
2
- import { StatusBarStyle } from '../types';
3
- export const attachStatusBarJSMethods = (hybridObject) => {
4
- hybridObject.setStyle = (style, animated) => {
5
- switch (style) {
6
- case StatusBarStyle.Light:
7
- return NativeStatusBar.setBarStyle('light-content', animated);
8
- case StatusBarStyle.Dark:
9
- return NativeStatusBar.setBarStyle('dark-content', animated);
10
- case StatusBarStyle.Default:
11
- return NativeStatusBar.setBarStyle('default', animated);
12
- }
13
- };
14
- const privateHybrid = hybridObject;
15
- privateHybrid._setHidden = hybridObject.setHidden;
16
- hybridObject.setHidden = (isHidden, animation) => {
17
- NativeStatusBar.setHidden(isHidden, animation);
18
- privateHybrid._setHidden(isHidden);
19
- };
20
- privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor;
21
- hybridObject.setBackgroundColor = (color) => {
22
- const parsedColor = processColor(color) ?? 0;
23
- privateHybrid._setBackgroundColor(parsedColor);
24
- };
25
- };
@@ -1 +0,0 @@
1
- import { UnistyleDependency } from '../NativePlatform';
@@ -1,13 +0,0 @@
1
- import { NitroModules } from 'react-native-nitro-modules';
2
- import { processColor, StyleSheet as NativeStyleSheet } from 'react-native';
3
- const HybridUnistylesStyleSheet = NitroModules
4
- .createHybridObject('UnistylesStyleSheet');
5
- HybridUnistylesStyleSheet.absoluteFillObject = NativeStyleSheet.absoluteFillObject;
6
- HybridUnistylesStyleSheet.absoluteFill = NativeStyleSheet.absoluteFill;
7
- HybridUnistylesStyleSheet.flatten = NativeStyleSheet.flatten;
8
- HybridUnistylesStyleSheet.compose = NativeStyleSheet.compose;
9
- HybridUnistylesStyleSheet.jsMethods = {
10
- processColor
11
- };
12
- HybridUnistylesStyleSheet.init();
13
- export const StyleSheet = HybridUnistylesStyleSheet;
@@ -1,2 +0,0 @@
1
- import { TurboModuleRegistry } from 'react-native';
2
- TurboModuleRegistry.get('Unistyles');
@@ -1 +0,0 @@
1
- import './NativeTurboUnistyles';
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- import { processColor } from 'react-native';
2
- import { NitroModules } from 'react-native-nitro-modules';
3
- import { attachStatusBarJSMethods } from '../StatusBar';
4
- import { attachNavigationBarJSMethods } from '../NavigtionBar';
5
- import { isIOS } from '../../common';
6
- const HybridUnistylesRuntime = NitroModules
7
- .createHybridObject('UnistylesRuntime');
8
- HybridUnistylesRuntime.statusBar = HybridUnistylesRuntime.createHybridStatusBar();
9
- HybridUnistylesRuntime.navigationBar = HybridUnistylesRuntime.createHybridNavigationBar();
10
- HybridUnistylesRuntime._setRootViewBackgroundColor = HybridUnistylesRuntime.setRootViewBackgroundColor;
11
- HybridUnistylesRuntime.setRootViewBackgroundColor = (color) => {
12
- const parsedColor = processColor(color) ?? 0;
13
- HybridUnistylesRuntime._setRootViewBackgroundColor(parsedColor);
14
- };
15
- if (isIOS) {
16
- HybridUnistylesRuntime.setImmersiveMode = (isEnabled) => HybridUnistylesRuntime.statusBar.setHidden(isEnabled, 'fade');
17
- }
18
- attachStatusBarJSMethods(HybridUnistylesRuntime.statusBar);
19
- attachNavigationBarJSMethods(HybridUnistylesRuntime.navigationBar);
20
- export const Runtime = HybridUnistylesRuntime;
@@ -1,8 +0,0 @@
1
- import './TurboUnistyles';
2
- import { Runtime } from './UnistylesRuntime';
3
- import { StyleSheet } from './StyleSheet';
4
- import { UnistylesShadowRegistry } from './ShadowRegistry';
5
- import { StatusBarStyle, ColorScheme, Orientation } from './types';
6
- import { UnistyleDependency } from './NativePlatform';
7
- export { StatusBarStyle, ColorScheme, Orientation, UnistyleDependency };
8
- export { UnistylesShadowRegistry, Runtime as UnistylesRuntime, StyleSheet, };
@@ -1,2 +0,0 @@
1
- export const getSSRUnistyles = () => [];
2
- export * from '../web';
@@ -1,17 +0,0 @@
1
- export var ColorScheme;
2
- (function (ColorScheme) {
3
- ColorScheme["Light"] = "light";
4
- ColorScheme["Dark"] = "dark";
5
- ColorScheme["Unspecified"] = "unspecified";
6
- })(ColorScheme || (ColorScheme = {}));
7
- export var Orientation;
8
- (function (Orientation) {
9
- Orientation["Portrait"] = "portrait";
10
- Orientation["Landscape"] = "landscape";
11
- })(Orientation || (Orientation = {}));
12
- export var StatusBarStyle;
13
- (function (StatusBarStyle) {
14
- StatusBarStyle["Default"] = "default";
15
- StatusBarStyle["Light"] = "light";
16
- StatusBarStyle["Dark"] = "dark";
17
- })(StatusBarStyle || (StatusBarStyle = {}));
@@ -1,30 +0,0 @@
1
- export var IOSContentSizeCategory;
2
- (function (IOSContentSizeCategory) {
3
- IOSContentSizeCategory["AccessibilityExtraExtraExtraLarge"] = "accessibilityExtraExtraExtraLarge";
4
- IOSContentSizeCategory["AccessibilityExtraExtraLarge"] = "accessibilityExtraExtraLarge";
5
- IOSContentSizeCategory["AccessibilityExtraLarge"] = "accessibilityExtraLarge";
6
- IOSContentSizeCategory["AccessibilityLarge"] = "accessibilityLarge";
7
- IOSContentSizeCategory["AccessibilityMedium"] = "accessibilityMedium";
8
- IOSContentSizeCategory["ExtraExtraExtraLarge"] = "xxxLarge";
9
- IOSContentSizeCategory["ExtraExtraLarge"] = "xxLarge";
10
- IOSContentSizeCategory["ExtraLarge"] = "xLarge";
11
- IOSContentSizeCategory["Large"] = "Large";
12
- IOSContentSizeCategory["Medium"] = "Medium";
13
- IOSContentSizeCategory["Small"] = "Small";
14
- IOSContentSizeCategory["ExtraSmall"] = "xSmall";
15
- IOSContentSizeCategory["Unspecified"] = "unspecified";
16
- })(IOSContentSizeCategory || (IOSContentSizeCategory = {}));
17
- export var AndroidContentSizeCategory;
18
- (function (AndroidContentSizeCategory) {
19
- AndroidContentSizeCategory["Small"] = "Small";
20
- AndroidContentSizeCategory["Default"] = "Default";
21
- AndroidContentSizeCategory["Large"] = "Large";
22
- AndroidContentSizeCategory["ExtraLarge"] = "ExtraLarge";
23
- AndroidContentSizeCategory["Huge"] = "Huge";
24
- AndroidContentSizeCategory["ExtraHuge"] = "ExtraHuge";
25
- AndroidContentSizeCategory["ExtraExtraHuge"] = "ExtraExtraHuge";
26
- })(AndroidContentSizeCategory || (AndroidContentSizeCategory = {}));
27
- export var WebContentSizeCategory;
28
- (function (WebContentSizeCategory) {
29
- WebContentSizeCategory["Unspecified"] = "web-unspecified";
30
- })(WebContentSizeCategory || (WebContentSizeCategory = {}));
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
package/src/types/core.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export { AndroidContentSizeCategory, IOSContentSizeCategory, WebContentSizeCategory } from './accessibility';
@@ -1,2 +0,0 @@
1
- const create = (stylesheet) => stylesheet;
2
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
1
- import { deepMergeObjects, warn } from '../utils';
2
- import { validateShadow } from './shadow';
3
- import { BOX_SHADOW_STYLES } from './types';
4
- import { extractShadowValue, normalizeColor, normalizeNumericValue } from './utils';
5
- const createBoxShadowValue = (style) => {
6
- // at this point every prop is present
7
- const { shadowColor, shadowOffset, shadowOpacity, shadowRadius } = style;
8
- const offsetX = normalizeNumericValue(shadowOffset.width);
9
- const offsetY = normalizeNumericValue(shadowOffset.height);
10
- const radius = normalizeNumericValue(shadowRadius);
11
- const color = normalizeColor(shadowColor, shadowOpacity);
12
- return `${offsetX} ${offsetY} ${radius} ${color}`;
13
- };
14
- export const getBoxShadowStyle = (styles) => {
15
- const missingStyles = BOX_SHADOW_STYLES.filter(key => !(key in styles));
16
- if (missingStyles.length) {
17
- warn(`can't apply box shadow as you miss these properties: ${missingStyles.join(', ')}`);
18
- return {};
19
- }
20
- const breakpointsSet = new Set();
21
- try {
22
- validateShadow(BOX_SHADOW_STYLES, styles, breakpointsSet);
23
- }
24
- catch (error) {
25
- if (typeof error === 'string') {
26
- warn(error);
27
- }
28
- return {};
29
- }
30
- const breakpoints = Array.from(breakpointsSet);
31
- // If no breakpoints were used return styles without media queries
32
- if (breakpoints.length === 0) {
33
- return {
34
- boxShadow: createBoxShadowValue(styles)
35
- };
36
- }
37
- // Create boxShadow for each breakpoint
38
- const breakpointStyles = breakpoints.map(breakpoint => {
39
- const color = extractShadowValue('shadowColor', breakpoint, styles);
40
- const { width, height } = extractShadowValue('shadowOffset', breakpoint, styles);
41
- const radius = extractShadowValue('shadowRadius', breakpoint, styles);
42
- const opacity = extractShadowValue('shadowOpacity', breakpoint, styles);
43
- return {
44
- [breakpoint]: {
45
- boxShadow: createBoxShadowValue({
46
- shadowColor: color,
47
- shadowOffset: {
48
- width,
49
- height
50
- },
51
- shadowRadius: radius,
52
- shadowOpacity: opacity
53
- })
54
- }
55
- };
56
- });
57
- // Merge all breakpoints styles into one
58
- return deepMergeObjects(...breakpointStyles);
59
- };
@@ -1,56 +0,0 @@
1
- import { isPseudo } from './pseudo';
2
- import { getStyle } from './style';
3
- import { deepMergeObjects } from '../utils';
4
- import { getTransformStyle } from './transform';
5
- import { isBoxShadow, isTextShadow, isTransform } from './utils';
6
- import { getTextShadowStyle } from './textShadow';
7
- import { getBoxShadowStyle } from './boxShadow';
8
- export const convertUnistyles = (value) => {
9
- // Flag to mark if textShadow is already created
10
- let hasTextShadow = false;
11
- // Flag to mark if boxShadow is already created
12
- let hasBoxShadow = false;
13
- const stylesArray = Object.entries({
14
- ...value,
15
- ...value._web
16
- }).flatMap(([unistylesKey, unistylesValue]) => {
17
- // Keys to omit
18
- if (['_classNames', '_web', 'variants', 'compoundVariants', 'uni__dependencies', '__unistyles-secrets__'].includes(unistylesKey) || unistylesKey.startsWith('variant-')) {
19
- return [];
20
- }
21
- // Pseudo classes :hover, :before etc.
22
- if (isPseudo(unistylesKey)) {
23
- const flattenValues = convertUnistyles(unistylesValue);
24
- return { [unistylesKey]: flattenValues };
25
- }
26
- // Text shadow
27
- if (isTextShadow(unistylesKey)) {
28
- if (hasTextShadow) {
29
- return [];
30
- }
31
- hasTextShadow = true;
32
- return getTextShadowStyle(value);
33
- }
34
- // Box shadow
35
- if (isBoxShadow(unistylesKey)) {
36
- if (hasBoxShadow) {
37
- return [];
38
- }
39
- hasBoxShadow = true;
40
- return getBoxShadowStyle(value);
41
- }
42
- // Transforms
43
- if (isTransform(unistylesKey, unistylesValue)) {
44
- return getTransformStyle(unistylesValue);
45
- }
46
- // Breakpoints
47
- if (typeof unistylesValue === 'object' && unistylesValue !== null) {
48
- return Object.entries(unistylesValue).map(([breakpointKey, breakpointValue]) => {
49
- return { [breakpointKey]: getStyle(unistylesKey, breakpointValue) };
50
- });
51
- }
52
- // Regular styles
53
- return getStyle(unistylesKey, unistylesValue);
54
- });
55
- return deepMergeObjects(...stylesArray);
56
- };