react-native-unistyles 2.4.0 → 2.4.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 (266) hide show
  1. package/README.md +72 -26
  2. package/android/CMakeLists.txt +18 -2
  3. package/android/build.gradle +5 -1
  4. package/android/src/main/cxx/cpp-adapter.cpp +16 -80
  5. package/android/src/main/cxx/helpers.cpp +61 -0
  6. package/android/src/main/cxx/helpers.h +7 -0
  7. package/android/src/main/cxx/platform.cpp +170 -0
  8. package/android/src/main/cxx/platform.h +20 -0
  9. package/android/src/main/java/com/unistyles/Models.kt +12 -70
  10. package/android/src/main/java/com/unistyles/Platform.kt +311 -10
  11. package/android/src/main/java/com/unistyles/UnistylesModule.kt +145 -153
  12. package/cxx/Macros.h +11 -0
  13. package/cxx/UnistylesImpl.cpp +310 -0
  14. package/cxx/UnistylesModel.cpp +234 -0
  15. package/cxx/UnistylesModel.h +141 -0
  16. package/cxx/UnistylesRuntime.cpp +17 -356
  17. package/cxx/UnistylesRuntime.h +71 -87
  18. package/ios/UnistylesModule.h +13 -0
  19. package/ios/UnistylesModule.mm +20 -90
  20. package/ios/platform/Platform_Shared.h +8 -0
  21. package/ios/platform/Platform_Shared.mm +160 -0
  22. package/ios/platform/Platform_iOS.h +6 -10
  23. package/ios/platform/Platform_iOS.mm +143 -93
  24. package/ios/platform/Platform_macOS.h +3 -7
  25. package/ios/platform/Platform_macOS.mm +52 -34
  26. package/ios/platform/Platform_tvOS.h +17 -0
  27. package/ios/platform/Platform_tvOS.mm +96 -0
  28. package/ios/platform/Platform_visionOS.h +20 -0
  29. package/ios/platform/Platform_visionOS.mm +120 -0
  30. package/lib/commonjs/UnistylesProvider.js +32 -0
  31. package/lib/commonjs/UnistylesProvider.js.map +1 -0
  32. package/lib/commonjs/common.js +3 -2
  33. package/lib/commonjs/common.js.map +1 -1
  34. package/lib/commonjs/core/UnistyleRegistry.js +14 -4
  35. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
  36. package/lib/commonjs/core/Unistyles.js +7 -0
  37. package/lib/commonjs/core/Unistyles.js.map +1 -1
  38. package/lib/commonjs/core/UnistylesModule.js +52 -8
  39. package/lib/commonjs/core/UnistylesModule.js.map +1 -1
  40. package/lib/commonjs/core/UnistylesModule.native.js.map +1 -1
  41. package/lib/commonjs/core/UnistylesModule.windows.js.map +1 -1
  42. package/lib/commonjs/core/UnistylesRuntime.js +114 -4
  43. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
  44. package/lib/commonjs/core/index.js.map +1 -1
  45. package/lib/commonjs/core/mocks/UnistylesMockedBridge.js +36 -0
  46. package/lib/commonjs/core/mocks/UnistylesMockedBridge.js.map +1 -0
  47. package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js +46 -0
  48. package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js.map +1 -0
  49. package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js +122 -0
  50. package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js.map +1 -0
  51. package/lib/commonjs/core/mocks/index.js +27 -0
  52. package/lib/commonjs/core/mocks/index.js.map +1 -0
  53. package/lib/commonjs/createStyleSheet.js.map +1 -1
  54. package/lib/commonjs/global.js.map +1 -1
  55. package/lib/commonjs/hooks/index.js.map +1 -1
  56. package/lib/commonjs/hooks/useCSS.js.map +1 -1
  57. package/lib/commonjs/hooks/useCSS.native.js.map +1 -1
  58. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -1
  59. package/lib/commonjs/hooks/useSharedContext.js +77 -0
  60. package/lib/commonjs/hooks/useSharedContext.js.map +1 -0
  61. package/lib/commonjs/hooks/useUnistyles.js +18 -65
  62. package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
  63. package/lib/commonjs/hooks/useVariants.js.map +1 -1
  64. package/lib/commonjs/index.js +7 -0
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/normalizer/index.js.map +1 -1
  67. package/lib/commonjs/normalizer/module.d.js.map +1 -1
  68. package/lib/commonjs/normalizer/normalizeStyle.js.map +1 -1
  69. package/lib/commonjs/normalizer/normalizer.js +1 -1
  70. package/lib/commonjs/normalizer/normalizer.js.map +1 -1
  71. package/lib/commonjs/normalizer/normalizer.macos.js.map +1 -1
  72. package/lib/commonjs/plugins/cssMediaQueriesPlugin.js.map +1 -1
  73. package/lib/commonjs/plugins/index.js.map +1 -1
  74. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +1 -1
  75. package/lib/commonjs/types/breakpoints.js.map +1 -1
  76. package/lib/commonjs/types/color.js +2 -0
  77. package/lib/commonjs/types/color.js.map +1 -0
  78. package/lib/commonjs/types/common.js.map +1 -1
  79. package/lib/commonjs/types/core.js.map +1 -1
  80. package/lib/commonjs/types/index.js +11 -0
  81. package/lib/commonjs/types/index.js.map +1 -1
  82. package/lib/commonjs/types/normalizer.js.map +1 -1
  83. package/lib/commonjs/types/plugin.js.map +1 -1
  84. package/lib/commonjs/types/stylesheet.js.map +1 -1
  85. package/lib/commonjs/types/unistyles.js.map +1 -1
  86. package/lib/commonjs/types/variants.js.map +1 -1
  87. package/lib/commonjs/useStyles.js +1 -1
  88. package/lib/commonjs/useStyles.js.map +1 -1
  89. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  90. package/lib/commonjs/utils/cssMediaQuery.js.map +1 -1
  91. package/lib/commonjs/utils/generateId.js.map +1 -1
  92. package/lib/commonjs/utils/hash32.js.map +1 -1
  93. package/lib/commonjs/utils/index.js +7 -0
  94. package/lib/commonjs/utils/index.js.map +1 -1
  95. package/lib/commonjs/utils/mq.js.map +1 -1
  96. package/lib/commonjs/utils/mqParser.js.map +1 -1
  97. package/lib/commonjs/utils/parseColor.js +35 -0
  98. package/lib/commonjs/utils/parseColor.js.map +1 -0
  99. package/lib/commonjs/utils/styles.js +15 -1
  100. package/lib/commonjs/utils/styles.js.map +1 -1
  101. package/lib/commonjs/utils/withPlugins.js.map +1 -1
  102. package/lib/module/UnistylesProvider.js +24 -0
  103. package/lib/module/UnistylesProvider.js.map +1 -0
  104. package/lib/module/common.js +2 -1
  105. package/lib/module/common.js.map +1 -1
  106. package/lib/module/core/UnistyleRegistry.js +15 -5
  107. package/lib/module/core/UnistyleRegistry.js.map +1 -1
  108. package/lib/module/core/Unistyles.js +8 -1
  109. package/lib/module/core/Unistyles.js.map +1 -1
  110. package/lib/module/core/UnistylesModule.js +52 -8
  111. package/lib/module/core/UnistylesModule.js.map +1 -1
  112. package/lib/module/core/UnistylesModule.native.js.map +1 -1
  113. package/lib/module/core/UnistylesModule.windows.js.map +1 -1
  114. package/lib/module/core/UnistylesRuntime.js +115 -4
  115. package/lib/module/core/UnistylesRuntime.js.map +1 -1
  116. package/lib/module/core/index.js +2 -1
  117. package/lib/module/core/index.js.map +1 -1
  118. package/lib/module/core/mocks/UnistylesMockedBridge.js +29 -0
  119. package/lib/module/core/mocks/UnistylesMockedBridge.js.map +1 -0
  120. package/lib/module/core/mocks/UnistylesMockedRegistry.js +39 -0
  121. package/lib/module/core/mocks/UnistylesMockedRegistry.js.map +1 -0
  122. package/lib/module/core/mocks/UnistylesMockedRuntime.js +114 -0
  123. package/lib/module/core/mocks/UnistylesMockedRuntime.js.map +1 -0
  124. package/lib/module/core/mocks/index.js +4 -0
  125. package/lib/module/core/mocks/index.js.map +1 -0
  126. package/lib/module/createStyleSheet.js.map +1 -1
  127. package/lib/module/global.js.map +1 -1
  128. package/lib/module/hooks/index.js.map +1 -1
  129. package/lib/module/hooks/useCSS.js.map +1 -1
  130. package/lib/module/hooks/useCSS.native.js.map +1 -1
  131. package/lib/module/hooks/useInitialTheme.js.map +1 -1
  132. package/lib/module/hooks/useSharedContext.js +70 -0
  133. package/lib/module/hooks/useSharedContext.js.map +1 -0
  134. package/lib/module/hooks/useUnistyles.js +19 -66
  135. package/lib/module/hooks/useUnistyles.js.map +1 -1
  136. package/lib/module/hooks/useVariants.js.map +1 -1
  137. package/lib/module/index.js +2 -2
  138. package/lib/module/index.js.map +1 -1
  139. package/lib/module/normalizer/index.js.map +1 -1
  140. package/lib/module/normalizer/module.d.js.map +1 -1
  141. package/lib/module/normalizer/normalizeStyle.js.map +1 -1
  142. package/lib/module/normalizer/normalizer.js.map +1 -1
  143. package/lib/module/normalizer/normalizer.macos.js.map +1 -1
  144. package/lib/module/plugins/cssMediaQueriesPlugin.js.map +1 -1
  145. package/lib/module/plugins/index.js.map +1 -1
  146. package/lib/module/plugins/normalizeWebStylesPlugin.js.map +1 -1
  147. package/lib/module/types/breakpoints.js.map +1 -1
  148. package/lib/module/types/color.js +2 -0
  149. package/lib/module/types/color.js.map +1 -0
  150. package/lib/module/types/common.js.map +1 -1
  151. package/lib/module/types/core.js.map +1 -1
  152. package/lib/module/types/index.js +1 -0
  153. package/lib/module/types/index.js.map +1 -1
  154. package/lib/module/types/normalizer.js.map +1 -1
  155. package/lib/module/types/plugin.js.map +1 -1
  156. package/lib/module/types/stylesheet.js.map +1 -1
  157. package/lib/module/types/unistyles.js.map +1 -1
  158. package/lib/module/types/variants.js.map +1 -1
  159. package/lib/module/useStyles.js +1 -1
  160. package/lib/module/useStyles.js.map +1 -1
  161. package/lib/module/utils/breakpoints.js.map +1 -1
  162. package/lib/module/utils/cssMediaQuery.js.map +1 -1
  163. package/lib/module/utils/generateId.js.map +1 -1
  164. package/lib/module/utils/hash32.js.map +1 -1
  165. package/lib/module/utils/index.js +1 -0
  166. package/lib/module/utils/index.js.map +1 -1
  167. package/lib/module/utils/mq.js.map +1 -1
  168. package/lib/module/utils/mqParser.js.map +1 -1
  169. package/lib/module/utils/parseColor.js +28 -0
  170. package/lib/module/utils/parseColor.js.map +1 -0
  171. package/lib/module/utils/styles.js +15 -1
  172. package/lib/module/utils/styles.js.map +1 -1
  173. package/lib/module/utils/withPlugins.js.map +1 -1
  174. package/lib/typescript/src/UnistylesProvider.d.ts +20 -0
  175. package/lib/typescript/src/UnistylesProvider.d.ts.map +1 -0
  176. package/lib/typescript/src/common.d.ts +3 -2
  177. package/lib/typescript/src/common.d.ts.map +1 -1
  178. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
  179. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -1
  180. package/lib/typescript/src/core/UnistylesModule.d.ts +1 -0
  181. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -1
  182. package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -1
  183. package/lib/typescript/src/core/UnistylesModule.windows.d.ts.map +1 -1
  184. package/lib/typescript/src/core/UnistylesRuntime.d.ts +84 -8
  185. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
  186. package/lib/typescript/src/core/index.d.ts +3 -1
  187. package/lib/typescript/src/core/index.d.ts.map +1 -1
  188. package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts +28 -0
  189. package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts.map +1 -0
  190. package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts +21 -0
  191. package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts.map +1 -0
  192. package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts +79 -0
  193. package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts.map +1 -0
  194. package/lib/typescript/src/core/mocks/index.d.ts +4 -0
  195. package/lib/typescript/src/core/mocks/index.d.ts.map +1 -0
  196. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
  197. package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -1
  198. package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -1
  199. package/lib/typescript/src/hooks/useSharedContext.d.ts +33 -0
  200. package/lib/typescript/src/hooks/useSharedContext.d.ts.map +1 -0
  201. package/lib/typescript/src/hooks/useUnistyles.d.ts +4 -19
  202. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
  203. package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -1
  204. package/lib/typescript/src/index.d.ts +7 -15
  205. package/lib/typescript/src/index.d.ts.map +1 -1
  206. package/lib/typescript/src/normalizer/normalizeStyle.d.ts.map +1 -1
  207. package/lib/typescript/src/types/breakpoints.d.ts +9 -8
  208. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  209. package/lib/typescript/src/types/color.d.ts +4 -0
  210. package/lib/typescript/src/types/color.d.ts.map +1 -0
  211. package/lib/typescript/src/types/core.d.ts +2 -2
  212. package/lib/typescript/src/types/core.d.ts.map +1 -1
  213. package/lib/typescript/src/types/index.d.ts +2 -1
  214. package/lib/typescript/src/types/index.d.ts.map +1 -1
  215. package/lib/typescript/src/types/normalizer.d.ts +1 -1
  216. package/lib/typescript/src/types/normalizer.d.ts.map +1 -1
  217. package/lib/typescript/src/types/stylesheet.d.ts +9 -6
  218. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  219. package/lib/typescript/src/types/unistyles.d.ts +20 -9
  220. package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
  221. package/lib/typescript/src/useStyles.d.ts +1 -1
  222. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  223. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  224. package/lib/typescript/src/utils/index.d.ts +1 -0
  225. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  226. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -1
  227. package/lib/typescript/src/utils/parseColor.d.ts +3 -0
  228. package/lib/typescript/src/utils/parseColor.d.ts.map +1 -0
  229. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  230. package/package.json +38 -25
  231. package/react-native-unistyles.podspec +4 -1
  232. package/src/UnistylesProvider.tsx +33 -0
  233. package/src/common.ts +3 -2
  234. package/src/core/UnistyleRegistry.ts +19 -5
  235. package/src/core/Unistyles.ts +10 -1
  236. package/src/core/UnistylesModule.ts +61 -14
  237. package/src/core/UnistylesRuntime.ts +120 -5
  238. package/src/core/index.ts +7 -1
  239. package/src/core/mocks/UnistylesMockedBridge.ts +30 -0
  240. package/src/core/mocks/UnistylesMockedRegistry.ts +47 -0
  241. package/src/core/mocks/UnistylesMockedRuntime.ts +144 -0
  242. package/src/core/mocks/index.ts +3 -0
  243. package/src/hooks/useSharedContext.ts +83 -0
  244. package/src/hooks/useUnistyles.ts +15 -71
  245. package/src/index.ts +10 -4
  246. package/src/types/breakpoints.ts +19 -9
  247. package/src/types/color.ts +26 -0
  248. package/src/types/core.ts +2 -2
  249. package/src/types/index.ts +5 -1
  250. package/src/types/normalizer.ts +1 -1
  251. package/src/types/stylesheet.ts +10 -7
  252. package/src/types/unistyles.ts +28 -12
  253. package/src/useStyles.ts +1 -1
  254. package/src/utils/index.ts +1 -0
  255. package/src/utils/parseColor.ts +33 -0
  256. package/src/utils/styles.ts +24 -1
  257. package/windows/ExperimentalFeatures.props +4 -4
  258. package/windows/NuGet.Config +0 -1
  259. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.h +42 -118
  260. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.vcxproj +7 -2
  261. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.vcxproj.filters +6 -1
  262. package/windows/ReactNativeUnistyles/packages.lock.json +31 -31
  263. package/android/src/main/java/com/unistyles/Config.kt +0 -116
  264. package/android/src/main/java/com/unistyles/Insets.kt +0 -138
  265. package/ios/UnistylesHelpers.h +0 -3
  266. package/ios/UnistylesHelpers.mm +0 -5
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
7
7
  "test:coverage": "jest --coverage",
8
8
  "tsc": "node_modules/typescript/bin/tsc --noEmit",
9
9
  "lint": "eslint . --ext .ts,.tsx",
10
- "prepare": "husky install && bob build",
10
+ "prepare": "husky && bob build",
11
11
  "precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn test'",
12
12
  "release": "release-it"
13
13
  },
@@ -43,6 +43,8 @@
43
43
  "react-native-macos",
44
44
  "react-native-windows",
45
45
  "react-native-web",
46
+ "react-native-tvos",
47
+ "react-native-visionos",
46
48
  "expo"
47
49
  ],
48
50
  "repository": "https://github.com/jpudysz/react-native-unistyles",
@@ -56,39 +58,40 @@
56
58
  "registry": "https://registry.npmjs.org/"
57
59
  },
58
60
  "devDependencies": {
59
- "@commitlint/config-conventional": "18.4.3",
60
- "@react-native/eslint-config": "0.74.0",
61
- "@react-native/normalize-colors": "0.74.1",
61
+ "@commitlint/config-conventional": "19.2.2",
62
+ "@react-native/eslint-config": "0.74.84",
63
+ "@react-native/normalize-colors": "0.74.84",
62
64
  "@release-it/conventional-changelog": "8.0.1",
63
65
  "@testing-library/react-hooks": "8.0.1",
64
- "@types/jest": "29.5.11",
65
- "@types/react": "18.2.46",
66
- "@typescript-eslint/eslint-plugin": "6.16.0",
67
- "@typescript-eslint/eslint-plugin-tslint": "6.16.0",
68
- "@typescript-eslint/parser": "6.16.0",
69
- "commitlint": "18.4.3",
66
+ "@types/jest": "29.5.12",
67
+ "@types/react": "18.3.3",
68
+ "@typescript-eslint/eslint-plugin": "6.21.0",
69
+ "@typescript-eslint/eslint-plugin-tslint": "6.21.0",
70
+ "@typescript-eslint/parser": "6.21.0",
71
+ "commitlint": "19.3.0",
70
72
  "concurrently": "8.2.2",
71
- "eslint": "8.56.0",
73
+ "eslint": "8.57.0",
72
74
  "eslint-config-codemask": "1.1.7",
73
- "eslint-plugin-functional": "6.0.0",
75
+ "eslint-plugin-functional": "6.6.0",
74
76
  "eslint-plugin-import": "2.29.1",
75
77
  "eslint-plugin-jsdoc": "46.10.1",
76
- "eslint-plugin-jsx-a11y": "6.8.0",
78
+ "eslint-plugin-jsx-a11y": "6.9.0",
77
79
  "eslint-plugin-nested-if": "1.0.0",
78
80
  "eslint-plugin-no-else": "0.2.2",
79
- "eslint-plugin-no-loops": "0.3.0",
81
+ "eslint-plugin-no-loops": "0.4.0",
80
82
  "eslint-plugin-prefer-arrow": "1.2.3",
81
- "eslint-plugin-react": "7.33.2",
82
- "eslint-plugin-react-hooks": "4.6.0",
83
- "husky": "8.0.3",
83
+ "eslint-plugin-react": "7.34.3",
84
+ "eslint-plugin-react-hooks": "4.6.2",
85
+ "husky": "9.0.11",
84
86
  "jest": "29.7.0",
85
- "react": "18.2.0",
86
- "react-native": "0.72.7",
87
+ "metro-react-native-babel-preset": "0.77.0",
88
+ "react": "18.3.1",
89
+ "react-native": "0.76.0",
87
90
  "react-native-builder-bob": "0.23.2",
88
- "react-native-web": "0.19.9",
89
- "react-test-renderer": "18.2.0",
90
- "release-it": "17.0.1",
91
- "typescript": "5.3.3"
91
+ "react-native-web": "0.19.12",
92
+ "react-test-renderer": "18.3.1",
93
+ "release-it": "17.4.0",
94
+ "typescript": "5.6.3"
92
95
  },
93
96
  "peerDependencies": {
94
97
  "@react-native/normalize-colors": "*",
@@ -109,13 +112,19 @@
109
112
  "optional": true
110
113
  }
111
114
  },
115
+ "resolutions": {
116
+ "@types/mime": "3.0.4"
117
+ },
112
118
  "workspaces": [
113
119
  "examples/expo",
114
120
  "examples/macos",
115
121
  "examples/win",
122
+ "examples/bare",
123
+ "examples/tv",
124
+ "examples/vision",
116
125
  "docs"
117
126
  ],
118
- "packageManager": "yarn@3.6.1",
127
+ "packageManager": "yarn@3.6.4",
119
128
  "engines": {
120
129
  "node": ">= 18.0.0"
121
130
  },
@@ -124,6 +133,10 @@
124
133
  "modulePathIgnorePatterns": [
125
134
  "<rootDir>/examples/expo/node_modules",
126
135
  "<rootDir>/examples/macos/node_modules",
136
+ "<rootDir>/examples/win/node_modules",
137
+ "<rootDir>/examples/bare/node_modules",
138
+ "<rootDir>/examples/tv/node_modules",
139
+ "<rootDir>/examples/vision/node_modules",
127
140
  "<rootDir>/docs/node_modules",
128
141
  "<rootDir>/lib/"
129
142
  ],
@@ -10,13 +10,16 @@ Pod::Spec.new do |s|
10
10
  s.license = package["license"]
11
11
  s.authors = package["author"]
12
12
 
13
- s.platforms = { :ios => min_ios_version_supported, :osx => "10.14" }
13
+ s.platforms = { :ios => min_ios_version_supported, :osx => "10.14", :tvos => "9.0", :visionos => "1.0" }
14
14
  s.source = { :git => package["repository"], :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = [
17
17
  "ios/**/*.{h,mm}",
18
18
  "cxx/*.{h,cpp}"
19
19
  ]
20
+ s.pod_target_xcconfig = {
21
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20"
22
+ }
20
23
 
21
24
  install_modules_dependencies(s)
22
25
  end
@@ -0,0 +1,33 @@
1
+ import React from 'react'
2
+ import type { UnistylesBreakpoints } from './global'
3
+ import type { ScreenDimensions, ScreenInsets, ScreenSize, UnistylesTheme } from './types'
4
+ import { useSharedContext } from './hooks/useSharedContext'
5
+
6
+ export type TUnistylesContext = {
7
+ plugins: Array<string>,
8
+ theme: UnistylesTheme,
9
+ layout: {
10
+ screen: ScreenSize,
11
+ statusBar: ScreenDimensions,
12
+ navigationBar: ScreenDimensions,
13
+ insets: ScreenInsets,
14
+ breakpoint: keyof UnistylesBreakpoints
15
+ orientation: 'landscape' | 'portrait'
16
+ }
17
+ }
18
+
19
+ export const UnistylesContext = React.createContext<TUnistylesContext | undefined>(undefined)
20
+
21
+ export const UnistylesProvider = ({ children }: { children: React.ReactNode }) => {
22
+ const { plugins, theme, layout } = useSharedContext({
23
+ // intentionally false, we want to listen for changes in the provider
24
+ useContext: false,
25
+ deps: []
26
+ })
27
+
28
+ return (
29
+ <UnistylesContext.Provider value={{ theme, layout, plugins }}>
30
+ {children}
31
+ </UnistylesContext.Provider>
32
+ )
33
+ }
package/src/common.ts CHANGED
@@ -9,6 +9,8 @@ export const isIOS = Platform.OS === 'ios'
9
9
  export const isAndroid = Platform.OS === 'android'
10
10
  export const isMobile = isIOS || isAndroid
11
11
  export const isServer = typeof window === 'undefined'
12
+ export const isDev = process.env.NODE_ENV !== 'production'
13
+ export const isTest = process.env.NODE_ENV === 'test' || process.env.JEST_WORKER_ID !== undefined || typeof jest !== 'undefined'
12
14
 
13
15
  export const ScreenOrientation = {
14
16
  Landscape: 'landscape',
@@ -44,8 +46,7 @@ export enum AndroidContentSizeCategory {
44
46
  export enum UnistylesEventType {
45
47
  Theme = 'theme',
46
48
  Layout = 'layout',
47
- Plugin = 'plugin',
48
- DynamicTypeSize = 'dynamicTypeSize'
49
+ Plugin = 'plugin'
49
50
  }
50
51
 
51
52
  export enum UnistylesError {
@@ -1,6 +1,6 @@
1
1
  import type { UnistylesBridge, UnistylesConfig, UnistylesPlugin } from '../types'
2
2
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
3
- import { isWeb, UnistylesError } from '../common'
3
+ import { isAndroid, isDev, isWeb, UnistylesError } from '../common'
4
4
  import { cssMediaQueriesPlugin, normalizeWebStylesPlugin } from '../plugins'
5
5
 
6
6
  export class UnistyleRegistry {
@@ -60,6 +60,14 @@ export class UnistyleRegistry {
60
60
  this.unistylesBridge.addPlugin(cssMediaQueriesPlugin.name, false)
61
61
  }
62
62
 
63
+ if (isWeb && config.windowResizeDebounceTimeMs !== undefined) {
64
+ this.unistylesBridge.setWindowResizeDebounceTimeMs(config.windowResizeDebounceTimeMs)
65
+ }
66
+
67
+ if (isAndroid && config.disableAnimatedInsets) {
68
+ this.unistylesBridge.disableAnimatedInsets()
69
+ }
70
+
63
71
  return {
64
72
  addBreakpoints: this.addBreakpoints,
65
73
  addThemes: this.addThemes
@@ -87,12 +95,18 @@ export class UnistyleRegistry {
87
95
  throw new Error(UnistylesError.InvalidPluginName)
88
96
  }
89
97
 
90
- if (this.plugins.some(({ name }) => name === plugin.name)) {
91
- throw new Error(UnistylesError.DuplicatePluginName)
98
+ const isAlreadyRegistered = this.plugins.some(({ name }) => name === plugin.name)
99
+
100
+ if (!isAlreadyRegistered) {
101
+ this.plugins = [plugin].concat(this.plugins)
102
+ this.unistylesBridge.addPlugin(plugin.name, notify)
103
+
104
+ return
92
105
  }
93
106
 
94
- this.plugins = [plugin].concat(this.plugins)
95
- this.unistylesBridge.addPlugin(plugin.name, notify)
107
+ if (!isDev) {
108
+ throw new Error(UnistylesError.DuplicatePluginName)
109
+ }
96
110
  }
97
111
 
98
112
  public removePlugin = (plugin: UnistylesPlugin) => {
@@ -2,7 +2,8 @@ import { UnistylesModule } from './UnistylesModule'
2
2
  import { UnistylesRuntime } from './UnistylesRuntime'
3
3
  import { UnistyleRegistry } from './UnistyleRegistry'
4
4
  import type { UnistylesBridge } from '../types'
5
- import { UnistylesError, isWeb } from '../common'
5
+ import { UnistylesError, isTest, isWeb } from '../common'
6
+ import { UnistylesMockedBridge, UnistylesMockedRegistry, UnistylesMockedRuntime } from './mocks'
6
7
 
7
8
  class Unistyles {
8
9
  private _runtime: UnistylesRuntime
@@ -10,6 +11,14 @@ class Unistyles {
10
11
  private _bridge: UnistylesBridge
11
12
 
12
13
  constructor() {
14
+ if (isTest) {
15
+ this._bridge = new UnistylesMockedBridge() as unknown as UnistylesBridge
16
+ this._registry = new UnistylesMockedRegistry(this._bridge) as unknown as UnistyleRegistry
17
+ this._runtime = new UnistylesMockedRuntime(this._bridge, this._registry) as unknown as UnistylesRuntime
18
+
19
+ return
20
+ }
21
+
13
22
  const isInstalled = UnistylesModule?.install() ?? false
14
23
 
15
24
  if (!isInstalled) {
@@ -1,11 +1,12 @@
1
1
  import { NativeEventEmitter, NativeModules } from 'react-native'
2
2
  import type { UnistylesThemes, UnistylesBreakpoints } from 'react-native-unistyles'
3
- import type { ColorSchemeName, ScreenInsets, ScreenDimensions } from '../types'
3
+ import type { ColorSchemeName, ScreenInsets, StatusBar, NavigationBar, Color } from '../types'
4
4
  import { normalizeWebStylesPlugin } from '../plugins'
5
5
  import { isServer } from '../common'
6
6
 
7
7
  export class UnistylesBridgeWeb {
8
8
  #timerRef?: ReturnType<typeof setTimeout> = undefined
9
+ #windowResizeDebounceTimeMs: number = 100
9
10
  #hasAdaptiveThemes: boolean = false
10
11
  #supportsAutomaticColorScheme = false
11
12
  #screenWidth = isServer ? undefined : window.innerWidth
@@ -25,20 +26,29 @@ export class UnistylesBridgeWeb {
25
26
  bottom: 0,
26
27
  left: 0
27
28
  }
28
- #statusBar: ScreenDimensions = {
29
+ #statusBar: StatusBar = {
29
30
  height: 0,
30
- width: 0
31
+ width: 0,
32
+ setColor: () => {},
33
+ setHidden: () => {}
31
34
  }
32
- #navigationBar: ScreenDimensions = {
35
+ #navigationBar: NavigationBar = {
33
36
  height: 0,
34
- width: 0
37
+ width: 0,
38
+ setColor: () => {},
39
+ setHidden: () => {}
35
40
  }
41
+ #pixelRatio = 1.0
42
+ #fontScale = 1.0
43
+ #hairlineWidth = 1
44
+ #rtl = false
36
45
 
37
46
  constructor() {
38
47
  if (!isServer) {
39
48
  this.setupListeners()
40
49
  this.#screenWidth = window.innerWidth
41
50
  this.#screenHeight = window.innerHeight
51
+ this.#rtl = document.documentElement.dir === 'rtl'
42
52
  }
43
53
  }
44
54
 
@@ -74,6 +84,14 @@ export class UnistylesBridgeWeb {
74
84
  return this.#statusBar
75
85
  case 'navigationBar':
76
86
  return this.#navigationBar
87
+ case 'pixelRatio':
88
+ return this.#pixelRatio
89
+ case 'fontScale':
90
+ return this.#fontScale
91
+ case 'hairlineWidth':
92
+ return this.#hairlineWidth
93
+ case 'rtl':
94
+ return this.#rtl
77
95
  case 'useTheme':
78
96
  return (themeName: keyof UnistylesThemes) => this.useTheme(themeName)
79
97
  case 'updateTheme':
@@ -86,6 +104,16 @@ export class UnistylesBridgeWeb {
86
104
  return (pluginName: string, notify: boolean) => this.addPlugin(pluginName, notify)
87
105
  case 'removePlugin':
88
106
  return (pluginName: string) => this.removePlugin(pluginName)
107
+ case 'setRootViewBackgroundColor':
108
+ return (color: Color | string) => this.setRootViewBackgroundColor(color)
109
+ case 'setImmersiveMode':
110
+ return () => {}
111
+ case 'setWindowResizeDebounceTimeMs':
112
+ return (timeMs: number) => {
113
+ if (timeMs >= 0) {
114
+ this.#windowResizeDebounceTimeMs = timeMs
115
+ }
116
+ }
89
117
  default:
90
118
  return Reflect.get(this, prop)
91
119
  }
@@ -119,6 +147,10 @@ export class UnistylesBridgeWeb {
119
147
  }
120
148
 
121
149
  private updateTheme(themeName: keyof UnistylesThemes) {
150
+ if (!this.#themeName) {
151
+ this.#themeName = this.getTheme()
152
+ }
153
+
122
154
  if (this.#themeName === themeName) {
123
155
  this.emitThemeChange()
124
156
  }
@@ -162,7 +194,6 @@ export class UnistylesBridgeWeb {
162
194
  }
163
195
 
164
196
  private getTheme(): keyof UnistylesThemes {
165
-
166
197
  if (this.#themes.length === 1) {
167
198
  return this.#themes.at(0) as keyof UnistylesThemes
168
199
  }
@@ -171,16 +202,21 @@ export class UnistylesBridgeWeb {
171
202
  }
172
203
 
173
204
  private setupListeners() {
174
- window.addEventListener('resize', () => {
175
- clearTimeout(this.#timerRef)
205
+ const onResize = () => {
206
+ this.#screenWidth = window.innerWidth
207
+ this.#screenHeight = window.innerHeight
208
+ this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth)
209
+
210
+ this.emitLayoutChange()
211
+ }
176
212
 
177
- this.#timerRef = setTimeout(() => {
178
- this.#screenWidth = window.innerWidth
179
- this.#screenHeight = window.innerHeight
180
- this.#breakpoint = this.getBreakpointFromScreenWidth(this.#screenWidth)
213
+ window.addEventListener('resize', () => {
214
+ if (this.#windowResizeDebounceTimeMs === 0) {
215
+ return onResize()
216
+ }
181
217
 
182
- this.emitLayoutChange()
183
- }, 100)
218
+ clearTimeout(this.#timerRef)
219
+ this.#timerRef = setTimeout(onResize, this.#windowResizeDebounceTimeMs)
184
220
  })
185
221
 
186
222
  window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
@@ -197,6 +233,13 @@ export class UnistylesBridgeWeb {
197
233
  this.emitThemeChange()
198
234
  }
199
235
  })
236
+
237
+ new MutationObserver(() => {
238
+ this.#rtl = document.documentElement.dir === 'rtl'
239
+ }).observe(document.documentElement, {
240
+ attributes: true,
241
+ attributeFilter: ['dir']
242
+ })
200
243
  }
201
244
 
202
245
  private getBreakpointFromScreenWidth(width: number): keyof UnistylesBreakpoints {
@@ -223,6 +266,10 @@ export class UnistylesBridgeWeb {
223
266
  return 'light'
224
267
  }
225
268
 
269
+ private setRootViewBackgroundColor(color?: Color | string) {
270
+ document.body.style.backgroundColor = color as string
271
+ }
272
+
226
273
  private emitPluginChange() {
227
274
  this.#unistylesEvents.emit('__unistylesOnChange', {
228
275
  type: 'plugin'
@@ -1,7 +1,8 @@
1
1
  import { ScreenOrientation, UnistylesError } from '../common'
2
- import type { UnistylesBridge, UnistylesPlugin } from '../types'
2
+ import type { Color, UnistylesBridge, UnistylesPlugin } from '../types'
3
3
  import type { UnistylesThemes } from '../global'
4
4
  import type { UnistyleRegistry } from './UnistyleRegistry'
5
+ import { parseColor } from '../utils/parseColor'
5
6
 
6
7
  /**
7
8
  * Utility to interact with the Unistyles during runtime
@@ -9,6 +10,32 @@ import type { UnistyleRegistry } from './UnistyleRegistry'
9
10
  export class UnistylesRuntime {
10
11
  constructor(private unistylesBridge: UnistylesBridge, private unistylesRegistry: UnistyleRegistry) {}
11
12
 
13
+ /**
14
+ * Get the mini runtime injected to creteStyleSheet
15
+ * @returns - The mini runtime
16
+ */
17
+ public get miniRuntime() {
18
+ return {
19
+ contentSizeCategory: this.contentSizeCategory,
20
+ breakpoint: this.breakpoint,
21
+ screen: this.screen,
22
+ insets: this.insets,
23
+ statusBar: {
24
+ width: this.statusBar.width,
25
+ height: this.statusBar.height
26
+ },
27
+ navigationBar: {
28
+ width: this.navigationBar.width,
29
+ height: this.navigationBar.height
30
+ },
31
+ orientation: this.orientation,
32
+ pixelRatio: this.pixelRatio,
33
+ fontScale: this.fontScale,
34
+ hairlineWidth: this.hairlineWidth,
35
+ rtl: this.rtl
36
+ }
37
+ }
38
+
12
39
  /**
13
40
  * Get the current color scheme
14
41
  * @returns - The current color scheme
@@ -17,6 +44,14 @@ export class UnistylesRuntime {
17
44
  return this.unistylesBridge.colorScheme
18
45
  }
19
46
 
47
+ /**
48
+ * Get the layout direction
49
+ * @returns - Boolean indicating if the layout direction is RTL
50
+ */
51
+ public get rtl() {
52
+ return this.unistylesBridge.rtl
53
+ }
54
+
20
55
  /**
21
56
  * Get info about adaptive themes
22
57
  * @returns - boolean indicating if the adaptive themes are enabled
@@ -59,6 +94,7 @@ export class UnistylesRuntime {
59
94
 
60
95
  /**
61
96
  * Get the names of currently enabled plugins
97
+ * @deprecated - Plugins will be removed in the next major release
62
98
  * @returns - The names of currently enabled plugins
63
99
  */
64
100
  public get enabledPlugins() {
@@ -86,18 +122,36 @@ export class UnistylesRuntime {
86
122
 
87
123
  /**
88
124
  * Get the status bar info
89
- * @returns - The status bar size { width, height }
125
+ * @returns - The status bar api { width, height, setColor, setHidden }
90
126
  */
91
127
  public get statusBar() {
92
- return this.unistylesBridge.statusBar
128
+ return {
129
+ width: this.unistylesBridge.statusBar.width,
130
+ height: this.unistylesBridge.statusBar.height,
131
+ setColor: (color?: Color, alpha?: number) => {
132
+ const [parsedColor, parsedAlpha] = parseColor(color, alpha)
133
+
134
+ this.unistylesBridge.statusBar.setColor(parsedColor, parsedAlpha)
135
+ },
136
+ setHidden: (hidden: boolean) => this.unistylesBridge.statusBar.setHidden(hidden)
137
+ }
93
138
  }
94
139
 
95
140
  /**
96
141
  * Get the navigation bar info (Android)
97
- * @returns - The navigation bar size { width, height }
142
+ * @returns - The navigation bar api { width, height, setColor, setHidden }
98
143
  */
99
144
  public get navigationBar() {
100
- return this.unistylesBridge.navigationBar
145
+ return {
146
+ width: this.unistylesBridge.navigationBar.width,
147
+ height: this.unistylesBridge.navigationBar.height,
148
+ setColor: (color?: Color, alpha?: number) => {
149
+ const [parsedColor, parsedAlpha] = parseColor(color, alpha)
150
+
151
+ this.unistylesBridge.navigationBar.setColor(parsedColor, parsedAlpha)
152
+ },
153
+ setHidden: (hidden: boolean) => this.unistylesBridge.navigationBar.setHidden(hidden)
154
+ }
101
155
  }
102
156
 
103
157
  /**
@@ -114,6 +168,65 @@ export class UnistylesRuntime {
114
168
  return ScreenOrientation.Portrait
115
169
  }
116
170
 
171
+ /**
172
+ * Get the pixel ratio
173
+ * @returns - The pixel ratio
174
+ */
175
+ public get pixelRatio() {
176
+ return this.unistylesBridge.pixelRatio
177
+ }
178
+
179
+ /**
180
+ * Get the font scale
181
+ * @returns - The font scale
182
+ */
183
+ public get fontScale() {
184
+ return parseFloat(this.unistylesBridge.fontScale.toFixed(2))
185
+ }
186
+
187
+ /**
188
+ * Get the hairline width
189
+ * @returns - The thinnest width of the platform
190
+ */
191
+ public get hairlineWidth() {
192
+ const pixelRatio = this.pixelRatio
193
+ const nearestPixel = Math.trunc(pixelRatio * 0.4) || 1
194
+
195
+ return nearestPixel / pixelRatio
196
+ }
197
+
198
+ /**
199
+ * Get theme by name
200
+ * @param themeName - The name of the theme to get or current theme if not specified
201
+ * @returns - The theme
202
+ */
203
+ public getTheme(themeName?: keyof UnistylesThemes) {
204
+ if (!themeName) {
205
+ return this.unistylesRegistry.getTheme(this.themeName)
206
+ }
207
+
208
+ return this.unistylesRegistry.getTheme(themeName)
209
+ }
210
+
211
+ /**
212
+ * Get the immersive mode (both status bar and navigation bar hidden (Android))
213
+ * @param isEnabled
214
+ */
215
+ public setImmersiveMode(isEnabled: boolean) {
216
+ return this.unistylesBridge.setImmersiveMode(isEnabled)
217
+ }
218
+
219
+ /**
220
+ * Set the root view background color
221
+ * @param color - The color to set
222
+ * @param alpha - Color alpha - default is 1
223
+ */
224
+ public setRootViewBackgroundColor = (color?: Color, alpha?: number) => {
225
+ const [parsedColor, parsedAlpha] = parseColor(color, alpha)
226
+
227
+ this.unistylesBridge.setRootViewBackgroundColor(parsedColor, parsedAlpha)
228
+ }
229
+
117
230
  /**
118
231
  * Switch to a different theme
119
232
  * @param name - The name of the theme to switch to
@@ -153,6 +266,7 @@ export class UnistylesRuntime {
153
266
 
154
267
  /**
155
268
  * Enable a plugin
269
+ * @deprecated - Plugins will be removed in the next major release
156
270
  * @param plugin - Plugin that conforms to UnistylesPlugin interface
157
271
  */
158
272
  public addPlugin = (plugin: UnistylesPlugin) => {
@@ -161,6 +275,7 @@ export class UnistylesRuntime {
161
275
 
162
276
  /**
163
277
  * Disable a plugin
278
+ * @deprecated - Plugins will be removed in the next major release
164
279
  * @param plugin - Plugin that conforms to UnistylesPlugin interface
165
280
  */
166
281
  public removePlugin = (plugin: UnistylesPlugin) => {
package/src/core/index.ts CHANGED
@@ -1,2 +1,8 @@
1
- export { unistyles } from './Unistyles'
1
+ import { unistyles } from './Unistyles'
2
2
  export type { UnistylesRuntime } from './UnistylesRuntime'
3
+
4
+ export type UnistylesMiniRuntime = typeof unistyles.runtime.miniRuntime
5
+
6
+ export {
7
+ unistyles
8
+ }
@@ -0,0 +1,30 @@
1
+ // @ts-nocheck
2
+ import type { UnistylesThemes, UnistylesBreakpoints } from '../../global'
3
+
4
+ export class UnistylesMockedBridge {
5
+ constructor() {}
6
+
7
+ public screenWidth() {}
8
+ public screenHeight() {}
9
+ public enabledPlugins() {}
10
+ public hasAdaptiveThemes() {}
11
+ public themeName() {}
12
+ public breakpoint() {}
13
+ public colorScheme() {}
14
+ public contentSizeCategory() {}
15
+ public sortedBreakpointPairs() {}
16
+ public insets() {}
17
+ public pixelRatio() {}
18
+ public fontScale() {}
19
+ public statusBar() {}
20
+ public navigationBar() {}
21
+ public themes(themes: Array<keyof UnistylesThemes>) {}
22
+ public useBreakpoints(breakpoints: UnistylesBreakpoints) {}
23
+ public useTheme(name: keyof UnistylesThemes) {}
24
+ public updateTheme(name: keyof UnistylesThemes) {}
25
+ public useAdaptiveThemes(enable: boolean) {}
26
+ public addPlugin(pluginName: string, notify: boolean) {}
27
+ public removePlugin(pluginName: string) {}
28
+ public setRootViewBackgroundColor(color?: string, alpha?: number) {}
29
+ public setImmersiveMode(isEnabled: boolean) {}
30
+ }