react-native-unistyles 3.0.0-beta.6 → 3.0.0-beta.8

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 (277) hide show
  1. package/README.md +19 -0
  2. package/android/CMakeLists.txt +2 -1
  3. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +4 -0
  4. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +29 -2
  5. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +4 -0
  6. package/android/src/main/java/com/unistyles/UnistylesModule.kt +5 -0
  7. package/cxx/common/Helpers.h +85 -0
  8. package/cxx/core/HashGenerator.cpp +1 -1
  9. package/cxx/core/HostUnistyle.cpp +28 -4
  10. package/cxx/core/HostUnistyle.h +1 -0
  11. package/cxx/core/UnistyleWrapper.h +6 -6
  12. package/cxx/core/UnistylesCommitHook.cpp +20 -17
  13. package/cxx/core/UnistylesMountHook.cpp +2 -2
  14. package/cxx/core/UnistylesMountHook.h +1 -4
  15. package/cxx/core/UnistylesRegistry.cpp +8 -6
  16. package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -5
  17. package/cxx/hybridObjects/HybridStyleSheet.cpp +1 -1
  18. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +5 -1
  19. package/cxx/parser/Parser.cpp +79 -14
  20. package/cxx/shadowTree/ShadowTrafficController.h +10 -4
  21. package/cxx/shadowTree/ShadowTreeManager.cpp +38 -35
  22. package/lib/commonjs/components/native/Animated.js +2 -2
  23. package/lib/commonjs/components/native/Animated.js.map +1 -1
  24. package/lib/commonjs/components/native/ImageBackground.js +29 -33
  25. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  26. package/lib/commonjs/components/native/NativeText.native.js.map +1 -1
  27. package/lib/commonjs/components/native/NativeView.native.js.map +1 -1
  28. package/lib/commonjs/components/native/Pressable.js +1 -1
  29. package/lib/commonjs/components/native/Pressable.js.map +1 -1
  30. package/lib/commonjs/components/native/Pressable.native.js +17 -10
  31. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  32. package/lib/commonjs/core/createUnistylesElement.js +5 -5
  33. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  34. package/lib/commonjs/core/createUnistylesElement.native.js +5 -1
  35. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  36. package/lib/commonjs/core/createUnistylesImageBackground.js +5 -1
  37. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  38. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +3 -3
  39. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  40. package/lib/commonjs/core/warn.js +1 -1
  41. package/lib/commonjs/core/withUnistyles/withUnistyles.js +2 -2
  42. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  43. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +18 -9
  44. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  45. package/lib/commonjs/hooks/useMedia.native.js +1 -1
  46. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  47. package/lib/commonjs/mq.js.map +1 -1
  48. package/lib/commonjs/server/getServerUnistyles.js +1 -1
  49. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  50. package/lib/commonjs/server/hydrateServerUnistyles.js +1 -1
  51. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  52. package/lib/commonjs/server/resetServerUnistyles.js +1 -1
  53. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  54. package/lib/commonjs/server/useServerUnistyles.js +2 -2
  55. package/lib/commonjs/server/useServerUnistyles.js.map +1 -1
  56. package/lib/commonjs/specs/ShadowRegistry/index.js +1 -1
  57. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  58. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  59. package/lib/commonjs/specs/StyleSheet/index.js +1 -1
  60. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  61. package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
  62. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  63. package/lib/commonjs/specs/index.native.js +3 -3
  64. package/lib/commonjs/specs/index.native.js.map +1 -1
  65. package/lib/commonjs/web/convert/index.js +4 -4
  66. package/lib/commonjs/web/convert/index.js.map +1 -1
  67. package/lib/commonjs/web/convert/object/boxShadow.js +4 -4
  68. package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
  69. package/lib/commonjs/web/convert/object/filter.js +3 -3
  70. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  71. package/lib/commonjs/web/convert/object/transform.js +1 -1
  72. package/lib/commonjs/web/convert/object/transform.js.map +1 -1
  73. package/lib/commonjs/web/convert/utils.js.map +1 -1
  74. package/lib/commonjs/web/index.js +1 -1
  75. package/lib/commonjs/web/index.js.map +1 -1
  76. package/lib/commonjs/web/registry.js +1 -1
  77. package/lib/commonjs/web/registry.js.map +1 -1
  78. package/lib/commonjs/web/runtime.js.map +1 -1
  79. package/lib/commonjs/web/shadowRegistry.js +1 -1
  80. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  81. package/lib/commonjs/web/state.js +1 -1
  82. package/lib/commonjs/web/state.js.map +1 -1
  83. package/lib/commonjs/web/utils/common.js +1 -1
  84. package/lib/commonjs/web/utils/unistyle.js +5 -5
  85. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  86. package/lib/module/components/native/Animated.js +2 -2
  87. package/lib/module/components/native/Animated.js.map +1 -1
  88. package/lib/module/components/native/ImageBackground.js +29 -33
  89. package/lib/module/components/native/ImageBackground.js.map +1 -1
  90. package/lib/module/components/native/NativeText.native.js.map +1 -1
  91. package/lib/module/components/native/NativeView.native.js.map +1 -1
  92. package/lib/module/components/native/Pressable.js +1 -1
  93. package/lib/module/components/native/Pressable.js.map +1 -1
  94. package/lib/module/components/native/Pressable.native.js +17 -10
  95. package/lib/module/components/native/Pressable.native.js.map +1 -1
  96. package/lib/module/core/createUnistylesElement.js +3 -3
  97. package/lib/module/core/createUnistylesElement.js.map +1 -1
  98. package/lib/module/core/createUnistylesElement.native.js +5 -1
  99. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  100. package/lib/module/core/createUnistylesImageBackground.js +5 -1
  101. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  102. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +3 -3
  103. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  104. package/lib/module/core/warn.js +1 -1
  105. package/lib/module/core/withUnistyles/withUnistyles.js +2 -2
  106. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  107. package/lib/module/core/withUnistyles/withUnistyles.native.js +19 -10
  108. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  109. package/lib/module/hooks/useMedia.native.js +1 -1
  110. package/lib/module/hooks/useMedia.native.js.map +1 -1
  111. package/lib/module/mq.js.map +1 -1
  112. package/lib/module/server/getServerUnistyles.js +1 -1
  113. package/lib/module/server/getServerUnistyles.js.map +1 -1
  114. package/lib/module/server/hydrateServerUnistyles.js +1 -1
  115. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  116. package/lib/module/server/resetServerUnistyles.js +1 -1
  117. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  118. package/lib/module/server/useServerUnistyles.js +2 -2
  119. package/lib/module/server/useServerUnistyles.js.map +1 -1
  120. package/lib/module/specs/ShadowRegistry/index.js +1 -1
  121. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  122. package/lib/module/specs/StatusBar/index.js.map +1 -1
  123. package/lib/module/specs/StyleSheet/index.js +1 -1
  124. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  125. package/lib/module/specs/UnistylesRuntime/index.js +1 -1
  126. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  127. package/lib/module/specs/index.native.js +4 -4
  128. package/lib/module/specs/index.native.js.map +1 -1
  129. package/lib/module/web/convert/index.js +5 -5
  130. package/lib/module/web/convert/index.js.map +1 -1
  131. package/lib/module/web/convert/object/boxShadow.js +2 -2
  132. package/lib/module/web/convert/object/boxShadow.js.map +1 -1
  133. package/lib/module/web/convert/object/filter.js +3 -3
  134. package/lib/module/web/convert/object/filter.js.map +1 -1
  135. package/lib/module/web/convert/object/transform.js +1 -1
  136. package/lib/module/web/convert/object/transform.js.map +1 -1
  137. package/lib/module/web/convert/utils.js.map +1 -1
  138. package/lib/module/web/index.js +1 -1
  139. package/lib/module/web/index.js.map +1 -1
  140. package/lib/module/web/registry.js +1 -1
  141. package/lib/module/web/registry.js.map +1 -1
  142. package/lib/module/web/runtime.js.map +1 -1
  143. package/lib/module/web/shadowRegistry.js +1 -1
  144. package/lib/module/web/shadowRegistry.js.map +1 -1
  145. package/lib/module/web/state.js +1 -1
  146. package/lib/module/web/state.js.map +1 -1
  147. package/lib/module/web/utils/common.js +1 -1
  148. package/lib/module/web/utils/unistyle.js +5 -5
  149. package/lib/module/web/utils/unistyle.js.map +1 -1
  150. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  151. package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -1
  152. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  153. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  154. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  155. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +2 -1
  156. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  157. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  158. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  159. package/lib/typescript/src/mq.d.ts +1 -1
  160. package/lib/typescript/src/mq.d.ts.map +1 -1
  161. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  162. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  163. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  164. package/lib/typescript/src/specs/StatusBar/index.d.ts +1 -1
  165. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  166. package/lib/typescript/src/specs/StyleSheet/index.d.ts +1 -1
  167. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  168. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +1 -1
  169. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  170. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +5 -5
  171. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  172. package/lib/typescript/src/specs/index.native.d.ts +4 -4
  173. package/lib/typescript/src/specs/index.native.d.ts.map +1 -1
  174. package/lib/typescript/src/types/breakpoints.d.ts +2 -2
  175. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  176. package/lib/typescript/src/types/core.d.ts +1 -1
  177. package/lib/typescript/src/types/core.d.ts.map +1 -1
  178. package/lib/typescript/src/types/stylesheet.d.ts +5 -5
  179. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  180. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  181. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  182. package/lib/typescript/src/web/convert/types.d.ts +1 -1
  183. package/lib/typescript/src/web/convert/types.d.ts.map +1 -1
  184. package/lib/typescript/src/web/convert/utils.d.ts +2 -2
  185. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  186. package/lib/typescript/src/web/create.d.ts +1 -1
  187. package/lib/typescript/src/web/create.d.ts.map +1 -1
  188. package/lib/typescript/src/web/index.d.ts +1 -1
  189. package/lib/typescript/src/web/index.d.ts.map +1 -1
  190. package/lib/typescript/src/web/registry.d.ts +1 -1
  191. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  192. package/lib/typescript/src/web/runtime.d.ts +1 -1
  193. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  194. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  195. package/lib/typescript/src/web/state.d.ts +1 -1
  196. package/lib/typescript/src/web/state.d.ts.map +1 -1
  197. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  198. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
  199. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
  200. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +19 -19
  201. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +1 -1
  202. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +7 -2
  203. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +7 -2
  204. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +1 -17
  205. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/unistylesOnLoad.kt +35 -0
  206. package/nitrogen/generated/android/unistyles+autolinking.cmake +16 -0
  207. package/nitrogen/generated/ios/Unistyles+autolinking.rb +2 -0
  208. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +1 -1
  209. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -1
  210. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +3 -1
  211. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +2 -3
  212. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +18 -18
  213. package/nitrogen/generated/shared/c++/ColorScheme.hpp +1 -1
  214. package/nitrogen/generated/shared/c++/Dimensions.hpp +2 -1
  215. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +1 -1
  216. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +1 -1
  217. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +1 -1
  218. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +1 -1
  219. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +1 -1
  220. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
  221. package/nitrogen/generated/shared/c++/Insets.hpp +2 -1
  222. package/nitrogen/generated/shared/c++/Orientation.hpp +1 -1
  223. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +1 -1
  224. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +2 -1
  225. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +2 -1
  226. package/package.json +31 -19
  227. package/plugin/index.d.ts +51 -18
  228. package/plugin/index.js +791 -189
  229. package/src/components/native/Animated.tsx +2 -2
  230. package/src/components/native/ImageBackground.tsx +6 -7
  231. package/src/components/native/NativeText.native.tsx +1 -1
  232. package/src/components/native/NativeView.native.tsx +1 -1
  233. package/src/components/native/Pressable.native.tsx +22 -12
  234. package/src/components/native/Pressable.tsx +1 -1
  235. package/src/core/createUnistylesElement.native.tsx +6 -1
  236. package/src/core/createUnistylesElement.tsx +3 -3
  237. package/src/core/createUnistylesImageBackground.tsx +6 -1
  238. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +4 -4
  239. package/src/core/warn.ts +1 -1
  240. package/src/core/withUnistyles/withUnistyles.native.tsx +47 -19
  241. package/src/core/withUnistyles/withUnistyles.tsx +4 -4
  242. package/src/hooks/useMedia.native.ts +1 -1
  243. package/src/mq.ts +1 -1
  244. package/src/server/getServerUnistyles.tsx +1 -1
  245. package/src/server/hydrateServerUnistyles.ts +1 -1
  246. package/src/server/resetServerUnistyles.ts +1 -1
  247. package/src/server/useServerUnistyles.tsx +2 -2
  248. package/src/specs/ShadowRegistry/index.ts +1 -0
  249. package/src/specs/StatusBar/index.ts +1 -1
  250. package/src/specs/StyleSheet/index.ts +3 -3
  251. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -1
  252. package/src/specs/UnistylesRuntime/index.ts +5 -5
  253. package/src/specs/index.native.ts +4 -4
  254. package/src/types/breakpoints.ts +2 -2
  255. package/src/types/core.ts +1 -1
  256. package/src/types/stylesheet.ts +5 -5
  257. package/src/web/convert/index.ts +5 -5
  258. package/src/web/convert/object/boxShadow.ts +2 -2
  259. package/src/web/convert/object/filter.ts +3 -3
  260. package/src/web/convert/object/transform.ts +2 -2
  261. package/src/web/convert/types.ts +1 -1
  262. package/src/web/convert/utils.ts +2 -2
  263. package/src/web/create.ts +1 -1
  264. package/src/web/index.ts +3 -3
  265. package/src/web/registry.ts +2 -2
  266. package/src/web/runtime.ts +2 -2
  267. package/src/web/shadowRegistry.ts +2 -2
  268. package/src/web/state.ts +4 -4
  269. package/src/web/utils/common.ts +1 -1
  270. package/src/web/utils/unistyle.ts +6 -6
  271. package/plugin/common.js +0 -142
  272. package/plugin/consts.js +0 -63
  273. package/plugin/exotic.js +0 -54
  274. package/plugin/import.js +0 -51
  275. package/plugin/ref.js +0 -11
  276. package/plugin/stylesheet.js +0 -239
  277. package/plugin/variants.js +0 -66
package/README.md CHANGED
@@ -18,6 +18,19 @@
18
18
  yarn add react-native-unistyles@beta
19
19
  ```
20
20
 
21
+ Install dependencies:
22
+
23
+ ```shell
24
+ yarn add react-native-edge-to-edge react-native-nitro-modules@0.22.1
25
+ ```
26
+
27
+ > Always use fixed version of `react-native-nitro-modules` to avoid unexpected behaviors.
28
+
29
+ | react-native-unistyles | react-native-nitro-modules |
30
+ |------------------------|----------------------------|
31
+ | 3.0.0.beta.7 | 0.22.1 |
32
+ | 3.0.0.nightly-20250226 | 0.24.1 |
33
+
21
34
  Then follow [installation guides](https://unistyl.es/v3/start/getting-started) for your platform.
22
35
 
23
36
  ## [Documentation](https://unistyl.es/)
@@ -74,6 +87,12 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
74
87
  <a href="https://github.com/4cc3ssX">
75
88
  <img src="https://avatars.githubusercontent.com/u/57473799?v=4" height="70px" width="70px" alt="4cc3ssX" />
76
89
  </a>
90
+ <a href="https://github.com/dacoto97">
91
+ <img src="https://avatars.githubusercontent.com/u/16915053?v=4" height="70px" width="70px" alt="dacoto97" />
92
+ </a>
93
+ <a href="https://github.com/chinamcafee">
94
+ <img src="https://avatars.githubusercontent.com/u/3439961?v=4" height="70px" width="70px" alt="chinamcafee" />
95
+ </a>
77
96
 
78
97
  ## Past sponsors
79
98
 
@@ -23,7 +23,8 @@ include_directories(
23
23
  ../cxx/shadowTree
24
24
  )
25
25
 
26
- string(APPEND CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_CFG_NO_COROUTINES=1 -DFOLLY_MOBILE=1")
26
+ # Nitro appends all Folly Flags, leaving it empty
27
+ string(APPEND CMAKE_CXX_FLAGS " ")
27
28
 
28
29
  set_target_properties(unistyles PROPERTIES
29
30
  CXX_STANDARD 20
@@ -6,11 +6,13 @@ import android.os.Build
6
6
  import android.util.DisplayMetrics
7
7
  import android.view.View
8
8
  import android.view.WindowManager
9
+ import androidx.annotation.Keep
9
10
  import androidx.core.text.TextUtilsCompat
10
11
  import androidx.core.view.ViewCompat
11
12
  import androidx.core.view.WindowCompat
12
13
  import androidx.core.view.WindowInsetsCompat
13
14
  import androidx.core.view.WindowInsetsControllerCompat
15
+ import com.facebook.proguard.annotations.DoNotStrip
14
16
  import com.facebook.react.bridge.LifecycleEventListener
15
17
  import com.facebook.react.bridge.ReactApplicationContext
16
18
  import com.margelo.nitro.unistyles.ColorScheme
@@ -22,6 +24,8 @@ import com.margelo.nitro.unistyles.UnistyleDependency
22
24
  import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
23
25
  import java.util.Locale
24
26
 
27
+ @Keep
28
+ @DoNotStrip
25
29
  class NativePlatformAndroid(private val reactContext: ReactApplicationContext): HybridNativePlatformSpec(), LifecycleEventListener {
26
30
  private val _insets = NativePlatformInsets(reactContext, this::getMiniRuntime) { this.diffMiniRuntime() }
27
31
  private var _miniRuntime: UnistylesNativeMiniRuntime = buildMiniRuntime()
@@ -5,9 +5,11 @@ import android.os.Build
5
5
  import android.view.View
6
6
  import android.view.Window
7
7
  import android.view.WindowManager
8
+ import androidx.annotation.Keep
8
9
  import androidx.core.view.ViewCompat
9
10
  import androidx.core.view.WindowInsetsAnimationCompat
10
11
  import androidx.core.view.WindowInsetsCompat
12
+ import com.facebook.proguard.annotations.DoNotStrip
11
13
  import com.facebook.react.bridge.ReactApplicationContext
12
14
  import com.margelo.nitro.unistyles.Insets
13
15
  import com.margelo.nitro.unistyles.UnistyleDependency
@@ -15,14 +17,28 @@ import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
15
17
 
16
18
  typealias CxxImeListener = (miniRuntime: UnistylesNativeMiniRuntime) -> Unit
17
19
 
20
+ @Keep
21
+ @DoNotStrip
18
22
  class NativePlatformInsets(
19
23
  private val reactContext: ReactApplicationContext,
20
24
  private val getMiniRuntime: () -> UnistylesNativeMiniRuntime,
21
25
  private val diffMiniRuntime: () -> Array<UnistyleDependency>
22
26
  ) {
27
+ private var _shouldListenToImeEvents = false
23
28
  private val _imeListeners: MutableList<CxxImeListener> = mutableListOf()
24
29
  private var _insets: Insets = Insets(0.0, 0.0, 0.0, 0.0, 0.0)
25
30
 
31
+ init {
32
+ // get initial insets
33
+ reactContext.currentActivity?.let { activity ->
34
+ val insets = ViewCompat.getRootWindowInsets(activity.window.decorView)
35
+
36
+ insets?.let { windowInsets ->
37
+ setInsets(windowInsets, activity.window, null, true)
38
+ }
39
+ }
40
+ }
41
+
26
42
  fun onDestroy() {
27
43
  this.removeImeListeners()
28
44
  }
@@ -39,7 +55,7 @@ class NativePlatformInsets(
39
55
  )
40
56
  }
41
57
 
42
- fun setInsets(insetsCompat: WindowInsetsCompat, window: Window, animatedBottomInsets: Double?) {
58
+ fun setInsets(insetsCompat: WindowInsetsCompat, window: Window, animatedBottomInsets: Double?, skipUpdate: Boolean = false) {
43
59
  // below Android 11, we need to use window flags to detect status bar visibility
44
60
  val isStatusBarVisible = when(Build.VERSION.SDK_INT) {
45
61
  in 30..Int.MAX_VALUE -> {
@@ -86,6 +102,10 @@ class NativePlatformInsets(
86
102
  imeInsets
87
103
  )
88
104
 
105
+ if (skipUpdate) {
106
+ return
107
+ }
108
+
89
109
  diffMiniRuntime()
90
110
 
91
111
  if (shouldEmitImeEvent) {
@@ -94,6 +114,8 @@ class NativePlatformInsets(
94
114
  }
95
115
 
96
116
  fun startInsetsListener() {
117
+ _shouldListenToImeEvents = true
118
+
97
119
  reactContext.currentActivity?.let { activity ->
98
120
  activity.findViewById<View>(android.R.id.content)?.let { mainView ->
99
121
  ViewCompat.setOnApplyWindowInsetsListener(mainView) { _, insets ->
@@ -111,6 +133,10 @@ class NativePlatformInsets(
111
133
  insets: WindowInsetsCompat,
112
134
  runningAnimations: List<WindowInsetsAnimationCompat>
113
135
  ): WindowInsetsCompat {
136
+ if (!_shouldListenToImeEvents) {
137
+ return insets
138
+ }
139
+
114
140
  runningAnimations.firstOrNull()?.let {
115
141
  val bottomInset = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom.toDouble() - this@NativePlatformInsets._insets.bottom
116
142
  val nextBottomInset = if (bottomInset < 0) {
@@ -141,9 +167,10 @@ class NativePlatformInsets(
141
167
  reactContext.currentActivity?.let { activity ->
142
168
  activity.window?.decorView?.let { view ->
143
169
  ViewCompat.setOnApplyWindowInsetsListener(view, null)
144
- ViewCompat.setWindowInsetsAnimationCallback(view, null)
145
170
  }
146
171
  }
172
+
173
+ _shouldListenToImeEvents = false
147
174
  }
148
175
 
149
176
  fun addImeListener(listener: CxxImeListener) {
@@ -6,12 +6,16 @@ import android.content.Intent
6
6
  import android.content.IntentFilter
7
7
  import android.os.Handler
8
8
  import android.os.Looper
9
+ import androidx.annotation.Keep
10
+ import com.facebook.proguard.annotations.DoNotStrip
9
11
  import com.facebook.react.bridge.ReactApplicationContext
10
12
  import com.margelo.nitro.unistyles.UnistyleDependency
11
13
  import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
12
14
 
13
15
  typealias CxxDependencyListener = (dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime) -> Unit
14
16
 
17
+ @Keep
18
+ @DoNotStrip
15
19
  class NativePlatformListener(
16
20
  private val reactContext: ReactApplicationContext,
17
21
  private val getMiniRuntime: () -> UnistylesNativeMiniRuntime,
@@ -11,6 +11,7 @@ import com.facebook.react.turbomodule.core.interfaces.TurboModuleWithJSIBindings
11
11
  import com.facebook.react.uimanager.UIManagerHelper
12
12
  import com.facebook.react.uimanager.common.UIManagerType
13
13
  import com.margelo.nitro.unistyles.HybridNativePlatformSpec
14
+ import com.margelo.nitro.unistyles.unistylesOnLoad.Companion.initializeNative
14
15
 
15
16
  @Suppress("KotlinJniMissingFunction")
16
17
  class UnistylesModule(reactContext: ReactApplicationContext): NativeTurboUnistylesSpec(reactContext), TurboModuleWithJSIBindings {
@@ -20,6 +21,10 @@ class UnistylesModule(reactContext: ReactApplicationContext): NativeTurboUnistyl
20
21
 
21
22
  companion object {
22
23
  const val NAME = NativeTurboUnistylesSpec.NAME
24
+
25
+ init {
26
+ initializeNative()
27
+ }
23
28
  }
24
29
 
25
30
  init {
@@ -225,4 +225,89 @@ inline static jsi::Array dependenciesToJSIArray(jsi::Runtime& rt, const std::vec
225
225
  return result;
226
226
  }
227
227
 
228
+ inline void debugPrintJSIObject(jsi::Runtime& rt, std::string& name, jsi::Object& obj) {
229
+ auto console = rt.global().getPropertyAsObject(rt, "console");
230
+ auto log = console.getPropertyAsFunction(rt, "log");
231
+ auto parser = [&](const std::string& key, jsi::Value& value){
232
+ if (value.isBool()) {
233
+ std::string output = key + ": " + (value.getBool() ? "true" : "false");
234
+ log.call(rt, output);
235
+
236
+ return;
237
+ }
238
+
239
+ if (value.isNumber()) {
240
+ std::string output = key + ": " + std::to_string(value.getNumber());
241
+ log.call(rt, output);
242
+
243
+ return;
244
+ }
245
+
246
+ if (value.isString()) {
247
+ std::string output = key + ": " + value.getString(rt).utf8(rt);
248
+ log.call(rt, output);
249
+
250
+ return;
251
+ }
252
+
253
+ if (value.isUndefined()) {
254
+ std::string output = key + ": undefined";
255
+ log.call(rt, output);
256
+
257
+ return;
258
+ }
259
+
260
+ if (value.isNull()) {
261
+ std::string output = key + ": null";
262
+ log.call(rt, output);
263
+
264
+ return;
265
+ }
266
+ };
267
+
268
+ log.call(rt, "===" + name + "===");
269
+
270
+ enumerateJSIObject(rt, obj, [&](const std::string& key, jsi::Value& value){
271
+ if (value.isObject()) {
272
+ if (value.asObject(rt).isArray(rt)) {
273
+ iterateJSIArray(rt, value.asObject(rt).asArray(rt), [&](size_t i, jsi::Value& nestedValue){
274
+ std::string printableKey = key + ": Array[" + std::to_string(i) + "]";
275
+
276
+ log.call(rt, printableKey);
277
+
278
+ if (nestedValue.isObject()) {
279
+ enumerateJSIObject(rt, nestedValue.asObject(rt), [&](const std::string& nestedKey, jsi::Value& nestedValue){
280
+ parser(nestedKey, nestedValue);
281
+ });
282
+ } else {
283
+ parser(printableKey, nestedValue);
284
+ }
285
+
286
+ std::string endKey = key + ": Array[end]";
287
+
288
+ log.call(rt, endKey);
289
+ });
290
+ }
291
+
292
+ if (value.asObject(rt).isFunction(rt)) {
293
+ std::string output = key + ": [Function]";
294
+
295
+ log.call(rt, output);
296
+
297
+ return;
298
+ }
299
+
300
+ enumerateJSIObject(rt, value.asObject(rt), [&](const std::string& nestedKey, jsi::Value& nestedValue){
301
+ parser(nestedKey, nestedValue);
302
+ });
303
+
304
+ return;
305
+ }
306
+
307
+ parser(key, value);
308
+ });
309
+
310
+ log.call(rt, "===/" + name + "===");
311
+ }
312
+
228
313
  }
@@ -17,7 +17,7 @@ std::string HashGenerator::generateHash(const std::string& input) {
17
17
  std::stringstream ss;
18
18
  ss << std::hex << std::setfill('0') << std::setw(8) << (combinedHash & 0xFFFFFFFF);
19
19
 
20
- return "unistyles-" + ss.str();
20
+ return "unistyles_" + ss.str();
21
21
  }
22
22
 
23
23
  }
@@ -39,14 +39,40 @@ jsi::Value HostUnistyle::get(jsi::Runtime& rt, const jsi::PropNameID& propNameId
39
39
  auto& unistyle = this->_stylesheet->unistyles[propertyName];
40
40
 
41
41
  // check if Unistyles recomputed new style in the background
42
- // ()when no node was mounted), if so we need to simply rebuild unistyle to get fresh data
42
+ // (when no node was mounted), if so we need to simply rebuild unistyle to get fresh data
43
43
  if (unistyle->isDirty) {
44
+ this->_cache.erase(propertyName);
45
+
44
46
  auto parser = parser::Parser(this->_unistylesRuntime);
45
47
 
46
48
  parser.rebuildUnistyle(rt, unistyle, this->_variants, std::nullopt);
47
49
  }
48
50
 
49
- return valueFromUnistyle(rt, this->_unistylesRuntime, this->_stylesheet->unistyles[propertyName], this->_variants);
51
+ if (unistyle->type == UnistyleType::DynamicFunction) {
52
+ // for dynamic functions we will also bind "this"
53
+ auto styleFn = valueFromUnistyle(rt, this->_unistylesRuntime, unistyle, this->_variants);
54
+
55
+ // construct newThis
56
+ jsi::Object newThis = jsi::Object(rt);
57
+ newThis.setProperty(rt, helpers::STYLESHEET_VARIANTS.c_str(), helpers::variantsToValue(rt, this->_variants));
58
+
59
+ auto functionPrototype = rt.global()
60
+ .getPropertyAsObject(rt, "Function")
61
+ .getPropertyAsObject(rt, "prototype")
62
+ .getPropertyAsFunction(rt, "bind");
63
+
64
+ return functionPrototype.callWithThis(rt, styleFn.asObject(rt), newThis);
65
+ }
66
+
67
+ if (this->_cache.contains(propertyName)) {
68
+ return jsi::Value(rt, this->_cache[propertyName]);
69
+ }
70
+
71
+ auto style = valueFromUnistyle(rt, this->_unistylesRuntime, unistyle, this->_variants);
72
+
73
+ this->_cache.emplace(propertyName, jsi::Value(rt, style));
74
+
75
+ return style;
50
76
  }
51
77
 
52
78
  void HostUnistyle::set(jsi::Runtime& rt, const jsi::PropNameID& propNameId, const jsi::Value& value) {}
@@ -73,8 +99,6 @@ jsi::Function HostUnistyle::createAddVariantsProxyFunction(jsi::Runtime& rt) {
73
99
  }
74
100
  });
75
101
 
76
- this->_variants = variants;
77
-
78
102
  auto style = std::make_shared<core::HostUnistyle>(this->_stylesheet, this->_unistylesRuntime, variants);
79
103
  auto styleHostObject = jsi::Object::createFromHostObject(rt, style);
80
104
 
@@ -22,6 +22,7 @@ private:
22
22
  Variants _variants;
23
23
  std::shared_ptr<StyleSheet> _stylesheet;
24
24
  std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
25
+ std::unordered_map<std::string, jsi::Value> _cache;
25
26
  };
26
27
 
27
28
  }
@@ -35,7 +35,7 @@ inline static Unistyle::Shared unistyleFromStaticStyleSheet(jsi::Runtime& rt, js
35
35
 
36
36
  inline static std::vector<std::string> getUnistylesHashKeys(jsi::Runtime& rt, jsi::Object& object) {
37
37
  std::vector<std::string> matchingKeys{};
38
- const std::string prefix = "unistyles-";
38
+ const std::string prefix = "unistyles_";
39
39
 
40
40
  auto propertyNames = object.getPropertyNames(rt);
41
41
  size_t length = propertyNames.length(rt);
@@ -82,13 +82,13 @@ inline static std::vector<Unistyle::Shared> unistylesFromNonExistentNativeState(
82
82
 
83
83
  You likely altered unistyle hash key and we're not able to recover C++ state attached to this node.)");
84
84
  }
85
-
85
+
86
86
  // someone merged unistyles, and will be warned in JS
87
87
  // the best we can do is to return first unistyle
88
88
  if (unistyles.size() > 1) {
89
89
  return {unistyles.at(0)};
90
90
  }
91
-
91
+
92
92
  return unistyles;
93
93
  }
94
94
 
@@ -137,7 +137,7 @@ inline static jsi::Value objectFromUnistyle(jsi::Runtime& rt, std::shared_ptr<Hy
137
137
  auto parsedArguments = arguments.has_value()
138
138
  ? helpers::parseDynamicFunctionArguments(rt, arguments.value())
139
139
  : std::optional<std::vector<folly::dynamic>>{};
140
-
140
+
141
141
  if (arguments.has_value()) {
142
142
  // this is required for HybridShadowRegistry::link
143
143
  helpers::defineHiddenProperty(rt, secrets, helpers::ARGUMENTS.c_str(), arguments.value());
@@ -148,7 +148,7 @@ inline static jsi::Value objectFromUnistyle(jsi::Runtime& rt, std::shared_ptr<Hy
148
148
 
149
149
  // this is required for withUnistyles
150
150
  helpers::defineHiddenProperty(rt, secrets, helpers::STYLE_DEPENDENCIES.c_str(), helpers::dependenciesToJSIArray(rt, unistyle->dependencies));
151
-
151
+
152
152
  // this is required for withUnistyles
153
153
  auto hostFn = jsi::Function::createFromHostFunction(
154
154
  rt,
@@ -160,7 +160,7 @@ inline static jsi::Value objectFromUnistyle(jsi::Runtime& rt, std::shared_ptr<Hy
160
160
 
161
161
  return jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
162
162
  });
163
-
163
+
164
164
  helpers::defineHiddenProperty(rt, secrets, helpers::GET_STYLES.c_str(), std::move(hostFn));
165
165
 
166
166
  obj.setProperty(rt, unistyleID, secrets);
@@ -29,21 +29,24 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
29
29
  // this is React Native / Reanimated commit
30
30
  // merge Unistyles updates before it completes
31
31
  auto& registry = core::UnistylesRegistry::get();
32
- auto& shadowLeafUpdates = registry.trafficController.getUpdates();
33
-
34
- // oops, no updates from Unistyles yet, skip it!
35
- if (shadowLeafUpdates.size() == 0) {
36
- return newRootShadowNode;
37
- }
38
-
39
- auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
40
-
41
- registry.trafficController.stopUnistylesTraffic();
42
-
43
- // we have few updates, so merge it
44
- return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
45
- *rootNode,
46
- shadowLeafUpdates,
47
- affectedNodes
48
- ));
32
+
33
+ return registry.trafficController.withLock([&](){
34
+ auto& shadowLeafUpdates = registry.trafficController.getUpdates();
35
+
36
+ // oops, no updates from Unistyles yet, skip it!
37
+ if (shadowLeafUpdates.size() == 0) {
38
+ return newRootShadowNode;
39
+ }
40
+
41
+ auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
42
+
43
+ registry.trafficController.stopUnistylesTraffic();
44
+
45
+ // we have few updates, so merge it
46
+ return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
47
+ *rootNode,
48
+ shadowLeafUpdates,
49
+ affectedNodes
50
+ ));
51
+ });
49
52
  }
@@ -22,7 +22,7 @@ void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &
22
22
  // one more time merge Unistyles changes
23
23
  auto& registry = core::UnistylesRegistry::get();
24
24
 
25
- if (!registry.trafficController.shouldStop()) {
26
- shadow::ShadowTreeManager::updateShadowTree(this->_uiManager->getShadowTreeRegistry());
25
+ if (registry.trafficController.shouldStop()) {
26
+ registry.trafficController.resumeUnistylesTraffic();
27
27
  }
28
28
  }
@@ -3,15 +3,13 @@
3
3
  #include <react/renderer/uimanager/UIManager.h>
4
4
  #include <react/renderer/uimanager/UIManagerMountHook.h>
5
5
  #include "ShadowTreeManager.h"
6
- #include "HybridUnistylesRuntime.h"
7
6
 
8
7
  namespace margelo::nitro::unistyles::core {
9
8
 
10
9
  using namespace facebook::react;
11
10
 
12
11
  struct UnistylesMountHook : public UIManagerMountHook {
13
- UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
14
- : _uiManager{uiManager}, _unistylesRuntime{unistylesRuntime} {
12
+ UnistylesMountHook(std::shared_ptr<UIManager> uiManager): _uiManager{uiManager} {
15
13
  _uiManager->registerMountHook(*this);
16
14
  }
17
15
 
@@ -21,7 +19,6 @@ struct UnistylesMountHook : public UIManagerMountHook {
21
19
 
22
20
  private:
23
21
  std::shared_ptr<UIManager> _uiManager;
24
- std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
25
22
  };
26
23
 
27
24
  }
@@ -108,12 +108,14 @@ void core::UnistylesRegistry::removeDuplicatedUnistyles(jsi::Runtime& rt, const
108
108
  }
109
109
 
110
110
  void core::UnistylesRegistry::unlinkShadowNodeWithUnistyles(jsi::Runtime& rt, const ShadowNodeFamily* shadowNodeFamily) {
111
- this->_shadowRegistry[&rt].erase(shadowNodeFamily);
112
- this->trafficController.removeShadowNode(shadowNodeFamily);
113
-
114
- if (this->_shadowRegistry[&rt].empty()) {
115
- this->_shadowRegistry.erase(&rt);
116
- }
111
+ this->trafficController.withLock([this, &rt, shadowNodeFamily](){
112
+ this->_shadowRegistry[&rt].erase(shadowNodeFamily);
113
+ this->trafficController.removeShadowNode(shadowNodeFamily);
114
+
115
+ if (this->_shadowRegistry[&rt].empty()) {
116
+ this->_shadowRegistry.erase(&rt);
117
+ }
118
+ });
117
119
  }
118
120
 
119
121
  std::shared_ptr<core::StyleSheet> core::UnistylesRegistry::addStyleSheet(jsi::Runtime& rt, int unid, core::StyleSheetType type, jsi::Object&& rawValue) {
@@ -49,7 +49,6 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
49
49
  }
50
50
 
51
51
  auto parser = parser::Parser(this->_unistylesRuntime);
52
- auto parsedStyleSheet = jsi::Value::undefined();
53
52
  std::vector<std::shared_ptr<core::UnistyleData>> unistylesData{};
54
53
 
55
54
  // create unistyleData based on wrappers
@@ -77,10 +76,8 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
77
76
  );
78
77
 
79
78
  // before linking we need to check if given unistyle is affected by scoped theme
80
- if (scopedTheme.has_value()) {
81
- if (parsedStyleSheet.isUndefined()) {
82
- parsedStyleSheet = parser.getParsedStyleSheetForScopedTheme(rt, unistyle, scopedTheme.value());
83
- }
79
+ if (scopedTheme.has_value() && unistyle->styleKey != helpers::EXOTIC_STYLE_KEY) {
80
+ auto parsedStyleSheet = parser.getParsedStyleSheetForScopedTheme(rt, unistyle, scopedTheme.value());
84
81
 
85
82
  // if so we need to force update
86
83
  parser.rebuildUnistyleWithScopedTheme(rt, parsedStyleSheet, unistyleData);
@@ -261,7 +261,7 @@ void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
261
261
  core::UnistylesRegistry::get().trafficController.restore();
262
262
 
263
263
  this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager);
264
- this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime);
264
+ this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager);
265
265
  }
266
266
 
267
267
  void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies) {
@@ -73,9 +73,13 @@ void HybridUnistylesRuntime::setTheme(const std::string &themeName) {
73
73
  helpers::assertThat(*_rt, !this->getHasAdaptiveThemes(), "Unistyles: You're trying to set theme to: '" + themeName + "', but adaptiveThemes are enabled.");
74
74
 
75
75
  auto& state = core::UnistylesRegistry::get().getState(*_rt);
76
+ auto currentThemeName = state.getCurrentThemeName();
76
77
 
77
78
  state.setTheme(themeName);
78
- this->_onDependenciesChange({UnistyleDependency::THEME, UnistyleDependency::THEMENAME});
79
+
80
+ if (currentThemeName.value() != themeName) {
81
+ this->_onDependenciesChange({UnistyleDependency::THEME, UnistyleDependency::THEMENAME});
82
+ }
79
83
  };
80
84
 
81
85
  void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {