react-native-unistyles 3.0.0-alpha.38 → 3.0.0-alpha.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. package/android/build.gradle +4 -4
  2. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +13 -30
  3. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +22 -18
  4. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +10 -5
  5. package/cxx/core/UnistyleWrapper.h +27 -10
  6. package/cxx/core/UnistylesRegistry.cpp +34 -10
  7. package/cxx/core/UnistylesRegistry.h +2 -2
  8. package/cxx/hybridObjects/HybridNavigationBar.cpp +0 -4
  9. package/cxx/hybridObjects/HybridNavigationBar.h +0 -1
  10. package/cxx/hybridObjects/HybridShadowRegistry.cpp +7 -3
  11. package/cxx/hybridObjects/HybridStatusBar.cpp +0 -4
  12. package/cxx/hybridObjects/HybridStatusBar.h +0 -1
  13. package/cxx/hybridObjects/HybridStyleSheet.cpp +59 -28
  14. package/cxx/hybridObjects/HybridStyleSheet.h +7 -3
  15. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +37 -6
  16. package/cxx/hybridObjects/HybridUnistylesRuntime.h +7 -3
  17. package/cxx/parser/Parser.cpp +7 -7
  18. package/cxx/parser/Parser.h +2 -2
  19. package/ios/NativePlatform+ios.swift +2 -4
  20. package/ios/NativePlatform+keyboard.swift +1 -1
  21. package/ios/NativePlatformListener+ios.swift +6 -6
  22. package/ios/UnistylesModuleOnLoad.h +1 -6
  23. package/lib/commonjs/core/createUnistylesComponent.js +27 -20
  24. package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
  25. package/lib/commonjs/core/createUnistylesComponent.native.js +14 -17
  26. package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -1
  27. package/lib/commonjs/specs/NavigtionBar/index.js +0 -15
  28. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
  29. package/lib/commonjs/specs/ShadowRegistry/index.js +5 -7
  30. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  31. package/lib/commonjs/specs/StatusBar/index.js +0 -5
  32. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  33. package/lib/commonjs/specs/UnistylesRuntime/index.js +0 -2
  34. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  35. package/lib/commonjs/utils.js +26 -0
  36. package/lib/commonjs/utils.js.map +1 -0
  37. package/lib/commonjs/web/convert/index.js +1 -1
  38. package/lib/commonjs/web/convert/object/boxShadow.js +2 -1
  39. package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
  40. package/lib/commonjs/web/convert/object/objectStyle.js +3 -2
  41. package/lib/commonjs/web/convert/object/objectStyle.js.map +1 -1
  42. package/lib/commonjs/web/convert/shadow/boxShadow.js +1 -1
  43. package/lib/commonjs/web/convert/shadow/textShadow.js +1 -1
  44. package/lib/commonjs/web/create.js +2 -1
  45. package/lib/commonjs/web/create.js.map +1 -1
  46. package/lib/commonjs/web/index.js +1 -1
  47. package/lib/commonjs/web/listener.js +18 -2
  48. package/lib/commonjs/web/listener.js.map +1 -1
  49. package/lib/commonjs/web/mock.js +1 -2
  50. package/lib/commonjs/web/mock.js.map +1 -1
  51. package/lib/commonjs/web/runtime.js +5 -2
  52. package/lib/commonjs/web/runtime.js.map +1 -1
  53. package/lib/commonjs/web/shadowRegistry.js +53 -73
  54. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  55. package/lib/commonjs/web/utils/common.js +1 -24
  56. package/lib/commonjs/web/utils/common.js.map +1 -1
  57. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  58. package/lib/commonjs/web/variants/getVariants.js +1 -1
  59. package/lib/module/core/createUnistylesComponent.js +28 -21
  60. package/lib/module/core/createUnistylesComponent.js.map +1 -1
  61. package/lib/module/core/createUnistylesComponent.native.js +15 -18
  62. package/lib/module/core/createUnistylesComponent.native.js.map +1 -1
  63. package/lib/module/specs/NavigtionBar/index.js +0 -10
  64. package/lib/module/specs/NavigtionBar/index.js.map +1 -1
  65. package/lib/module/specs/ShadowRegistry/index.js +5 -7
  66. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  67. package/lib/module/specs/StatusBar/index.js +1 -6
  68. package/lib/module/specs/StatusBar/index.js.map +1 -1
  69. package/lib/module/specs/UnistylesRuntime/index.js +0 -2
  70. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  71. package/lib/module/utils.js +21 -0
  72. package/lib/module/utils.js.map +1 -0
  73. package/lib/module/web/convert/index.js +1 -1
  74. package/lib/module/web/convert/index.js.map +1 -1
  75. package/lib/module/web/convert/object/boxShadow.js +2 -1
  76. package/lib/module/web/convert/object/boxShadow.js.map +1 -1
  77. package/lib/module/web/convert/object/objectStyle.js +2 -1
  78. package/lib/module/web/convert/object/objectStyle.js.map +1 -1
  79. package/lib/module/web/convert/shadow/boxShadow.js +1 -1
  80. package/lib/module/web/convert/shadow/boxShadow.js.map +1 -1
  81. package/lib/module/web/convert/shadow/textShadow.js +1 -1
  82. package/lib/module/web/convert/shadow/textShadow.js.map +1 -1
  83. package/lib/module/web/create.js +2 -1
  84. package/lib/module/web/create.js.map +1 -1
  85. package/lib/module/web/index.js +1 -1
  86. package/lib/module/web/index.js.map +1 -1
  87. package/lib/module/web/listener.js +18 -2
  88. package/lib/module/web/listener.js.map +1 -1
  89. package/lib/module/web/mock.js +1 -2
  90. package/lib/module/web/mock.js.map +1 -1
  91. package/lib/module/web/runtime.js +6 -3
  92. package/lib/module/web/runtime.js.map +1 -1
  93. package/lib/module/web/shadowRegistry.js +51 -71
  94. package/lib/module/web/shadowRegistry.js.map +1 -1
  95. package/lib/module/web/utils/common.js +0 -22
  96. package/lib/module/web/utils/common.js.map +1 -1
  97. package/lib/module/web/utils/unistyle.js.map +1 -1
  98. package/lib/module/web/variants/getVariants.js +1 -1
  99. package/lib/module/web/variants/getVariants.js.map +1 -1
  100. package/lib/typescript/src/core/createUnistylesComponent.d.ts +1 -1
  101. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
  102. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +1 -1
  103. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -1
  104. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -4
  105. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  106. package/lib/typescript/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.d.ts +0 -1
  107. package/lib/typescript/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.d.ts.map +1 -1
  108. package/lib/typescript/src/specs/NavigtionBar/index.d.ts +1 -15
  109. package/lib/typescript/src/specs/NavigtionBar/index.d.ts.map +1 -1
  110. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
  111. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  112. package/lib/typescript/src/specs/StatusBar/UnistylesStatusBar.nitro.d.ts +0 -1
  113. package/lib/typescript/src/specs/StatusBar/UnistylesStatusBar.nitro.d.ts.map +1 -1
  114. package/lib/typescript/src/specs/StatusBar/index.d.ts +2 -9
  115. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  116. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  117. package/lib/typescript/src/utils.d.ts +2 -0
  118. package/lib/typescript/src/utils.d.ts.map +1 -0
  119. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  120. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  121. package/lib/typescript/src/web/create.d.ts.map +1 -1
  122. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  123. package/lib/typescript/src/web/mock.d.ts.map +1 -1
  124. package/lib/typescript/src/web/runtime.d.ts +1 -1
  125. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  126. package/lib/typescript/src/web/shadowRegistry.d.ts +1 -3
  127. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  128. package/lib/typescript/src/web/utils/common.d.ts +0 -4
  129. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  130. package/lib/typescript/src/web/utils/unistyle.d.ts +1 -1
  131. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  132. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +57 -0
  133. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +69 -0
  134. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +8 -16
  135. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +2 -4
  136. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/{Func_void_std__vector_UnistyleDependency_.kt → Func_void_UnistylesNativeMiniRuntime.kt} +5 -5
  137. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/{Func_void.kt → Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt} +5 -5
  138. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +4 -12
  139. package/nitrogen/generated/android/unistylesOnLoad.cpp +4 -4
  140. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +43 -30
  141. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +2 -8
  142. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +2 -4
  143. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +10 -32
  144. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +0 -2
  145. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +2 -4
  146. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +0 -1
  147. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +0 -1
  148. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +0 -1
  149. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +0 -1
  150. package/package.json +4 -2
  151. package/plugin/common.js +12 -1
  152. package/plugin/index.js +12 -10
  153. package/plugin/ref.js +80 -15
  154. package/plugin/style.js +113 -18
  155. package/src/core/createUnistylesComponent.native.tsx +15 -22
  156. package/src/core/createUnistylesComponent.tsx +29 -23
  157. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -4
  158. package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.ts +0 -1
  159. package/src/specs/NavigtionBar/index.ts +1 -30
  160. package/src/specs/ShadowRegistry/index.ts +8 -11
  161. package/src/specs/StatusBar/UnistylesStatusBar.nitro.ts +0 -1
  162. package/src/specs/StatusBar/index.ts +2 -17
  163. package/src/specs/UnistylesRuntime/index.ts +1 -2
  164. package/src/utils.ts +22 -0
  165. package/src/web/convert/index.ts +1 -1
  166. package/src/web/convert/object/boxShadow.ts +2 -1
  167. package/src/web/convert/object/objectStyle.ts +2 -1
  168. package/src/web/convert/shadow/boxShadow.ts +1 -1
  169. package/src/web/convert/shadow/textShadow.ts +1 -1
  170. package/src/web/create.ts +2 -1
  171. package/src/web/index.ts +1 -1
  172. package/src/web/listener.ts +22 -2
  173. package/src/web/mock.ts +1 -2
  174. package/src/web/runtime.ts +7 -3
  175. package/src/web/shadowRegistry.ts +55 -70
  176. package/src/web/utils/common.ts +0 -26
  177. package/src/web/utils/unistyle.ts +1 -1
  178. package/src/web/variants/getVariants.ts +1 -1
  179. package/nitrogen/generated/android/c++/JFunc_void.hpp +0 -48
  180. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency_.hpp +0 -60
@@ -219,17 +219,6 @@ public class HybridNativePlatformSpecCxx {
219
219
  }
220
220
  }
221
221
 
222
- @inline(__always)
223
- public func setNavigationBarBackgroundColor(color: Double) -> Void {
224
- do {
225
- try self.__implementation.setNavigationBarBackgroundColor(color: color)
226
- return
227
- } catch {
228
- let __message = "\(error.localizedDescription)"
229
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
230
- }
231
- }
232
-
233
222
  @inline(__always)
234
223
  public func setNavigationBarHidden(isHidden: Bool) -> Void {
235
224
  do {
@@ -252,17 +241,6 @@ public class HybridNativePlatformSpecCxx {
252
241
  }
253
242
  }
254
243
 
255
- @inline(__always)
256
- public func setStatusBarBackgroundColor(color: Double) -> Void {
257
- do {
258
- try self.__implementation.setStatusBarBackgroundColor(color: color)
259
- return
260
- } catch {
261
- let __message = "\(error.localizedDescription)"
262
- fatalError("Swift errors can currently not be propagated to C++! See https://github.com/swiftlang/swift/issues/75290 (Error: \(__message))")
263
- }
264
- }
265
-
266
244
  @inline(__always)
267
245
  public func setImmersiveMode(isEnabled: Bool) -> Void {
268
246
  do {
@@ -286,18 +264,18 @@ public class HybridNativePlatformSpecCxx {
286
264
  }
287
265
 
288
266
  @inline(__always)
289
- public func registerPlatformListener(callback: bridge.Func_void_std__vector_UnistyleDependency_) -> Void {
267
+ public func registerPlatformListener(callback: bridge.Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime) -> Void {
290
268
  do {
291
- try self.__implementation.registerPlatformListener(callback: { () -> (([UnistyleDependency]) -> Void) in
292
- let __sharedClosure = bridge.share_Func_void_std__vector_UnistyleDependency_(callback)
293
- return { (__dependencies: [UnistyleDependency]) -> Void in
269
+ try self.__implementation.registerPlatformListener(callback: { () -> (([UnistyleDependency], UnistylesNativeMiniRuntime) -> Void) in
270
+ let __sharedClosure = bridge.share_Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime(callback)
271
+ return { (__dependencies: [UnistyleDependency], __miniRuntime: UnistylesNativeMiniRuntime) -> Void in
294
272
  __sharedClosure.pointee.call({ () -> bridge.std__vector_UnistyleDependency_ in
295
273
  var __vector = bridge.create_std__vector_UnistyleDependency_(__dependencies.count)
296
274
  for __item in __dependencies {
297
275
  __vector.push_back(__item)
298
276
  }
299
277
  return __vector
300
- }())
278
+ }(), __miniRuntime)
301
279
  }
302
280
  }())
303
281
  return
@@ -308,12 +286,12 @@ public class HybridNativePlatformSpecCxx {
308
286
  }
309
287
 
310
288
  @inline(__always)
311
- public func registerImeListener(callback: bridge.Func_void) -> Void {
289
+ public func registerImeListener(callback: bridge.Func_void_UnistylesNativeMiniRuntime) -> Void {
312
290
  do {
313
- try self.__implementation.registerImeListener(callback: { () -> (() -> Void) in
314
- let __sharedClosure = bridge.share_Func_void(callback)
315
- return { () -> Void in
316
- __sharedClosure.pointee.call()
291
+ try self.__implementation.registerImeListener(callback: { () -> ((UnistylesNativeMiniRuntime) -> Void) in
292
+ let __sharedClosure = bridge.share_Func_void_UnistylesNativeMiniRuntime(callback)
293
+ return { (__miniRuntime: UnistylesNativeMiniRuntime) -> Void in
294
+ __sharedClosure.pointee.call(__miniRuntime)
317
295
  }
318
296
  }())
319
297
  return
@@ -25,10 +25,8 @@ namespace margelo::nitro::unistyles {
25
25
  prototype.registerHybridMethod("getNavigationBarDimensions", &HybridNativePlatformSpec::getNavigationBarDimensions);
26
26
  prototype.registerHybridMethod("getPrefersRtlDirection", &HybridNativePlatformSpec::getPrefersRtlDirection);
27
27
  prototype.registerHybridMethod("setRootViewBackgroundColor", &HybridNativePlatformSpec::setRootViewBackgroundColor);
28
- prototype.registerHybridMethod("setNavigationBarBackgroundColor", &HybridNativePlatformSpec::setNavigationBarBackgroundColor);
29
28
  prototype.registerHybridMethod("setNavigationBarHidden", &HybridNativePlatformSpec::setNavigationBarHidden);
30
29
  prototype.registerHybridMethod("setStatusBarHidden", &HybridNativePlatformSpec::setStatusBarHidden);
31
- prototype.registerHybridMethod("setStatusBarBackgroundColor", &HybridNativePlatformSpec::setStatusBarBackgroundColor);
32
30
  prototype.registerHybridMethod("setImmersiveMode", &HybridNativePlatformSpec::setImmersiveMode);
33
31
  prototype.registerHybridMethod("getMiniRuntime", &HybridNativePlatformSpec::getMiniRuntime);
34
32
  prototype.registerHybridMethod("registerPlatformListener", &HybridNativePlatformSpec::registerPlatformListener);
@@ -78,14 +78,12 @@ namespace margelo::nitro::unistyles {
78
78
  virtual Dimensions getNavigationBarDimensions() = 0;
79
79
  virtual bool getPrefersRtlDirection() = 0;
80
80
  virtual void setRootViewBackgroundColor(double color) = 0;
81
- virtual void setNavigationBarBackgroundColor(double color) = 0;
82
81
  virtual void setNavigationBarHidden(bool isHidden) = 0;
83
82
  virtual void setStatusBarHidden(bool isHidden) = 0;
84
- virtual void setStatusBarBackgroundColor(double color) = 0;
85
83
  virtual void setImmersiveMode(bool isEnabled) = 0;
86
84
  virtual UnistylesNativeMiniRuntime getMiniRuntime() = 0;
87
- virtual void registerPlatformListener(const std::function<void(const std::vector<UnistyleDependency>& /* dependencies */)>& callback) = 0;
88
- virtual void registerImeListener(const std::function<void()>& callback) = 0;
85
+ virtual void registerPlatformListener(const std::function<void(const std::vector<UnistyleDependency>& /* dependencies */, const UnistylesNativeMiniRuntime& /* miniRuntime */)>& callback) = 0;
86
+ virtual void registerImeListener(const std::function<void(const UnistylesNativeMiniRuntime& /* miniRuntime */)>& callback) = 0;
89
87
  virtual void unregisterPlatformListeners() = 0;
90
88
 
91
89
  protected:
@@ -16,7 +16,6 @@ namespace margelo::nitro::unistyles {
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
17
  prototype.registerHybridGetter("width", &HybridUnistylesNavigationBarSpec::getWidth);
18
18
  prototype.registerHybridGetter("height", &HybridUnistylesNavigationBarSpec::getHeight);
19
- prototype.registerHybridMethod("setBackgroundColor", &HybridUnistylesNavigationBarSpec::setBackgroundColor);
20
19
  prototype.registerHybridMethod("setHidden", &HybridUnistylesNavigationBarSpec::setHidden);
21
20
  });
22
21
  }
@@ -49,7 +49,6 @@ namespace margelo::nitro::unistyles {
49
49
 
50
50
  public:
51
51
  // Methods
52
- virtual void setBackgroundColor(double color) = 0;
53
52
  virtual void setHidden(bool isHidden) = 0;
54
53
 
55
54
  protected:
@@ -16,7 +16,6 @@ namespace margelo::nitro::unistyles {
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
17
  prototype.registerHybridGetter("width", &HybridUnistylesStatusBarSpec::getWidth);
18
18
  prototype.registerHybridGetter("height", &HybridUnistylesStatusBarSpec::getHeight);
19
- prototype.registerHybridMethod("setBackgroundColor", &HybridUnistylesStatusBarSpec::setBackgroundColor);
20
19
  prototype.registerHybridMethod("setHidden", &HybridUnistylesStatusBarSpec::setHidden);
21
20
  });
22
21
  }
@@ -49,7 +49,6 @@ namespace margelo::nitro::unistyles {
49
49
 
50
50
  public:
51
51
  // Methods
52
- virtual void setBackgroundColor(double color) = 0;
53
52
  virtual void setHidden(bool isHidden) = 0;
54
53
 
55
54
  protected:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-alpha.38",
3
+ "version": "3.0.0-alpha.39",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -86,7 +86,9 @@
86
86
  "peerDependencies": {
87
87
  "@react-native/normalize-colors": "*",
88
88
  "react": "*",
89
- "react-native": "*"
89
+ "react-native": ">=0.76.0",
90
+ "react-native-edge-to-edge": "*",
91
+ "react-native-nitro-modules": "*"
90
92
  },
91
93
  "workspaces": [
92
94
  "example",
package/plugin/common.js CHANGED
@@ -61,10 +61,18 @@ function getIdentifierNameFromExpression(t, memberExpression) {
61
61
  .flatMap(property => getIdentifierNameFromExpression(t, property.value))
62
62
  }
63
63
 
64
+ if (t.isUnaryExpression(memberExpression)) {
65
+ return getIdentifierNameFromExpression(t, memberExpression.argument.object)
66
+ }
67
+
64
68
  return []
65
69
  }
66
70
 
67
71
  function getSecondPropertyName(t, memberExpression) {
72
+ if (t.isUnaryExpression(memberExpression)) {
73
+ return getSecondPropertyName(t, memberExpression.argument.object)
74
+ }
75
+
68
76
  if (t.isConditionalExpression(memberExpression)) {
69
77
  return [
70
78
  getSecondPropertyName(t, memberExpression.test.left),
@@ -130,7 +138,10 @@ function getSecondPropertyName(t, memberExpression) {
130
138
  return []
131
139
  }
132
140
 
141
+ const PRESSABLE_STATE_NAME = '__uni_pressable_state'
142
+
133
143
  module.exports = {
134
144
  getIdentifierNameFromExpression,
135
- getSecondPropertyName
145
+ getSecondPropertyName,
146
+ PRESSABLE_STATE_NAME
136
147
  }
package/plugin/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const addShadowRegistryImport = require('./import')
2
- const { getStyleMetadata, getStyleAttribute, styleAttributeToArray } = require('./style')
2
+ const { getStyleMetadata, getStyleAttribute, styleAttributeToArray, handlePressable } = require('./style')
3
3
  const { getRefProp, addRef, overrideRef, hasStringRef } = require('./ref')
4
4
  const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyle } = require('./stylesheet')
5
5
  const { isUsingVariants, extractVariants } = require('./variants')
@@ -128,22 +128,24 @@ module.exports = function ({ types: t }) {
128
128
  return
129
129
  }
130
130
 
131
+ if (openingElementName === 'Pressable') {
132
+ handlePressable(t, path, styleAttr, metadata)
133
+ }
134
+
131
135
  styleAttributeToArray(t, path)
132
136
 
133
137
  // to add import
134
138
  state.file.hasAnyUnistyle = true
135
139
 
136
- metadata.forEach(meta => {
137
- const refProp = getRefProp(t, path)
140
+ const refProp = getRefProp(t, path)
138
141
 
139
- if (!refProp && hasStringRef(t, path)) {
140
- throw new Error("Detected string based ref which is not supported by Unistyles.")
141
- }
142
+ if (!refProp && hasStringRef(t, path)) {
143
+ throw new Error("Detected string based ref which is not supported by Unistyles.")
144
+ }
142
145
 
143
- refProp
144
- ? overrideRef(t, path, refProp, meta, state)
145
- : addRef(t, path, meta, state)
146
- })
146
+ refProp
147
+ ? overrideRef(t, path, refProp, metadata, state)
148
+ : addRef(t, path, metadata, state)
147
149
  },
148
150
  CallExpression(path, state) {
149
151
  if (isUsingVariants(t, path)) {
package/plugin/ref.js CHANGED
@@ -1,3 +1,5 @@
1
+ const { PRESSABLE_STATE_NAME } = require('./common')
2
+
1
3
  function getRefProp(t, path) {
2
4
  return path.node.openingElement.attributes.find(attr =>
3
5
  t.isJSXAttribute(attr) &&
@@ -14,17 +16,80 @@ function hasStringRef(t, path) {
14
16
  )
15
17
  }
16
18
 
17
- function memberExpressionFromArray(t, identifiers) {
18
- // possible for inline styles
19
- if (identifiers.length === 0) {
20
- return undefined
21
- }
19
+ function arrayExpressionFromMetadata(t, metadata) {
20
+ const memberExpressions = metadata
21
+ .map(meta => {
22
+ // possible for inline styles
23
+ if (meta.members.length === 0) {
24
+ return meta.inlineStyle || meta.conditionalExpression
25
+ }
22
26
 
23
- const [base, ...members] = identifiers
27
+ const [base, ...members] = meta.members
24
28
 
25
- return members.reduce((object, property) => t.memberExpression(object, t.identifier(property)), t.identifier(base))
29
+ return members.reduce((object, property) => t.memberExpression(object, t.identifier(property)), t.identifier(base))
30
+ })
31
+
32
+ return t.arrayExpression(memberExpressions)
26
33
  }
27
34
 
35
+ function arrayFromDynamicFunctionArgs(t, metadata, path) {
36
+ const hasPressableDynamicFunction = path.node.openingElement.attributes
37
+ .find(attr => t.isJSXIdentifier(attr.name) && attr.name.name === "style" && t.isArrowFunctionExpression(attr.value.expression))
38
+
39
+ const memberExpressions = metadata
40
+ .map(meta => {
41
+ if (meta.dynamicFunction && meta.dynamicFunction.arguments) {
42
+ const args = meta.dynamicFunction.arguments.map(arg => {
43
+ // special case for pressable
44
+ if (t.isIdentifier(arg) && arg.name === PRESSABLE_STATE_NAME) {
45
+ // replace with { pressed: false }
46
+ return t.objectExpression([
47
+ t.objectProperty(
48
+ t.identifier("pressed"),
49
+ t.booleanLiteral(false)
50
+ )
51
+ ])
52
+ }
53
+
54
+ if (t.isMemberExpression(arg) && arg.object.name === PRESSABLE_STATE_NAME) {
55
+ return t.identifier('false')
56
+ }
57
+
58
+ return arg
59
+ })
60
+
61
+ return t.arrayExpression(args)
62
+ }
63
+
64
+ // typeof styles.pressable === "function" ? { pressed: false } : []
65
+ if (hasPressableDynamicFunction) {
66
+ return t.arrayExpression([
67
+ t.conditionalExpression(
68
+ t.binaryExpression(
69
+ "===",
70
+ t.unaryExpression(
71
+ "typeof",
72
+ t.identifier("styles.pressable")
73
+ ),
74
+ t.stringLiteral("function")
75
+ ),
76
+ t.objectExpression([
77
+ t.objectProperty(
78
+ t.identifier("pressed"),
79
+ t.booleanLiteral(false)
80
+ )
81
+ ]),
82
+ t.arrayExpression([])
83
+ )
84
+ ])
85
+ }
86
+
87
+ return t.arrayExpression([])
88
+ })
89
+ .filter(Boolean)
90
+
91
+ return t.arrayExpression(memberExpressions)
92
+ }
28
93
  function addRef(t, path, metadata, state) {
29
94
  const hasVariants = state.file.hasVariants
30
95
 
@@ -36,9 +101,9 @@ function addRef(t, path, metadata, state) {
36
101
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
37
102
  [
38
103
  t.identifier('ref'),
39
- memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle || metadata.conditionalExpression,
104
+ arrayExpressionFromMetadata(t, metadata),
40
105
  t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
41
- metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
106
+ arrayFromDynamicFunctionArgs(t, metadata, path)
42
107
  ]
43
108
  )
44
109
  ),
@@ -85,9 +150,9 @@ function overrideRef(t, path, refProp, metadata, state) {
85
150
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
86
151
  [
87
152
  t.identifier(uniqueRefName),
88
- memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle || metadata.conditionalExpression,
153
+ arrayExpressionFromMetadata(t, metadata),
89
154
  t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
90
- metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
155
+ arrayFromDynamicFunctionArgs(t, metadata, path)
91
156
  ]
92
157
  )
93
158
  ),
@@ -130,9 +195,9 @@ function overrideRef(t, path, refProp, metadata, state) {
130
195
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
131
196
  [
132
197
  t.identifier(userRefName),
133
- memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle || metadata.conditionalExpression,
198
+ arrayExpressionFromMetadata(t, metadata),
134
199
  t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
135
- metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
200
+ arrayFromDynamicFunctionArgs(t, metadata, path)
136
201
  ]
137
202
  )
138
203
  ),
@@ -192,9 +257,9 @@ function overrideRef(t, path, refProp, metadata, state) {
192
257
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
193
258
  [
194
259
  t.identifier(uniqueRefName),
195
- memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle || metadata.conditionalExpression,
260
+ arrayExpressionFromMetadata(t, metadata),
196
261
  t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
197
- metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
262
+ arrayFromDynamicFunctionArgs(t, metadata, path)
198
263
  ]
199
264
  )
200
265
  ),
package/plugin/style.js CHANGED
@@ -1,3 +1,5 @@
1
+ const { PRESSABLE_STATE_NAME } = require('./common')
2
+
1
3
  function getStyleMetadata(t, node, dynamicFunction = null) {
2
4
  // {styles.container}
3
5
  if (t.isMemberExpression(node)) {
@@ -27,32 +29,22 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
27
29
 
28
30
  // {{ ...styles.container }}
29
31
  if (t.isObjectExpression(node)) {
30
- const inlineStyles = []
31
-
32
- const partialResult = node
32
+ return node
33
33
  .properties
34
34
  .flatMap(prop => {
35
35
  // handle inline styles
36
36
  if (t.isObjectProperty(prop)) {
37
- inlineStyles.push(prop)
38
-
39
- return null
37
+ return [{
38
+ members: [],
39
+ inlineStyle: t.objectExpression([prop]),
40
+ dynamicFunction: undefined,
41
+ conditionalExpression: undefined
42
+ }]
40
43
  }
41
44
 
42
45
  return getStyleMetadata(t, prop.argument)
43
46
  })
44
47
  .filter(Boolean)
45
-
46
- if (inlineStyles.length > 0) {
47
- return partialResult.concat([{
48
- members: [],
49
- inlineStyle: t.objectExpression(inlineStyles),
50
- dynamicFunction: undefined,
51
- conditionalExpression: undefined
52
- }])
53
- }
54
-
55
- return partialResult
56
48
  }
57
49
 
58
50
  // {styles.container(arg1, arg2)}
@@ -78,6 +70,11 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
78
70
  }]
79
71
  }
80
72
 
73
+ // pressable
74
+ if (t.isArrowFunctionExpression(node)) {
75
+ return getStyleMetadata(t, node.body, node)
76
+ }
77
+
81
78
  return []
82
79
  }
83
80
 
@@ -92,6 +89,12 @@ function getStyleAttribute(t, path) {
92
89
  function styleAttributeToArray(t, path) {
93
90
  const styleAttribute = getStyleAttribute(t, path)
94
91
 
92
+ // special case for pressable
93
+ // {state => styles.pressable(state)}
94
+ if (t.isArrowFunctionExpression(styleAttribute.value.expression)) {
95
+ return
96
+ }
97
+
95
98
  // {{...style.container, ...style.container}}
96
99
  if (t.isObjectExpression(styleAttribute.value.expression)) {
97
100
  const properties = styleAttribute.value.expression.properties
@@ -123,8 +126,100 @@ function styleAttributeToArray(t, path) {
123
126
  styleAttribute.value.expression = t.arrayExpression([styleAttribute.value.expression])
124
127
  }
125
128
 
129
+ function handlePressable(t, path, styleAttr, metadata) {
130
+ const styleExpression = styleAttr.value.expression
131
+
132
+ // {style.pressable}
133
+ // the worst case, we don't know if user rely on state
134
+ if (t.isMemberExpression(styleExpression)) {
135
+ const members = metadata.at(0).members
136
+
137
+ if (members.length === 0) {
138
+ return
139
+ }
140
+
141
+ const stylePath = members.slice(1).reduce(
142
+ (acc, property) => t.memberExpression(acc, t.identifier(property)),
143
+ t.identifier(members[0])
144
+ )
145
+
146
+ // state => typeof style.pressable === 'function' ? style.pressable(state) : style.pressable
147
+ styleAttr.value.expression = t.arrowFunctionExpression(
148
+ [t.identifier("state")],
149
+ t.conditionalExpression(
150
+ t.binaryExpression(
151
+ "===",
152
+ t.unaryExpression(
153
+ "typeof",
154
+ stylePath
155
+ ),
156
+ t.stringLiteral("function")
157
+ ),
158
+ t.callExpression(
159
+ stylePath,
160
+ [t.identifier("state")]
161
+ ),
162
+ stylePath
163
+ )
164
+ )
165
+
166
+ return
167
+ }
168
+
169
+ // {style.pressable(1, 2)}
170
+ if (t.isCallExpression(styleExpression)) {
171
+ // user already called dynamic function
172
+ // there is no work to do
173
+ return
174
+ }
175
+
176
+ // {() => style.pressable(1, 2)}
177
+ if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 0) {
178
+ // user doesn't care about the state
179
+ // we can safely unwrap the function
180
+ styleAttr.value.expression = styleExpression.body
181
+
182
+ return
183
+ }
184
+
185
+ // {state => style.pressable(state, 1, 2)}
186
+ if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length > 0) {
187
+ // already a function, we need to set state to false
188
+ // and pass it to C++ as in background it will never be true
189
+ const args = metadata.at(0).dynamicFunction
190
+
191
+ if (!t.isCallExpression(args) || args.arguments.length === 0) {
192
+ return
193
+ }
194
+
195
+ // get state local name
196
+ const stateIdentifier = styleExpression.params[0]
197
+
198
+ if (!stateIdentifier || !t.isIdentifier(stateIdentifier)) {
199
+ return
200
+ }
201
+
202
+ // replace state name with matching identifier
203
+ args.arguments.map(arg => {
204
+ if (t.isIdentifier(arg) && arg.name === stateIdentifier.name) {
205
+ arg.name = PRESSABLE_STATE_NAME
206
+ }
207
+
208
+ if (t.isMemberExpression(arg) && arg.object.name === stateIdentifier.name) {
209
+ arg.object.name = PRESSABLE_STATE_NAME
210
+ }
211
+
212
+ return arg
213
+ })
214
+
215
+ // update arrow function arg name
216
+ styleExpression.params[0].name = PRESSABLE_STATE_NAME
217
+ }
218
+ }
219
+
126
220
  module.exports = {
127
221
  getStyleMetadata,
128
222
  getStyleAttribute,
129
- styleAttributeToArray
223
+ styleAttributeToArray,
224
+ handlePressable
130
225
  }
@@ -1,13 +1,15 @@
1
- import React, { type ComponentType, useEffect, useRef, useState } from 'react'
1
+ import React, { type ComponentType, forwardRef, useEffect, useRef, useState } from 'react'
2
2
  import type { UnistylesTheme } from '../types'
3
3
  import { StyleSheet, UnistyleDependency, UnistylesRuntime, type UnistylesStyleSheet } from '../specs'
4
4
  import type { PartialBy } from '../types/common'
5
+ import { deepMergeObjects } from '../utils'
5
6
 
6
7
  const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'] as const
7
8
  type SupportedStyleProps = typeof SUPPORTED_STYLE_PROPS[number]
8
9
 
9
- export const createUnistylesComponent =<TProps extends Record<string, any>, TMappings extends Partial<Omit<TProps, SupportedStyleProps>>>(Component: ComponentType<TProps>, mappings?: (theme: UnistylesTheme) => TMappings) => {
10
- return (props: PartialBy<TProps, keyof TMappings | SupportedStyleProps>) => {
10
+ export const createUnistylesComponent = <TProps extends Record<string, any>, TMappings extends Partial<Omit<TProps, SupportedStyleProps>>>(Component: ComponentType<TProps>, mappings?: (theme: UnistylesTheme) => TMappings) => {
11
+ return forwardRef<unknown, PartialBy<TProps, keyof TMappings | SupportedStyleProps>>((props, ref) => {
12
+ const narrowedProps = props as PartialBy<TProps, keyof TMappings | SupportedStyleProps>
11
13
  const [theme, setTheme] = useState<UnistylesTheme>(UnistylesRuntime.getTheme())
12
14
  const [, setRt] = useState(0)
13
15
  const stylesRef = useRef<Record<string, any>>({})
@@ -15,8 +17,8 @@ export const createUnistylesComponent =<TProps extends Record<string, any>, TMap
15
17
 
16
18
  if (!isForcedRef.current) {
17
19
  SUPPORTED_STYLE_PROPS.forEach(propName => {
18
- if (props?.[propName]) {
19
- if (Array.isArray(props[propName])) {
20
+ if (narrowedProps?.[propName]) {
21
+ if (Array.isArray(narrowedProps[propName])) {
20
22
  console.error(`🦄 Unistyles: createUnistylesComponent requires ${propName} to be an object. Please check props for component: ${Component.displayName}`)
21
23
  }
22
24
 
@@ -27,7 +29,7 @@ export const createUnistylesComponent =<TProps extends Record<string, any>, TMap
27
29
 
28
30
  stylesRef.current = {
29
31
  ...stylesRef.current,
30
- [propName]: props[propName]
32
+ [propName]: narrowedProps[propName]
31
33
  }
32
34
  }
33
35
  })
@@ -35,14 +37,14 @@ export const createUnistylesComponent =<TProps extends Record<string, any>, TMap
35
37
 
36
38
  useEffect(() => {
37
39
  const removeChangeListener = (StyleSheet as UnistylesStyleSheet).addChangeListener(dependencies => {
38
- const componentDependencies = (props.style?.__proto__.uni__dependencies || mappings?.(theme).style?.__proto__.uni__dependencies) as Array<UnistyleDependency>
40
+ const componentDependencies = (narrowedProps.style?.__proto__.uni__dependencies || mappings?.(theme).style?.__proto__.uni__dependencies) as Array<UnistyleDependency>
39
41
 
40
42
  if (dependencies.includes(UnistyleDependency.Theme) && (!componentDependencies ||componentDependencies.includes(UnistyleDependency.Theme))) {
41
43
  setTheme(UnistylesRuntime.getTheme())
42
44
 
43
45
  // override with Unistyles styles
44
46
  SUPPORTED_STYLE_PROPS.forEach(propName => {
45
- if (props?.[propName]) {
47
+ if (narrowedProps?.[propName]) {
46
48
  stylesRef.current = {
47
49
  ...stylesRef.current,
48
50
  // @ts-expect-error - this is hidden from TS
@@ -65,26 +67,17 @@ export const createUnistylesComponent =<TProps extends Record<string, any>, TMap
65
67
  }, [])
66
68
 
67
69
  const mergedProps = mappings?.(theme) as Record<string, any> ?? {}
68
-
69
- Object.keys(props).forEach(key => {
70
- if (key in mergedProps) {
71
- mergedProps[key] = Object.assign(props[key as keyof typeof props], mergedProps[key])
72
-
73
- return
74
- }
75
-
76
- mergedProps[key] = props[key as keyof typeof props]
77
- })
70
+ const finalProps = deepMergeObjects(mergedProps, props)
78
71
 
79
72
  // override with Unistyles styles
80
73
  SUPPORTED_STYLE_PROPS.forEach(propName => {
81
- if (mergedProps[propName]) {
82
- mergedProps[propName] = stylesRef.current[propName]
74
+ if (finalProps[propName]) {
75
+ finalProps[propName] = stylesRef.current[propName]
83
76
  }
84
77
  })
85
78
 
86
79
  isForcedRef.current = false
87
80
 
88
- return <Component {...mergedProps as TProps} />
89
- }
81
+ return <Component {...finalProps as TProps} ref={ref} />
82
+ })
90
83
  }