react-native-unistyles 3.0.0-alpha.37 → 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 +15 -18
  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 +16 -19
  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 +19 -2
  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 +16 -23
  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
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState, type ComponentType } from 'react'
1
+ import React, { useEffect, useState, type ComponentType, forwardRef, useRef, useMemo } from 'react'
2
2
  import type { UnistylesTheme } from '../types'
3
3
  import { UnistylesRuntime } from '../specs'
4
4
  import { UnistyleDependency } from '../specs/NativePlatform'
@@ -6,6 +6,7 @@ import type { PartialBy } from '../types/common'
6
6
  import { UnistylesListener } from '../web/listener'
7
7
  import { UnistylesShadowRegistry } from '../web'
8
8
  import { equal } from '../web/utils'
9
+ import { deepMergeObjects } from '../utils'
9
10
 
10
11
  const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'] as const
11
12
  const ALL_DEPENDENCIES = Object.values(UnistyleDependency).filter((dependency): dependency is UnistyleDependency => typeof dependency === 'number')
@@ -13,34 +14,40 @@ const ALL_DEPENDENCIES = Object.values(UnistyleDependency).filter((dependency):
13
14
  type SupportedStyleProps = typeof SUPPORTED_STYLE_PROPS[number]
14
15
 
15
16
  const useShadowRegistry = (style?: Record<string, any>) => {
16
- const [classNames, setClassNames] = useState<Array<string>>([])
17
17
  const [ref] = useState(document.createElement('div'))
18
+ const oldClassNames = useRef<Array<string>>([])
19
+ const classNames = useMemo(() => {
20
+ if (!style) {
21
+ return []
22
+ }
18
23
 
19
- if (style) {
20
- UnistylesShadowRegistry
21
- .add(ref, style)
22
- .then(newClassNames => {
23
- if (equal(classNames, newClassNames)) {
24
- return
25
- }
24
+ const newClassNames = UnistylesShadowRegistry.add(ref, [style], undefined, []) ?? []
26
25
 
27
- setClassNames(newClassNames)
28
- })
29
- }
26
+ if (equal(oldClassNames.current, newClassNames)) {
27
+ return oldClassNames.current
28
+ }
29
+
30
+ oldClassNames.current = newClassNames
31
+
32
+ return newClassNames
33
+ }, [style])
30
34
 
31
35
  useEffect(() => () => {
32
36
  // Remove styles on unmount
33
- UnistylesShadowRegistry.add(null, style)
37
+ if (style) {
38
+ UnistylesShadowRegistry.add(null, [style], undefined, [])
39
+ }
34
40
  })
35
41
 
36
42
  return classNames
37
43
  }
38
44
 
39
45
  export const createUnistylesComponent = <TProps extends Record<string, any>, TMappings extends Partial<Omit<TProps, SupportedStyleProps>>>(Component: ComponentType<TProps>, mappings?: (theme: UnistylesTheme) => TMappings) => {
40
- return (props: PartialBy<TProps, keyof TMappings | SupportedStyleProps>) => {
46
+ return forwardRef<unknown, PartialBy<TProps, keyof TMappings | SupportedStyleProps>>((props, ref) => {
47
+ const narrowedProps = props as PartialBy<TProps, keyof TMappings | SupportedStyleProps>
41
48
  const [mappingsProps, setMappingsProps] = useState(mappings?.(UnistylesRuntime.getTheme()))
42
- const styleClassNames = useShadowRegistry(props.style)
43
- const contentContainerStyleClassNames = useShadowRegistry(props.contentContainerStyle)
49
+ const styleClassNames = useShadowRegistry(narrowedProps.style)
50
+ const contentContainerStyleClassNames = useShadowRegistry(narrowedProps.contentContainerStyle)
44
51
 
45
52
  useEffect(() => {
46
53
  const disposeMappings = UnistylesListener.addListeners(ALL_DEPENDENCIES, () => {
@@ -54,18 +61,17 @@ export const createUnistylesComponent = <TProps extends Record<string, any>, TMa
54
61
  })
55
62
 
56
63
  return () => disposeMappings()
57
- }, [mappingsProps, props.style])
64
+ }, [mappingsProps, narrowedProps.style])
58
65
 
59
66
  const combinedProps = {
60
- ...mappingsProps,
61
- ...props,
62
- ...props.style ? {
67
+ ...deepMergeObjects(props, (mappingsProps ?? {}) as object),
68
+ ...narrowedProps.style ? {
63
69
  style: {
64
70
  $$css: true,
65
71
  'unistyles': styleClassNames.join(' ')
66
72
  },
67
73
  } : {},
68
- ...props.contentContainerStyle ? {
74
+ ...narrowedProps.contentContainerStyle ? {
69
75
  style: {
70
76
  $$css: true,
71
77
  'unistyles': contentContainerStyleClassNames.join(' ')
@@ -73,6 +79,6 @@ export const createUnistylesComponent = <TProps extends Record<string, any>, TMa
73
79
  } : {},
74
80
  } as unknown as TProps
75
81
 
76
- return <Component {...combinedProps} />
77
- }
82
+ return <Component {...combinedProps} ref={ref} />
83
+ })
78
84
  }
@@ -51,15 +51,13 @@ export interface NativePlatform extends HybridObject<{ ios: 'swift', android: 'k
51
51
  getPrefersRtlDirection(): boolean,
52
52
 
53
53
  setRootViewBackgroundColor(color: number): void,
54
- setNavigationBarBackgroundColor?(color: number): void,
55
54
  setNavigationBarHidden?(isHidden: boolean): void,
56
55
  setStatusBarHidden(isHidden: boolean): void,
57
- setStatusBarBackgroundColor?(color: number): void,
58
56
  setImmersiveMode(isEnabled: boolean): void,
59
57
 
60
58
  // private
61
59
  getMiniRuntime(): UnistylesNativeMiniRuntime,
62
- registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>) => void): void,
63
- registerImeListener(callback: () => void): void,
60
+ registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime) => void): void,
61
+ registerImeListener(callback: (miniRuntime: UnistylesNativeMiniRuntime) => void): void,
64
62
  unregisterPlatformListeners(): void
65
63
  }
@@ -5,6 +5,5 @@ export interface UnistylesNavigationBar extends HybridObject<{ ios: 'c++', andro
5
5
  readonly width: number,
6
6
  readonly height: number,
7
7
 
8
- setBackgroundColor(color: number): void,
9
8
  setHidden(isHidden: boolean): void
10
9
  }
@@ -1,30 +1 @@
1
- import { processColor } from 'react-native'
2
- import type { UnistylesNavigationBar as UnistylesNavigationBarSpec } from './UnistylesNavigationBar.nitro'
3
- import type { Color } from '../types'
4
-
5
- interface PrivateUnistylesNavigationBar extends Omit<UnistylesNavigationBarSpec, 'setBackgroundColor'> {
6
- /**
7
- * Apps targeting Android SDK 35
8
- * This API is deprecated but continues to affect 3-button navigation
9
- * @deprecated
10
- */
11
- setBackgroundColor(color?: string): void,
12
- _setBackgroundColor(color?: Color): void
13
- }
14
-
15
- export const attachNavigationBarJSMethods = (hybridObject: UnistylesNavigationBar) => {
16
- const privateHybrid = hybridObject as PrivateUnistylesNavigationBar
17
-
18
- privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor
19
- hybridObject.setBackgroundColor = (color?: string) => {
20
- const parsedColor = processColor(color) ?? 0
21
-
22
- privateHybrid._setBackgroundColor(parsedColor as number)
23
- }
24
- }
25
-
26
- type PrivateMethods =
27
- | '_setBackgroundColor'
28
- | 'dispose'
29
-
30
- export type UnistylesNavigationBar = Omit<PrivateUnistylesNavigationBar, PrivateMethods>
1
+ export type { UnistylesNavigationBar } from './UnistylesNavigationBar.nitro'
@@ -4,10 +4,10 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types'
4
4
 
5
5
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
6
6
  // Babel API
7
- add(handle?: ViewHandle, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void,
8
- remove(handle?: ViewHandle, style?: Unistyle): void,
7
+ add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>): void,
8
+ remove(handle?: ViewHandle): void,
9
9
  // JSI
10
- link(node: ShadowNode, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void,
10
+ link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>): void,
11
11
  unlink(node: ShadowNode): void
12
12
  }
13
13
 
@@ -26,18 +26,15 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
26
26
  return node
27
27
  }
28
28
 
29
- HybridShadowRegistry.add = (handle, style, variants, args) => {
29
+ HybridShadowRegistry.add = (handle, styles, variants, args) => {
30
30
  // virtualized nodes can be null
31
- if (!handle || !style) {
31
+ if (!handle || !styles || !Array.isArray(styles)) {
32
32
  return
33
33
  }
34
34
 
35
- // don't register Reanimated styles
36
- if (style?.initial?.updater) {
37
- return
38
- }
39
-
40
- HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? [])
35
+ // filter Reanimated styles
36
+ const filteredStyles = styles.filter(style => !style?.initial?.updater)
37
+ HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [])
41
38
  }
42
39
 
43
40
  HybridShadowRegistry.remove = handle => {
@@ -5,6 +5,5 @@ export interface UnistylesStatusBar extends HybridObject<{ ios: 'c++', android:
5
5
  readonly width: number,
6
6
  readonly height: number,
7
7
 
8
- setBackgroundColor(color: number): void,
9
8
  setHidden(isHidden: boolean): void,
10
9
  }
@@ -1,6 +1,6 @@
1
- import { processColor, StatusBar as NativeStatusBar } from 'react-native'
1
+ import { StatusBar as NativeStatusBar } from 'react-native'
2
2
  import type { UnistylesStatusBar as UnistylesStatusBarSpec } from './UnistylesStatusBar.nitro'
3
- import { type Color, StatusBarStyle } from '../types'
3
+ import { StatusBarStyle } from '../types'
4
4
 
5
5
  export type StatusBarHiddenAnimation = 'none' | 'fade' | 'slide'
6
6
 
@@ -8,13 +8,6 @@ interface PrivateUnistylesStatusBar extends Omit<UnistylesStatusBarSpec, 'setBac
8
8
  setStyle(style: StatusBarStyle, animated?: boolean): void,
9
9
  setHidden(isHidden: boolean, animation?: StatusBarHiddenAnimation): void,
10
10
  _setHidden(isHidden: boolean, animation?: StatusBarHiddenAnimation): void,
11
- /**
12
- * Apps targeting Android SDK 35
13
- * This API is deprecated as status bar background color is always transparent
14
- * @deprecated
15
- */
16
- setBackgroundColor(color?: string): void,
17
- _setBackgroundColor(color?: Color): void
18
11
  }
19
12
 
20
13
  export const attachStatusBarJSMethods = (hybridObject: UnistylesStatusBar) => {
@@ -36,17 +29,9 @@ export const attachStatusBarJSMethods = (hybridObject: UnistylesStatusBar) => {
36
29
  NativeStatusBar.setHidden(isHidden, animation)
37
30
  privateHybrid._setHidden(isHidden)
38
31
  }
39
-
40
- privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor
41
- hybridObject.setBackgroundColor = (color?: string) => {
42
- const parsedColor = processColor(color) ?? 0
43
-
44
- privateHybrid._setBackgroundColor(parsedColor as number)
45
- }
46
32
  }
47
33
 
48
34
  type PrivateMethods =
49
- | '_setBackgroundColor'
50
35
  | '_setHidden'
51
36
  | 'dispose'
52
37
 
@@ -3,7 +3,7 @@ import { NitroModules } from 'react-native-nitro-modules'
3
3
  import type { UnistylesRuntime as UnistylesRuntimeSpec, UnistylesMiniRuntime } from './UnistylesRuntime.nitro'
4
4
  import type { AppBreakpoint, AppTheme, AppThemeName, Color, ColorScheme, Orientation } from '../types'
5
5
  import { attachStatusBarJSMethods, type UnistylesStatusBar } from '../StatusBar'
6
- import { attachNavigationBarJSMethods, type UnistylesNavigationBar } from '../NavigtionBar'
6
+ import { type UnistylesNavigationBar } from '../NavigtionBar'
7
7
  import type { AndroidContentSizeCategory, IOSContentSizeCategory, UnistylesTheme } from '../../types'
8
8
  import { isIOS } from '../../common'
9
9
  import type { UnistylesThemes } from '../../global'
@@ -57,7 +57,6 @@ if (isIOS) {
57
57
  }
58
58
 
59
59
  attachStatusBarJSMethods(HybridUnistylesRuntime.statusBar)
60
- attachNavigationBarJSMethods(HybridUnistylesRuntime.navigationBar)
61
60
 
62
61
  export const Runtime = HybridUnistylesRuntime as UnistylesRuntime
63
62
 
package/src/utils.ts ADDED
@@ -0,0 +1,22 @@
1
+ export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources: Array<T>) => {
2
+ const target = {} as T
3
+
4
+ sources.forEach(source => {
5
+ Object.keys(source).forEach(key => {
6
+ const sourceValue = source[key]
7
+ const targetValue = target[key]
8
+
9
+ if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
10
+ // @ts-expect-error - can't assign to generic
11
+ target[key] = deepMergeObjects(targetValue, sourceValue)
12
+
13
+ return
14
+ }
15
+
16
+ // @ts-expect-error - can't assign to generic
17
+ target[key] = sourceValue
18
+ })
19
+ })
20
+
21
+ return target
22
+ }
@@ -1,7 +1,7 @@
1
1
  import type { UnistylesValues } from '../../types'
2
2
  import { isPseudo } from './pseudo'
3
3
  import { getStyle } from './style'
4
- import { deepMergeObjects } from '../utils'
4
+ import { deepMergeObjects } from '../../utils'
5
5
  import { getTransformStyle, getBoxShadow, getFilterStyle } from './object'
6
6
  import { isShadow, isFilter, isTextShadow, isTransform, isBoxShadow } from './utils'
7
7
  import { getTextShadowStyle, getBoxShadowStyle } from './shadow'
@@ -1,6 +1,7 @@
1
1
  import type { BoxShadowValue } from 'react-native'
2
2
  import { normalizeNumericValue } from '../utils'
3
- import { deepMergeObjects, keyInObject } from '../../utils'
3
+ import { keyInObject } from '../../utils'
4
+ import { deepMergeObjects } from '../../../utils'
4
5
 
5
6
  const createBoxShadowValue = (style: BoxShadowValue) => {
6
7
  const { offsetX, offsetY, blurRadius = 0, spreadDistance = 0, color = '#000', inset } = style
@@ -1,4 +1,5 @@
1
- import { deepMergeObjects, keyInObject } from '../../utils'
1
+ import { deepMergeObjects } from '../../../utils'
2
+ import { keyInObject } from '../../utils'
2
3
 
3
4
  type Styles = Record<string, any>
4
5
  type Normalize<TStyles extends Styles> = (key: keyof TStyles, value: TStyles[keyof TStyles]) => any
@@ -1,4 +1,4 @@
1
- import { deepMergeObjects } from '../../utils'
1
+ import { deepMergeObjects } from '../../../utils'
2
2
  import { BOX_SHADOW_STYLES, type BoxShadow } from '../types'
3
3
  import { extractShadowValue, normalizeColor, normalizeNumericValue } from '../utils'
4
4
  import { getShadowBreakpoints } from './getShadowBreakpoints'
@@ -1,4 +1,4 @@
1
- import { deepMergeObjects } from '../../utils'
1
+ import { deepMergeObjects } from '../../../utils'
2
2
  import { TEXT_SHADOW_STYLES, type TextShadow } from '../types'
3
3
  import { extractShadowValue, normalizeColor, normalizeNumericValue } from '../utils'
4
4
  import { getShadowBreakpoints } from './getShadowBreakpoints'
package/src/web/create.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ReactNativeStyleSheet } from '../types'
2
2
  import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
3
- import { assignSecrets, reduceObject, getStyles, deepMergeObjects } from './utils'
3
+ import { assignSecrets, reduceObject, getStyles } from './utils'
4
+ import { deepMergeObjects } from '../utils'
4
5
  import { UnistylesRuntime } from './runtime'
5
6
  import { createUseVariants, getVariants } from './variants'
6
7
 
package/src/web/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { create } from './create'
2
2
  import { UnistylesState } from './state'
3
- import { deepMergeObjects } from './utils'
3
+ import { deepMergeObjects } from '../utils'
4
4
 
5
5
  export const StyleSheet = {
6
6
  configure: UnistylesState.init,
@@ -17,8 +17,28 @@ class UnistylesListenerBuilder {
17
17
  }
18
18
 
19
19
  this.isInitialized = true
20
- UnistylesRuntime.darkMedia?.addEventListener('change', () => this.emitChange(UnistyleDependency.ColorScheme))
21
- UnistylesRuntime.lightMedia?.addEventListener('change', () => this.emitChange(UnistyleDependency.ColorScheme))
20
+ UnistylesRuntime.darkMedia?.addEventListener('change', event => {
21
+ if (!event.matches) {
22
+ return
23
+ }
24
+
25
+ this.emitChange(UnistyleDependency.ColorScheme)
26
+
27
+ if (UnistylesRuntime.hasAdaptiveThemes) {
28
+ this.emitChange(UnistyleDependency.Theme)
29
+ }
30
+ })
31
+ UnistylesRuntime.lightMedia?.addEventListener('change', event => {
32
+ if (!event.matches) {
33
+ return
34
+ }
35
+
36
+ this.emitChange(UnistyleDependency.ColorScheme)
37
+
38
+ if (UnistylesRuntime.hasAdaptiveThemes) {
39
+ this.emitChange(UnistyleDependency.Theme)
40
+ }
41
+ })
22
42
  window.addEventListener('orientationchange', () => this.emitChange(UnistyleDependency.Orientation))
23
43
  window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
24
44
  }
package/src/web/mock.ts CHANGED
@@ -6,7 +6,6 @@ export const StatusBar: StatusBarSpec = {
6
6
  height: 0,
7
7
  setStyle: () => {},
8
8
  setHidden: () => {},
9
- setBackgroundColor: () => {},
10
9
  equals: () => true,
11
10
  toString: () => 'StatusBar',
12
11
  __type: 'web',
@@ -17,8 +16,8 @@ export const NavigationBar: NavigationBarSpec = {
17
16
  width: 0,
18
17
  height: 0,
19
18
  setHidden: () => {},
20
- setBackgroundColor: () => {},
21
19
  equals: () => true,
20
+ dispose: () => {},
22
21
  toString: () => 'NavigationBar',
23
22
  __type: 'web',
24
23
  name: 'NavigationBar'
@@ -5,7 +5,7 @@ import { WebContentSizeCategory } from '../types'
5
5
  import { UnistylesListener } from './listener'
6
6
  import { NavigationBar, StatusBar } from './mock'
7
7
  import { UnistylesState } from './state'
8
- import { hexToRGBA, isServer, schemeToTheme } from './utils'
8
+ import { isServer, schemeToTheme } from './utils'
9
9
 
10
10
  class UnistylesRuntimeBuilder {
11
11
  lightMedia = this.getLightMedia()
@@ -47,6 +47,10 @@ class UnistylesRuntimeBuilder {
47
47
  }
48
48
 
49
49
  get themeName() {
50
+ if (UnistylesState.hasAdaptiveThemes) {
51
+ return schemeToTheme(this.colorScheme) as AppThemeName
52
+ }
53
+
50
54
  return UnistylesState.themeName
51
55
  }
52
56
 
@@ -167,12 +171,12 @@ class UnistylesRuntimeBuilder {
167
171
  this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme) as AppThemeName)
168
172
  }
169
173
 
170
- setRootViewBackgroundColor = (hex: string, alpha?: number) => {
174
+ setRootViewBackgroundColor = (color: string) => {
171
175
  if (isServer()) {
172
176
  return
173
177
  }
174
178
 
175
- document.documentElement.style.backgroundColor = alpha ? hexToRGBA(hex, alpha) : hex
179
+ document.documentElement.style.backgroundColor = color
176
180
  }
177
181
 
178
182
  setImmersiveMode = () => {}
@@ -2,7 +2,8 @@ import type { UnistylesValues } from '../types'
2
2
  import { convertUnistyles } from './convert'
3
3
  import { UnistylesListener } from './listener'
4
4
  import { UnistylesRegistry } from './registry'
5
- import { deepMergeObjects, equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils'
5
+ import { deepMergeObjects } from '../utils'
6
+ import { equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils'
6
7
  import { getVariants } from './variants'
7
8
 
8
9
  type Style = UnistylesValues | ((...args: Array<any>) => UnistylesValues)
@@ -19,27 +20,13 @@ class UnistylesShadowRegistryBuilder {
19
20
  private resultsMap = new Map<HTMLElement, UnistylesValues>()
20
21
  private hashMap = new Map<HTMLElement, string>()
21
22
  private classNamesMap = new Map<HTMLElement, Array<string>>()
22
- private timeoutMap = new Map<HTMLElement, NodeJS.Timeout>()
23
- private queuedResultMap = new Map<HTMLElement, Record<string, any>>()
24
23
 
25
- add = (ref: any, _style?: Style | Array<Style>, _variants?: Record<string, any>, _args?: Array<any>) => new Promise<Array<string>>(resolve => {
24
+ add = (ref: any, _style: Array<Style>, _variants: Record<string, any> | undefined, _args: Array<Array<any>>) => {
26
25
  // Style is not provided
27
26
  if (!_style) {
28
27
  return
29
28
  }
30
29
 
31
- // Array of styles
32
- if (Array.isArray(_style)) {
33
- _style.forEach(style => this.add(ref, style, _variants, _args))
34
-
35
- return
36
- }
37
-
38
- // Not a unistyle
39
- if (!Object.keys(_style).some(key => key.startsWith('__uni__'))) {
40
- return
41
- }
42
-
43
30
  // Ref is unmounted, remove style tags from the document
44
31
  if (ref === null) {
45
32
  const secrets = extractSecrets(_style)
@@ -68,70 +55,34 @@ class UnistylesShadowRegistryBuilder {
68
55
  return
69
56
  }
70
57
 
71
- extractSecrets(_style).forEach(secret => {
58
+ const styles = _style.filter(style => Object.keys(style ?? {}).some(key => key.startsWith('__uni__')))
59
+
60
+ // No unistyles
61
+ if (styles.length === 0) {
62
+ return
63
+ }
64
+
65
+ const parsedStyles = styles.flatMap((style, styleIndex) => extractSecrets(style).map(secret => {
72
66
  const { __uni__key, __uni__stylesheet, __uni__variants, __uni__args = [], __uni__refs } = secret
73
67
  const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
74
68
  const style = newComputedStylesheet[__uni__key]!
75
- const args = _args ?? __uni__args
76
69
  const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants
70
+ const args = _args[styleIndex] ? _args[styleIndex] : __uni__args
77
71
  const result = typeof style === 'function'
78
72
  ? style(...args)
79
73
  : style
80
74
  const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
81
75
  const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
76
+ const dependencies = extractUnistyleDependencies(resultWithVariants)
82
77
 
83
- // Get stored result from queue
84
- const storedResult = this.queuedResultMap.get(ref) ?? {}
85
- // Merge stored result with new result
86
- const newResult = deepMergeObjects(storedResult, resultWithVariants)
87
- const timeout = this.timeoutMap.get(ref)
88
-
89
- // Add callback to the queue and remove old one
90
- this.queuedResultMap.set(ref, newResult)
91
- clearTimeout(timeout)
92
- this.timeoutMap.set(ref, setTimeout(() => {
93
- const oldResult = this.resultsMap.get(ref)
94
-
95
- // If results are the same do nothing
96
- if (equal(oldResult, newResult)) {
97
- return
98
- }
99
-
100
- const oldClassNames = this.classNamesMap.get(ref)
101
-
102
- // Remove old styles
103
- if (oldResult) {
104
- UnistylesRegistry.remove(oldResult)
105
- }
106
-
107
- // Remove old classnames from the ref
108
- oldClassNames?.forEach(className => ref.classList.remove(className))
109
- this.resultsMap.set(ref, newResult)
78
+ if (typeof __uni__stylesheet === 'function') {
79
+ // Add dependencies from dynamic styles to stylesheet
80
+ UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
81
+ }
110
82
 
111
- const { hash, existingHash } = UnistylesRegistry.add(newResult)
112
- const injectedClassNames: Array<string> = newResult?._web?._classNames ?? []
113
- const newClassNames = injectedClassNames.concat(hash)
114
- const dependencies = extractUnistyleDependencies(newResult)
83
+ __uni__refs.add(ref)
115
84
 
116
- if (typeof __uni__stylesheet === 'function') {
117
- // Add dependencies from dynamic styles to stylesheet
118
- UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
119
- }
120
-
121
- __uni__refs.add(ref)
122
- this.classNamesMap.set(ref, newClassNames)
123
- // Add new classnames to the ref
124
- ref.classList.add(...newClassNames)
125
- resolve(newClassNames)
126
-
127
- // If it is new hash add it to the map to use for the listener
128
- if (!existingHash) {
129
- this.hashMap.set(ref, hash)
130
- }
131
- }, 0))
132
-
133
- // Listen for theme / runtime changes
134
- const dispose = UnistylesListener.addListeners(extractUnistyleDependencies(newResult), () => {
85
+ const dispose = UnistylesListener.addListeners(extractUnistyleDependencies(resultWithVariants), () => {
135
86
  const hash = this.hashMap.get(ref)
136
87
 
137
88
  // Dispose listener if there is no hash
@@ -151,8 +102,42 @@ class UnistylesShadowRegistryBuilder {
151
102
 
152
103
  UnistylesRegistry.applyStyles(hash, convertUnistyles(resultWithVariants))
153
104
  })
154
- })
155
- })
105
+
106
+ return resultWithVariants as UnistylesValues
107
+ }))
108
+ const combinedStyles = deepMergeObjects(...parsedStyles)
109
+ const oldStyles = this.resultsMap.get(ref)
110
+
111
+ if (equal(combinedStyles, oldStyles)) {
112
+ return
113
+ }
114
+
115
+ const oldClassNames = this.classNamesMap.get(ref)
116
+
117
+ // Remove old styles
118
+ if (oldStyles) {
119
+ UnistylesRegistry.remove(oldStyles)
120
+ }
121
+
122
+ // Remove old classnames from the ref
123
+ oldClassNames?.forEach(className => ref.classList.remove(className))
124
+ this.resultsMap.set(ref, combinedStyles)
125
+
126
+ const { hash, existingHash } = UnistylesRegistry.add(combinedStyles)
127
+ const injectedClassNames = combinedStyles?._web?._classNames ?? []
128
+ const newClassNames = (Array.isArray(injectedClassNames) ? injectedClassNames : [injectedClassNames]).concat(hash)
129
+
130
+ this.classNamesMap.set(ref, newClassNames)
131
+ // Add new classnames to the ref
132
+ ref.classList.add(...newClassNames)
133
+
134
+ // If it is new hash add it to the map to use for the listener
135
+ if (!existingHash) {
136
+ this.hashMap.set(ref, hash)
137
+ }
138
+
139
+ return newClassNames
140
+ }
156
141
 
157
142
  remove = () => {}
158
143
  }
@@ -7,32 +7,6 @@ export const keyInObject = <T extends Record<string, any>>(obj: T, key: Property
7
7
 
8
8
  export const isServer = () => typeof window === 'undefined'
9
9
 
10
- /**
11
- * Deeply merges properties of passed object
12
- */
13
- export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources: Array<T>) => {
14
- const target = {} as T
15
-
16
- sources.forEach(source => {
17
- Object.keys(source).forEach(key => {
18
- const sourceValue = source[key]
19
- const targetValue = target[key]
20
-
21
- if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
22
- // @ts-expect-error - can't assign to generic
23
- target[key] = deepMergeObjects(targetValue, sourceValue)
24
-
25
- return
26
- }
27
-
28
- // @ts-expect-error - can't assign to generic
29
- target[key] = sourceValue
30
- })
31
- })
32
-
33
- return target
34
- }
35
-
36
10
  export const warn = (message: string) => console.warn(`🦄 [react-native-unistyles] ${message}`)
37
11
 
38
12
  export const equal = <T>(a: T, b: T) => {
@@ -5,7 +5,7 @@ import { isUnistylesMq, parseMq } from '../../mq'
5
5
  import { UnistylesState } from '../state'
6
6
  import { keyInObject, reduceObject } from './common'
7
7
 
8
- export const schemeToTheme = (scheme: ColorScheme): string => {
8
+ export const schemeToTheme = (scheme: ColorScheme) => {
9
9
  switch (scheme) {
10
10
  case ColorScheme.Dark:
11
11
  return 'dark'
@@ -1,5 +1,5 @@
1
1
  import type { ReactNativeStyleSheet, StyleSheet } from '../../types'
2
- import { deepMergeObjects } from '../utils'
2
+ import { deepMergeObjects } from '../../utils'
3
3
 
4
4
  type StylesWithVariants = {
5
5
  variants: Record<string, any>,