react-native-unistyles 3.0.0-nightly-20250221 → 3.0.0-nightly-20250318

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 (132) hide show
  1. package/README.md +16 -3
  2. package/android/CMakeLists.txt +2 -1
  3. package/cxx/core/StyleSheet.h +1 -1
  4. package/cxx/core/UnistyleWrapper.h +1 -1
  5. package/cxx/core/UnistylesMountHook.cpp +2 -2
  6. package/cxx/core/UnistylesMountHook.h +1 -4
  7. package/cxx/hybridObjects/HybridStyleSheet.cpp +1 -1
  8. package/cxx/hybridObjects/HybridStyleSheet.h +1 -1
  9. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +2 -2
  10. package/cxx/parser/Parser.cpp +26 -4
  11. package/cxx/parser/Parser.h +1 -1
  12. package/lib/commonjs/core/createUnistylesElement.native.js +4 -0
  13. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  14. package/lib/commonjs/core/createUnistylesImageBackground.js +4 -0
  15. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  16. package/lib/commonjs/core/getClassname.js +2 -2
  17. package/lib/commonjs/core/getClassname.js.map +1 -1
  18. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +12 -0
  19. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  20. package/lib/commonjs/core/withUnistyles/withUnistyles.js +13 -5
  21. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  22. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +14 -7
  23. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  24. package/lib/commonjs/web/registry.js +4 -3
  25. package/lib/commonjs/web/registry.js.map +1 -1
  26. package/lib/commonjs/web/runtime.js +5 -1
  27. package/lib/commonjs/web/runtime.js.map +1 -1
  28. package/lib/commonjs/web/shadowRegistry.js +4 -3
  29. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  30. package/lib/commonjs/web/state.js +8 -2
  31. package/lib/commonjs/web/state.js.map +1 -1
  32. package/lib/commonjs/web/utils/unistyle.js +1 -3
  33. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  34. package/lib/module/core/createUnistylesElement.native.js +4 -0
  35. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  36. package/lib/module/core/createUnistylesImageBackground.js +4 -0
  37. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  38. package/lib/module/core/getClassname.js +2 -2
  39. package/lib/module/core/getClassname.js.map +1 -1
  40. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +12 -0
  41. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  42. package/lib/module/core/withUnistyles/withUnistyles.js +13 -5
  43. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  44. package/lib/module/core/withUnistyles/withUnistyles.native.js +14 -7
  45. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  46. package/lib/module/web/registry.js +4 -3
  47. package/lib/module/web/registry.js.map +1 -1
  48. package/lib/module/web/runtime.js +5 -1
  49. package/lib/module/web/runtime.js.map +1 -1
  50. package/lib/module/web/shadowRegistry.js +4 -3
  51. package/lib/module/web/shadowRegistry.js.map +1 -1
  52. package/lib/module/web/state.js +8 -2
  53. package/lib/module/web/state.js.map +1 -1
  54. package/lib/module/web/utils/unistyle.js +0 -1
  55. package/lib/module/web/utils/unistyle.js.map +1 -1
  56. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  57. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  58. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  59. package/lib/typescript/src/core/getClassname.d.ts +1 -1
  60. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  61. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  62. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  63. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  64. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  65. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  66. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +1 -1
  67. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  68. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +1 -3
  69. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  70. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  71. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  72. package/lib/typescript/src/mq.d.ts.map +1 -1
  73. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  74. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  75. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  76. package/lib/typescript/src/types/common.d.ts +0 -1
  77. package/lib/typescript/src/types/common.d.ts.map +1 -1
  78. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  79. package/lib/typescript/src/utils.d.ts.map +1 -1
  80. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  81. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  82. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  83. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  84. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  85. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  86. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  87. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  88. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  89. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  90. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  91. package/lib/typescript/src/web/create.d.ts.map +1 -1
  92. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  93. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  94. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  95. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  96. package/lib/typescript/src/web/registry.d.ts +1 -1
  97. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  98. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  99. package/lib/typescript/src/web/shadowRegistry.d.ts +1 -1
  100. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  101. package/lib/typescript/src/web/state.d.ts.map +1 -1
  102. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  103. package/lib/typescript/src/web/utils/unistyle.d.ts +0 -1
  104. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  105. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  106. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
  107. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
  108. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +19 -19
  109. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +7 -2
  110. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +7 -2
  111. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +22 -22
  112. package/nitrogen/generated/android/unistyles+autolinking.cmake +16 -0
  113. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -1
  114. package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -0
  115. package/nitrogen/generated/shared/c++/Insets.hpp +1 -0
  116. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -0
  117. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -0
  118. package/package.json +3 -3
  119. package/plugin/index.js +6 -0
  120. package/src/core/createUnistylesElement.native.tsx +5 -0
  121. package/src/core/createUnistylesImageBackground.tsx +5 -0
  122. package/src/core/getClassname.ts +3 -2
  123. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +16 -0
  124. package/src/core/withUnistyles/withUnistyles.native.tsx +42 -17
  125. package/src/core/withUnistyles/withUnistyles.tsx +17 -6
  126. package/src/types/common.ts +0 -1
  127. package/src/web/registry.ts +6 -3
  128. package/src/web/runtime.ts +6 -2
  129. package/src/web/shadowRegistry.ts +7 -3
  130. package/src/web/state.ts +10 -2
  131. package/src/web/utils/unistyle.ts +0 -2
  132. /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
@@ -40,7 +40,7 @@ fun interface Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRunti
40
40
  @Keep
41
41
  @Suppress(
42
42
  "KotlinJniMissingFunction", "unused",
43
- "RedundantSuppression", "RedundantUnitReturnType",
43
+ "RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
44
44
  "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
45
45
  )
46
46
  class Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx: Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime {
@@ -54,8 +54,13 @@ class Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx:
54
54
  mHybridData = hybridData
55
55
  }
56
56
 
57
+ @DoNotStrip
58
+ @Keep
59
+ override fun invoke(dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime): Unit
60
+ = invoke_cxx(dependencies,miniRuntime)
61
+
57
62
  @FastNative
58
- external override fun invoke(dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime): Unit
63
+ private external fun invoke_cxx(dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime): Unit
59
64
  }
60
65
 
61
66
  /**
@@ -37,87 +37,87 @@ abstract class HybridNativePlatformSpec: HybridObject() {
37
37
  }
38
38
 
39
39
  // Properties
40
-
40
+
41
41
 
42
42
  // Methods
43
43
  @DoNotStrip
44
44
  @Keep
45
45
  abstract fun getInsets(): Insets
46
-
46
+
47
47
  @DoNotStrip
48
48
  @Keep
49
49
  abstract fun getColorScheme(): ColorScheme
50
-
50
+
51
51
  @DoNotStrip
52
52
  @Keep
53
53
  abstract fun getFontScale(): Double
54
-
54
+
55
55
  @DoNotStrip
56
56
  @Keep
57
57
  abstract fun getPixelRatio(): Double
58
-
58
+
59
59
  @DoNotStrip
60
60
  @Keep
61
61
  abstract fun getOrientation(): Orientation
62
-
62
+
63
63
  @DoNotStrip
64
64
  @Keep
65
65
  abstract fun getContentSizeCategory(): String
66
-
66
+
67
67
  @DoNotStrip
68
68
  @Keep
69
69
  abstract fun getScreenDimensions(): Dimensions
70
-
70
+
71
71
  @DoNotStrip
72
72
  @Keep
73
73
  abstract fun getStatusBarDimensions(): Dimensions
74
-
74
+
75
75
  @DoNotStrip
76
76
  @Keep
77
77
  abstract fun getNavigationBarDimensions(): Dimensions
78
-
78
+
79
79
  @DoNotStrip
80
80
  @Keep
81
81
  abstract fun getPrefersRtlDirection(): Boolean
82
-
82
+
83
83
  @DoNotStrip
84
84
  @Keep
85
85
  abstract fun setRootViewBackgroundColor(color: Double): Unit
86
-
86
+
87
87
  @DoNotStrip
88
88
  @Keep
89
89
  abstract fun setNavigationBarHidden(isHidden: Boolean): Unit
90
-
90
+
91
91
  @DoNotStrip
92
92
  @Keep
93
93
  abstract fun setStatusBarHidden(isHidden: Boolean): Unit
94
-
94
+
95
95
  @DoNotStrip
96
96
  @Keep
97
97
  abstract fun setImmersiveMode(isEnabled: Boolean): Unit
98
-
98
+
99
99
  @DoNotStrip
100
100
  @Keep
101
101
  abstract fun getMiniRuntime(): UnistylesNativeMiniRuntime
102
-
102
+
103
103
  abstract fun registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime) -> Unit): Unit
104
-
104
+
105
105
  @DoNotStrip
106
106
  @Keep
107
- fun registerPlatformListener_cxx(callback: Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime): Unit {
107
+ private fun registerPlatformListener_cxx(callback: Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime): Unit {
108
108
  val __result = registerPlatformListener(callback)
109
109
  return __result
110
110
  }
111
-
111
+
112
112
  abstract fun registerImeListener(callback: (miniRuntime: UnistylesNativeMiniRuntime) -> Unit): Unit
113
-
113
+
114
114
  @DoNotStrip
115
115
  @Keep
116
- fun registerImeListener_cxx(callback: Func_void_UnistylesNativeMiniRuntime): Unit {
116
+ private fun registerImeListener_cxx(callback: Func_void_UnistylesNativeMiniRuntime): Unit {
117
117
  val __result = registerImeListener(callback)
118
118
  return __result
119
119
  }
120
-
120
+
121
121
  @DoNotStrip
122
122
  @Keep
123
123
  abstract fun unregisterPlatformListeners(): Unit
@@ -40,6 +40,22 @@ target_sources(
40
40
  # Define a flag to check if we are building properly
41
41
  add_definitions(-DBUILDING_UNISTYLES_WITH_GENERATED_CMAKE_PROJECT)
42
42
 
43
+ # From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
44
+ # Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
45
+ target_compile_definitions(
46
+ unistyles PRIVATE
47
+ -DFOLLY_NO_CONFIG=1
48
+ -DFOLLY_HAVE_CLOCK_GETTIME=1
49
+ -DFOLLY_USE_LIBCPP=1
50
+ -DFOLLY_CFG_NO_COROUTINES=1
51
+ -DFOLLY_MOBILE=1
52
+ -DFOLLY_HAVE_RECVMMSG=1
53
+ -DFOLLY_HAVE_PTHREAD=1
54
+ # Once we target android-23 above, we can comment
55
+ # the following line. NDK uses GNU style stderror_r() after API 23.
56
+ -DFOLLY_HAVE_XSI_STRERROR_R=1
57
+ )
58
+
43
59
  # Add all libraries required by the generated specs
44
60
  find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
45
61
  find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
@@ -44,7 +44,6 @@ namespace margelo::nitro::unistyles { struct UnistylesNativeMiniRuntime; }
44
44
  // Common C++ types used in Swift
45
45
  #include <NitroModules/ArrayBufferHolder.hpp>
46
46
  #include <NitroModules/AnyMapHolder.hpp>
47
- #include <NitroModules/HybridContext.hpp>
48
47
  #include <NitroModules/RuntimeError.hpp>
49
48
 
50
49
  // Forward declarations of Swift defined types
@@ -33,6 +33,7 @@ namespace margelo::nitro::unistyles {
33
33
  double height SWIFT_PRIVATE;
34
34
 
35
35
  public:
36
+ Dimensions() = default;
36
37
  explicit Dimensions(double width, double height): width(width), height(height) {}
37
38
  };
38
39
 
@@ -36,6 +36,7 @@ namespace margelo::nitro::unistyles {
36
36
  double ime SWIFT_PRIVATE;
37
37
 
38
38
  public:
39
+ Insets() = default;
39
40
  explicit Insets(double top, double bottom, double left, double right, double ime): top(top), bottom(bottom), left(left), right(right), ime(ime) {}
40
41
  };
41
42
 
@@ -54,6 +54,7 @@ namespace margelo::nitro::unistyles {
54
54
  bool isLandscape SWIFT_PRIVATE;
55
55
 
56
56
  public:
57
+ UnistylesCxxMiniRuntime() = default;
57
58
  explicit UnistylesCxxMiniRuntime(std::optional<std::string> themeName, std::optional<std::string> breakpoint, bool hasAdaptiveThemes, ColorScheme colorScheme, Dimensions screen, std::string contentSizeCategory, Insets insets, double pixelRatio, double fontScale, bool rtl, Dimensions statusBar, Dimensions navigationBar, bool isPortrait, bool isLandscape): themeName(themeName), breakpoint(breakpoint), hasAdaptiveThemes(hasAdaptiveThemes), colorScheme(colorScheme), screen(screen), contentSizeCategory(contentSizeCategory), insets(insets), pixelRatio(pixelRatio), fontScale(fontScale), rtl(rtl), statusBar(statusBar), navigationBar(navigationBar), isPortrait(isPortrait), isLandscape(isLandscape) {}
58
59
  };
59
60
 
@@ -50,6 +50,7 @@ namespace margelo::nitro::unistyles {
50
50
  bool isLandscape SWIFT_PRIVATE;
51
51
 
52
52
  public:
53
+ UnistylesNativeMiniRuntime() = default;
53
54
  explicit UnistylesNativeMiniRuntime(ColorScheme colorScheme, Dimensions screen, std::string contentSizeCategory, Insets insets, double pixelRatio, double fontScale, bool rtl, Dimensions statusBar, Dimensions navigationBar, bool isPortrait, bool isLandscape): colorScheme(colorScheme), screen(screen), contentSizeCategory(contentSizeCategory), insets(insets), pixelRatio(pixelRatio), fontScale(fontScale), rtl(rtl), statusBar(statusBar), navigationBar(navigationBar), isPortrait(isPortrait), isLandscape(isLandscape) {}
54
55
  };
55
56
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-nightly-20250221",
3
+ "version": "3.0.0-nightly-20250318",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -105,11 +105,11 @@
105
105
  "husky": "9.1.7",
106
106
  "jest": "29.7.0",
107
107
  "metro-react-native-babel-preset": "0.77.0",
108
- "nitro-codegen": "0.22.1",
108
+ "nitro-codegen": "0.24.1",
109
109
  "react": "18.3.1",
110
110
  "react-native": "0.77.1",
111
111
  "react-native-builder-bob": "0.37.0",
112
- "react-native-nitro-modules": "0.22.1",
112
+ "react-native-nitro-modules": "0.24.1",
113
113
  "react-native-web": "0.19.13",
114
114
  "react-test-renderer": "18.3.1",
115
115
  "release-it": "17.11.0",
package/plugin/index.js CHANGED
@@ -523,6 +523,12 @@ function getStylesDependenciesFromFunction(path) {
523
523
  usedLabel = "ime";
524
524
  }
525
525
  }
526
+ if (usedLabel === "insets" && (memberExpr.parentPath.isBinaryExpression() || memberExpr.parentPath.isLogicalExpression())) {
527
+ const secondPropPath = memberExpr.node.property;
528
+ if (t4.isIdentifier(secondPropPath) && secondPropPath.name === "ime") {
529
+ usedLabel = "ime";
530
+ }
531
+ }
526
532
  }
527
533
  }
528
534
  const containerProp = refPath.findParent((parent2) => parent2.isObjectProperty() && parent2.parentPath === returnedObjectPath);
@@ -42,6 +42,11 @@ export const createUnistylesElement = (Component: any) => {
42
42
 
43
43
  // @ts-ignore we don't know the type of the component
44
44
  maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
45
+
46
+ return () => {
47
+ // @ts-ignore
48
+ UnistylesShadowRegistry.remove(ref)
49
+ }
45
50
  }}
46
51
  />
47
52
  )
@@ -32,6 +32,11 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
32
32
  return () => {
33
33
  // @ts-ignore
34
34
  UnistylesShadowRegistry.remove(ref)
35
+
36
+ if (storedImageRef.current) {
37
+ // @ts-ignore
38
+ UnistylesShadowRegistry.remove(storedImageRef.current)
39
+ }
35
40
  }
36
41
  }}
37
42
  imageRef={ref => {
@@ -1,13 +1,14 @@
1
1
  import type { UnistylesValues } from '../types'
2
2
  import { UnistylesWeb } from '../web'
3
3
 
4
- export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>) => {
4
+ export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>, forChild?: boolean) => {
5
5
  if (!unistyle) {
6
6
  return undefined
7
7
  }
8
8
 
9
9
  const { hash, injectedClassName } = UnistylesWeb.shadowRegistry.addStyles(
10
- Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle]
10
+ Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle],
11
+ forChild
11
12
  )
12
13
 
13
14
  return hash ? { $$css: true, hash, injectedClassName } : undefined
@@ -63,6 +63,22 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
63
63
  })
64
64
  const proxifiedRuntime = new Proxy(getMiniRuntime(), {
65
65
  get: (target, prop) => {
66
+ if (prop === 'insets') {
67
+ return new Proxy(target.insets, {
68
+ get: (target, prop) => {
69
+ if (prop === 'ime') {
70
+ dependencies.add(UnistyleDependency.Ime)
71
+
72
+ return target[prop as keyof typeof target]
73
+ }
74
+
75
+ dependencies.add(UnistyleDependency.Insets)
76
+
77
+ return target[prop as keyof typeof target]
78
+ }
79
+ })
80
+ }
81
+
66
82
  if (prop in RTDependencyMap) {
67
83
  dependencies.add(RTDependencyMap[prop as keyof typeof RTDependencyMap])
68
84
  }
@@ -1,33 +1,58 @@
1
1
  import React, { forwardRef, useEffect, type ComponentType, useRef } from 'react'
2
2
  import { type UnistyleDependency, UnistylesShadowRegistry } from '../../specs'
3
3
  import type { UnistylesTheme } from '../../types'
4
- import type { PartialBy } from '../../types/common'
5
4
  import { deepMergeObjects } from '../../utils'
6
5
  import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
7
6
  import { maybeWarnAboutMultipleUnistyles } from '../warn'
8
- import type { Mappings, SupportedStyleProps } from './types'
7
+ import type { Mappings } from './types'
9
8
 
10
9
  // @ts-expect-error
11
10
  type GenericComponentProps<P> = ComponentProps<P>
12
11
  // @ts-expect-error
13
12
  type GenericComponentRef<T> = ComponentRef<T>
14
13
 
14
+ type UnistylesSecrets = {
15
+ uni__getStyles: () => Record<string, any>,
16
+ uni__dependencies: Array<UnistyleDependency>
17
+ }
18
+
19
+ type MappedSecrets = {
20
+ styles: Record<string, any>,
21
+ dependencies: Array<UnistyleDependency>
22
+ }
23
+
15
24
  export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
16
25
  type TProps = GenericComponentProps<TComponent>
17
- type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
26
+ type PropsWithUnistyles = Partial<TProps> & {
18
27
  uniProps?: Mappings<TProps>
19
28
  }
20
- const getSecrets = (styleProps: Record<string, any> = {}): { uni__getStyles(): any, uni__dependencies: Array<UnistyleDependency> } => {
21
- const unistyleKey = Object
22
- .keys(styleProps)
23
- .find(key => key.startsWith('unistyles_'))
24
-
25
- return unistyleKey
26
- ? styleProps[unistyleKey]
27
- : {
28
- uni__getStyles: () => styleProps,
29
- uni__dependencies: [],
30
- }
29
+ const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
30
+ const styles = Array.isArray(styleProps)
31
+ ? styleProps.flat()
32
+ : [styleProps]
33
+
34
+ const secrets: Array<UnistylesSecrets> = styles
35
+ .filter(Boolean)
36
+ .reduce((acc, style) => {
37
+ const unistyleKey = Object
38
+ .keys(style)
39
+ .find(key => key.startsWith('unistyles_'))
40
+
41
+ return acc.concat([
42
+ unistyleKey
43
+ ? style[unistyleKey]
44
+ : {
45
+ uni__getStyles: () => styleProps,
46
+ uni__dependencies: [],
47
+ }
48
+ ])
49
+ }, [])
50
+
51
+ return {
52
+ styles: secrets.reduce((acc, secret) => Object
53
+ .assign(acc, secret.uni__getStyles()), {} as Record<string, any>),
54
+ dependencies: secrets.flatMap(secret => secret.uni__dependencies),
55
+ }
31
56
  }
32
57
 
33
58
  return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
@@ -46,7 +71,7 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
46
71
  const styleSecrets = getSecrets(narrowedProps.style)
47
72
  const contentContainerStyleSecrets = getSecrets(narrowedProps.contentContainerStyle)
48
73
 
49
- addDependencies(Array.from(new Set([...styleSecrets.uni__dependencies, ...contentContainerStyleSecrets.uni__dependencies])))
74
+ addDependencies(Array.from(new Set([...styleSecrets.dependencies, ...contentContainerStyleSecrets.dependencies])))
50
75
  }, [narrowedProps.style, narrowedProps.contentContainerStyle])
51
76
 
52
77
  const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
@@ -58,10 +83,10 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
58
83
  const finalProps = {
59
84
  ...deepMergeObjects(mappingsProps, unistyleProps, props),
60
85
  ...narrowedProps.style ? {
61
- style: styleSecrets.uni__getStyles(),
86
+ style: styleSecrets.styles,
62
87
  } : {},
63
88
  ...narrowedProps.contentContainerStyle ? {
64
- contentContainerStyle: contentContainerStyleSecrets.uni__getStyles(),
89
+ contentContainerStyle: contentContainerStyleSecrets.styles,
65
90
  } : {},
66
91
  } as any
67
92
 
@@ -1,11 +1,10 @@
1
1
  import React, { type ComponentType, forwardRef, type ComponentProps, type ComponentRef } from 'react'
2
2
  import type { UnistylesValues } from '../../types'
3
- import type { PartialBy } from '../../types/common'
4
3
  import { deepMergeObjects } from '../../utils'
5
4
  import { getClassName } from '../getClassname'
6
5
  import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
7
6
  import { maybeWarnAboutMultipleUnistyles } from '../warn'
8
- import type { Mappings, SupportedStyleProps } from './types'
7
+ import type { Mappings } from './types'
9
8
 
10
9
  // @ts-expect-error
11
10
  type GenericComponentProps<T> = ComponentProps<T>
@@ -14,7 +13,7 @@ type GenericComponentRef<T> = ComponentRef<T>
14
13
 
15
14
  export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
16
15
  type TProps = GenericComponentProps<TComponent>
17
- type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
16
+ type PropsWithUnistyles = Partial<TProps> & {
18
17
  uniProps?: Mappings<TProps>
19
18
  }
20
19
  type UnistyleStyles = {
@@ -24,17 +23,22 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
24
23
 
25
24
  return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
26
25
  const narrowedProps = props as PropsWithUnistyles & UnistyleStyles
27
- const styleClassNames = getClassName(narrowedProps.style)
26
+ const styleClassNames = getClassName(narrowedProps.style, true)
28
27
  const contentContainerStyleClassNames = getClassName(narrowedProps.contentContainerStyle)
29
28
  const { proxifiedRuntime, proxifiedTheme } = useProxifiedUnistyles()
30
29
 
31
30
  const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
32
31
  const unistyleProps = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
33
32
 
33
+ const emptyStyles = Object.fromEntries(Object.entries(Object.getOwnPropertyDescriptors(narrowedProps.style))
34
+ .filter(([key]) => !key.startsWith('unistyles') && !key.startsWith('_'))
35
+ .map(([key]) => [key, undefined]))
36
+
34
37
  const combinedProps = {
35
38
  ...deepMergeObjects(mappingsProps, unistyleProps, props),
36
39
  ...narrowedProps.style ? {
37
- style: styleClassNames,
40
+ // Override default component styles with undefined values to reset them
41
+ style: emptyStyles
38
42
  } : {},
39
43
  ...narrowedProps.contentContainerStyle ? {
40
44
  contentContainerStyle: contentContainerStyleClassNames,
@@ -48,6 +52,13 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
48
52
 
49
53
  const NativeComponent = Component as ComponentType
50
54
 
51
- return <NativeComponent {...combinedProps} ref={ref} />
55
+ return (
56
+ <div
57
+ className={styleClassNames?.hash}
58
+ style={{ display: 'contents' }}
59
+ >
60
+ <NativeComponent {...combinedProps} ref={ref} />
61
+ </div>
62
+ )
52
63
  })
53
64
  }
@@ -1,5 +1,4 @@
1
1
  export type Optional<T> = T | undefined
2
2
  export type Nullable<T> = T | null
3
3
  export type SafeReturnType<T> = T extends (...args: any) => infer R ? R : T
4
- export type PartialBy<T, K> = Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>
5
4
  export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
@@ -21,7 +21,7 @@ export class UnistylesRegistry {
21
21
  }
22
22
 
23
23
  if (scopedThemeName) {
24
- const scopedTheme = this.services.runtime.getTheme(scopedThemeName, this.services.state.CSSVars)
24
+ const scopedTheme = this.services.runtime.getTheme(scopedThemeName)
25
25
 
26
26
  if (!scopedTheme) {
27
27
  throw error(`Unistyles: You're trying to use scoped theme '${scopedThemeName}' but it wasn't registered.`)
@@ -92,8 +92,11 @@ export class UnistylesRegistry {
92
92
  return false
93
93
  }
94
94
 
95
- add = (value: UnistylesValues) => {
96
- const hash = generateHash(value)
95
+ add = (value: UnistylesValues, forChild?: boolean) => {
96
+ const generatedHash = generateHash(value)
97
+ const hash = forChild
98
+ ? `${generatedHash} > *`
99
+ : generatedHash
97
100
 
98
101
  if (!this.stylesCache.has(hash)) {
99
102
  this.applyStyles(hash, value)
@@ -1,7 +1,7 @@
1
1
  import { UnistyleDependency } from '../specs/NativePlatform'
2
2
  import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
3
3
  import { type AppTheme, type AppThemeName, ColorScheme, Orientation } from '../specs/types'
4
- import { WebContentSizeCategory } from '../types'
4
+ import { type UnistylesTheme, WebContentSizeCategory } from '../types'
5
5
  import { NavigationBar, StatusBar } from './mock'
6
6
  import type { UnistylesServices } from './types'
7
7
  import { error, isServer, schemeToTheme } from './utils'
@@ -213,7 +213,11 @@ export class UnistylesRuntime {
213
213
  : this.services.state.themes.get(themeName ?? '')
214
214
 
215
215
  if (!themeName || !theme) {
216
- throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
216
+ return new Proxy({} as UnistylesTheme, {
217
+ get: () => {
218
+ throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
219
+ }
220
+ })
217
221
  }
218
222
 
219
223
  return theme
@@ -27,7 +27,7 @@ export class UnistylesShadowRegistry {
27
27
  this.services.registry.connect(ref, hash)
28
28
  }
29
29
 
30
- addStyles = (unistyles: Array<UnistylesValues>) => {
30
+ addStyles = (unistyles: Array<UnistylesValues>, forChild?: boolean) => {
31
31
  const getParsedStyles = () => {
32
32
  const allStyles = unistyles.map(unistyle => {
33
33
  const secrets = extractSecrets(unistyle)
@@ -61,7 +61,7 @@ export class UnistylesShadowRegistry {
61
61
  // Copy scoped theme to not use referenced value
62
62
  const scopedTheme = this.scopedTheme
63
63
  const parsedStyles = getParsedStyles()
64
- const { hash, existingHash } = this.services.registry.add(parsedStyles)
64
+ const { hash, existingHash } = this.services.registry.add(parsedStyles, forChild)
65
65
  const injectedClassNames = parsedStyles?._web?._classNames ?? []
66
66
  const injectedClassName = Array.isArray(injectedClassNames) ? injectedClassNames.join(' ') : injectedClassNames
67
67
  const dependencies = extractUnistyleDependencies(parsedStyles)
@@ -75,7 +75,11 @@ export class UnistylesShadowRegistry {
75
75
  }))
76
76
  }
77
77
 
78
- return { injectedClassName, hash }
78
+ const hashClassname = forChild
79
+ ? hash.replace(' > *', '')
80
+ : hash
81
+
82
+ return { injectedClassName, hash: hashClassname }
79
83
  }
80
84
 
81
85
  setScopedTheme = (theme?: UnistylesTheme) => {
package/src/web/state.ts CHANGED
@@ -58,7 +58,11 @@ export class UnistylesState {
58
58
  this.services.listener.initListeners()
59
59
  }
60
60
 
61
- private initThemes = (themes = {} as UnistylesThemes, CSSVars = true) => {
61
+ private initThemes = (themes?: UnistylesThemes, CSSVars = true) => {
62
+ if (!themes) {
63
+ return
64
+ }
65
+
62
66
  this.CSSVars = CSSVars
63
67
 
64
68
  Object.entries(themes).forEach(([themeName, theme]) => {
@@ -117,7 +121,11 @@ export class UnistylesState {
117
121
  }
118
122
  }
119
123
 
120
- private initBreakpoints = (breakpoints = {} as UnistylesBreakpoints) => {
124
+ private initBreakpoints = (breakpoints?: UnistylesBreakpoints) => {
125
+ if (!breakpoints) {
126
+ return
127
+ }
128
+
121
129
  this.breakpoints = breakpoints
122
130
  const breakpointsEntries = Object.entries(breakpoints)
123
131
 
@@ -70,8 +70,6 @@ export const removeInlineStyles = (values: UnistylesValues) => {
70
70
  return returnValue
71
71
  }
72
72
 
73
- export const isInDocument = (element: HTMLElement) => document.body.contains(element)
74
-
75
73
  export const getMediaQuery = (query: string, allBreakpoints: Array<string>) => {
76
74
  if (Object.values(Orientation).includes(query as Orientation)) {
77
75
  return `@media (orientation: ${query})`