react-native-unistyles 3.0.0-alpha.27 → 3.0.0-alpha.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. package/README.md +7 -0
  2. package/android/CMakeLists.txt +12 -21
  3. package/cxx/core/UnistylesMountHook.cpp +0 -10
  4. package/cxx/core/UnistylesMountHook.h +3 -8
  5. package/cxx/core/UnistylesRegistry.cpp +4 -8
  6. package/cxx/core/UnistylesRegistry.h +1 -1
  7. package/cxx/core/UnistylesState.cpp +2 -10
  8. package/cxx/core/UnistylesState.h +1 -1
  9. package/cxx/hybridObjects/HybridStyleSheet.cpp +67 -34
  10. package/cxx/hybridObjects/HybridStyleSheet.h +9 -1
  11. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +15 -7
  12. package/cxx/hybridObjects/HybridUnistylesRuntime.h +5 -1
  13. package/cxx/parser/Parser.cpp +73 -5
  14. package/cxx/parser/Parser.h +2 -0
  15. package/ios/NativePlatform+ios.swift +16 -5
  16. package/ios/NativePlatform+keyboard.swift +83 -0
  17. package/ios/NativePlatformListener+ios.swift +19 -6
  18. package/ios/UnistylesModuleOnLoad.h +3 -1
  19. package/ios/UnistylesModuleOnLoad.mm +11 -1
  20. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  21. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  22. package/lib/commonjs/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -1
  23. package/lib/commonjs/specs/ShadowRegistry/types.js +3 -0
  24. package/lib/commonjs/specs/ShadowRegistry/types.js.map +1 -1
  25. package/lib/commonjs/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -1
  26. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js +2 -4
  27. package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -1
  28. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +1 -3
  29. package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +2 -1
  30. package/lib/commonjs/specs/TurboUnistyles/index.js.map +1 -1
  31. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +2 -1
  32. package/lib/commonjs/specs/index.web.js.map +2 -1
  33. package/lib/commonjs/specs/types.js +10 -10
  34. package/lib/commonjs/specs/types.js.map +1 -1
  35. package/lib/commonjs/types/stylesheet.js.map +1 -1
  36. package/lib/commonjs/web/create.js +1 -4
  37. package/lib/commonjs/web/create.js.map +1 -1
  38. package/lib/commonjs/web/registry.js +1 -4
  39. package/lib/commonjs/web/registry.js.map +1 -1
  40. package/lib/commonjs/web/runtime.js.map +1 -1
  41. package/lib/commonjs/web/shadowRegistry.js +1 -4
  42. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  43. package/lib/commonjs/web/state.js.map +1 -1
  44. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  45. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  46. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +2 -1
  47. package/lib/module/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +1 -1
  48. package/lib/module/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -0
  49. package/lib/module/specs/ShadowRegistry/types.js +2 -0
  50. package/lib/module/specs/ShadowRegistry/types.js.map +1 -1
  51. package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -0
  52. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -1
  53. package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -0
  54. package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js +2 -3
  55. package/lib/module/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +1 -1
  56. package/lib/module/specs/index.js.map +2 -1
  57. package/lib/module/specs/index.web.js.map +2 -1
  58. package/lib/module/specs/types.js +10 -10
  59. package/lib/module/specs/types.js.map +1 -0
  60. package/lib/module/types/stylesheet.js.map +1 -1
  61. package/lib/module/web/create.js +2 -5
  62. package/lib/module/web/create.js.map +1 -1
  63. package/lib/module/web/registry.js +2 -5
  64. package/lib/module/web/registry.js.map +1 -1
  65. package/lib/module/web/runtime.js.map +1 -1
  66. package/lib/module/web/shadowRegistry.js +2 -5
  67. package/lib/module/web/shadowRegistry.js.map +1 -1
  68. package/lib/module/web/state.js.map +1 -1
  69. package/lib/module/web/utils/unistyle.js.map +1 -1
  70. package/lib/typescript/src/global.d.ts +0 -2
  71. package/lib/typescript/src/global.d.ts.map +1 -1
  72. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +4 -1
  73. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  74. package/lib/typescript/src/types/breakpoints.d.ts +11 -11
  75. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  76. package/lib/typescript/src/types/stylesheet.d.ts +4 -2
  77. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  78. package/lib/typescript/src/web/create.d.ts +204 -0
  79. package/lib/typescript/src/web/create.d.ts.map +1 -1
  80. package/lib/typescript/src/web/index.d.ts +204 -0
  81. package/lib/typescript/src/web/index.d.ts.map +1 -1
  82. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  83. package/lib/typescript/src/web/runtime.d.ts +3 -3
  84. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  85. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  86. package/lib/typescript/src/web/state.d.ts +1 -1
  87. package/lib/typescript/src/web/state.d.ts.map +1 -1
  88. package/lib/typescript/src/web/utils/unistyle.d.ts +2 -2
  89. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  90. package/nitrogen/generated/android/c++/JFunc_void.hpp +48 -0
  91. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +9 -0
  92. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +2 -0
  93. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
  94. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void.kt +45 -0
  95. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +15 -0
  96. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
  97. package/nitrogen/generated/android/unistylesOnLoad.cpp +2 -0
  98. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +29 -1
  99. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +6 -0
  100. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +2 -0
  101. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +27 -0
  102. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
  103. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +2 -0
  104. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +2 -0
  105. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
  106. package/package.json +13 -13
  107. package/plugin/common.js +9 -0
  108. package/plugin/stylesheet.js +7 -1
  109. package/src/global.ts +1 -4
  110. package/src/specs/NativePlatform/NativePlatform.nitro.js +18 -0
  111. package/src/specs/NativePlatform/NativePlatform.nitro.ts +5 -2
  112. package/src/specs/NativePlatform/index.js +1 -0
  113. package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.js +1 -0
  114. package/src/specs/NavigtionBar/index.js +9 -0
  115. package/src/specs/ShadowRegistry/ShadowRegistry.nitro.js +1 -0
  116. package/src/specs/ShadowRegistry/index.js +26 -0
  117. package/src/specs/ShadowRegistry/types.js +1 -0
  118. package/src/specs/StatusBar/UnistylesStatusBar.nitro.js +1 -0
  119. package/src/specs/StatusBar/index.js +25 -0
  120. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -0
  121. package/src/specs/StyleSheet/index.js +13 -0
  122. package/src/specs/TurboUnistyles/NativeTurboUnistyles.js +2 -0
  123. package/src/specs/TurboUnistyles/index.js +1 -0
  124. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.js +1 -0
  125. package/src/specs/UnistylesRuntime/index.js +20 -0
  126. package/src/specs/index.js +8 -0
  127. package/src/specs/index.web.js +2 -0
  128. package/src/specs/types.js +17 -0
  129. package/src/types/breakpoints.ts +25 -13
  130. package/src/types/stylesheet.ts +5 -3
  131. package/src/web/create.ts +2 -5
  132. package/src/web/registry.ts +2 -5
  133. package/src/web/runtime.ts +1 -1
  134. package/src/web/shadowRegistry.ts +2 -5
  135. package/src/web/state.ts +3 -3
  136. package/src/web/utils/unistyle.ts +2 -2
@@ -0,0 +1,17 @@
1
+ export var ColorScheme;
2
+ (function (ColorScheme) {
3
+ ColorScheme["Light"] = "light";
4
+ ColorScheme["Dark"] = "dark";
5
+ ColorScheme["Unspecified"] = "unspecified";
6
+ })(ColorScheme || (ColorScheme = {}));
7
+ export var Orientation;
8
+ (function (Orientation) {
9
+ Orientation["Portrait"] = "portrait";
10
+ Orientation["Landscape"] = "landscape";
11
+ })(Orientation || (Orientation = {}));
12
+ export var StatusBarStyle;
13
+ (function (StatusBarStyle) {
14
+ StatusBarStyle["Default"] = "default";
15
+ StatusBarStyle["Light"] = "light";
16
+ StatusBarStyle["Dark"] = "dark";
17
+ })(StatusBarStyle || (StatusBarStyle = {}));
@@ -17,45 +17,57 @@ type ExtractBreakpoints<T> = T extends object
17
17
  }
18
18
  : T
19
19
 
20
- type ParseNestedObject<T> = T extends (...args: infer A) => infer R
21
- ? (...args: A) => ParseNestedObject<R>
20
+ type ParseNestedObject<T, ShouldFlatten> = T extends (...args: infer A) => infer R
21
+ ? (...args: A) => ParseNestedObject<R, false>
22
22
  : T extends object
23
23
  ? T extends { variants: infer R, compoundVariants: infer C }
24
- ? ParseVariants<FlattenVariants<R>> & FlattenCompoundVariants<C> & ParseNestedObject<Omit<T, 'variants' | 'compoundVariants'>>
24
+ // // if intersection of Base, Variants and Compound Variants is never, then flatten variants and compound variants to generic "string"
25
+ ? (ParseVariants<FlattenVariants<R, false>> & FlattenCompoundVariants<C, false> & ParseNestedObject<Omit<T, 'variants' | 'compoundVariants'>, false>) extends never
26
+ ? ParseVariants<FlattenVariants<R, true>> & FlattenCompoundVariants<C, true> & ParseNestedObject<Omit<T, 'variants' | 'compoundVariants'>, false>
27
+ : ParseVariants<FlattenVariants<R, false>> & FlattenCompoundVariants<C, false> & ParseNestedObject<Omit<T, 'variants' | 'compoundVariants'>, false>
25
28
  : T extends { variants: infer R }
26
- ? ParseVariants<FlattenVariants<R>> & ParseNestedObject<Omit<T, 'variants'>>
29
+ // if intersection of Base and Variants is never, then flatten variants to generic "string"
30
+ ? (ParseVariants<FlattenVariants<R, false>> & ParseNestedObject<Omit<T, 'variants'>, false>) extends never
31
+ ? ParseVariants<FlattenVariants<R, true>> & ParseNestedObject<Omit<T, 'variants'>, false>
32
+ : ParseVariants<FlattenVariants<R, false>> & ParseNestedObject<Omit<T, 'variants'>, false>
27
33
  : T extends { compoundVariants: object }
28
- ? ParseNestedObject<Omit<T, 'compoundVariants'>>
34
+ ? ParseNestedObject<Omit<T, 'compoundVariants'>, false>
29
35
  : {
30
36
  [K in keyof T as K extends '_web' ? never : K]: T[K] extends object
31
37
  ? T[K] extends OpaqueColorValue
32
38
  ? ColorValue
33
39
  : ExtractBreakpoints<T[K]>
34
- : T[K]
40
+ : T[K] extends string
41
+ ? ShouldFlatten extends true
42
+ ? string
43
+ : T[K]
44
+ : T[K]
35
45
  }
36
46
  : T
37
47
 
38
- type FlattenVariants<T> = T extends object
48
+ type FlattenVariants<T, ShouldFlatten> = T extends object
39
49
  ? {
40
50
  [K in keyof T]: T[K] extends object
41
51
  ? {
42
52
  [key in keyof T[K]]: T[K][key] extends object
43
- ? ParseNestedObject<T[K][key]>
53
+ ? ParseNestedObject<T[K][key], ShouldFlatten>
44
54
  : never
45
55
  }
46
56
  : never
47
57
  }
48
58
  : never
49
59
 
50
- type FlattenCompoundVariants<T> = T extends Array<infer _>
51
- ? FlattenCompoundVariants<T[number]>
60
+ type FlattenCompoundVariants<T, ShouldFlatten> = T extends Array<infer _>
61
+ ? FlattenCompoundVariants<T[number], ShouldFlatten>
52
62
  : T extends { styles: infer S }
53
- ? ParseNestedObject<S>
63
+ ? ParseNestedObject<S, ShouldFlatten>
54
64
  : never
55
65
 
56
66
  type ParseVariants<T> = T extends object
57
67
  ? T[keyof T] extends object
58
- ? UnionToIntersection<ParseVariants<T[keyof T]>>
68
+ ? UnionToIntersection<ParseVariants<T[keyof T]>> extends never
69
+ ? ParseVariants<T[keyof T]>
70
+ : UnionToIntersection<ParseVariants<T[keyof T]>>
59
71
  : T
60
72
  : T
61
73
 
@@ -63,7 +75,7 @@ type UnionToIntersection<U> =
63
75
  (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
64
76
 
65
77
  type ParseStyleKeys<T> = T extends object
66
- ? { [K in keyof T]: ParseNestedObject<T[K]> }
78
+ ? { [K in keyof T]: ParseNestedObject<T[K], false> }
67
79
  : never
68
80
 
69
81
  export type ReactNativeStyleSheet<T> = ParseStyleKeys<SafeReturnType<T>>
@@ -1,4 +1,4 @@
1
- import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
1
+ import type { BoxShadowValue, ImageStyle, TextStyle, ViewStyle, FilterFunction } from 'react-native'
2
2
  import type { ShadowOffset, TransformStyles, UnistylesTheme } from './core'
3
3
  import type { UnistylesBreakpoints } from '../global'
4
4
  import type { UnistylesMiniRuntime } from '../specs'
@@ -8,7 +8,7 @@ import type { CSSProperties } from 'react'
8
8
  import type { Pseudo } from '../web/convert/pseudo'
9
9
 
10
10
  // these props are treated differently to nest breakpoints and media queries
11
- type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
11
+ type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset' | 'boxShadow' | 'filter'
12
12
 
13
13
  export type UnistyleView = Omit<ViewStyle, NestedKeys>
14
14
  export type UnistyleText = Omit<TextStyle, NestedKeys>
@@ -17,7 +17,9 @@ export type UnistyleImage = Omit<ImageStyle, NestedKeys>
17
17
  type UnistyleNestedStyles = {
18
18
  shadowOffset?: ToDeepUnistyles<ShadowOffset>,
19
19
  textShadowOffset?: ToDeepUnistyles<ShadowOffset>,
20
- transform?: Array<ToDeepUnistyles<TransformStyles>>
20
+ transform?: Array<ToDeepUnistyles<TransformStyles>>,
21
+ boxShadow?: Array<ToDeepUnistyles<BoxShadowValue>> | string,
22
+ filter?: Array<ToDeepUnistyles<FilterFunction>> | string
21
23
  }
22
24
 
23
25
  type VariantsObject = {
package/src/web/create.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ReactNativeStyleSheet } from '../types'
2
2
  import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
3
- import { assignSecrets, reduceObject, getStyles } from './utils'
3
+ import { assignSecrets, reduceObject, getStyles, deepMergeObjects } from './utils'
4
4
  import { UnistylesRuntime } from './runtime'
5
5
  import { createUseVariants, getVariants } from './variants'
6
6
 
@@ -26,10 +26,7 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
26
26
  const dynamicStyle = (...args: Array<any>) => {
27
27
  const result = value(...args)
28
28
  const variants = Object.fromEntries(getVariants({ [key]: result } as ReactNativeStyleSheet<StyleSheet>, copyVariants()))
29
- const resultWithVariants = {
30
- ...result,
31
- ...variants[key]
32
- }
29
+ const resultWithVariants = deepMergeObjects(result, variants[key] ?? {})
33
30
 
34
31
  // Add secrets to result of dynamic styles function
35
32
  return addSecrets(getStyles(resultWithVariants), key, args)
@@ -1,7 +1,7 @@
1
1
  import type { UnistylesTheme, UnistylesValues } from '../types'
2
2
  import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
3
3
  import { UnistylesRuntime } from './runtime'
4
- import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies } from './utils'
4
+ import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies, deepMergeObjects } from './utils'
5
5
  import { UnistylesListener } from './listener'
6
6
  import { convertUnistyles } from './convert'
7
7
  import type { UnistyleDependency } from '../specs/NativePlatform'
@@ -107,10 +107,7 @@ class UnistylesRegistryBuilder {
107
107
  ? newValue(...args)
108
108
  : newValue
109
109
  const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
110
- const resultWithVariants = {
111
- ...result,
112
- ...variantsResult
113
- }
110
+ const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
114
111
 
115
112
  this.applyStyles(hash, convertUnistyles(resultWithVariants))
116
113
  })
@@ -160,7 +160,7 @@ class UnistylesRuntimeBuilder {
160
160
  return
161
161
  }
162
162
 
163
- this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme))
163
+ this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme) as AppThemeName)
164
164
  }
165
165
 
166
166
  setRootViewBackgroundColor = (hex: string, alpha?: number) => {
@@ -1,6 +1,6 @@
1
1
  import type { UnistylesValues } from '../types'
2
2
  import { UnistylesRegistry } from './registry'
3
- import { createDoubleMap, equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils'
3
+ import { createDoubleMap, deepMergeObjects, equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils'
4
4
  import { getVariants } from './variants'
5
5
 
6
6
  type Style = UnistylesValues | ((...args: Array<any>) => UnistylesValues)
@@ -73,10 +73,7 @@ class UnistylesShadowRegistryBuilder {
73
73
  ? style(...args)
74
74
  : style
75
75
  const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
76
- const resultWithVariants = {
77
- ...result,
78
- ...variantsResult
79
- }
76
+ const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
80
77
  const oldResult = this.resultsMap.get(ref, __uni__key)
81
78
 
82
79
  // If results are the same do nothing
package/src/web/state.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { UnistylesTheme } from '../types'
2
2
  import type { UnistylesConfig } from '../specs/StyleSheet'
3
- import type { AppBreakpoint, AppThemeName } from '../specs/types'
3
+ import type { AppBreakpoint, AppTheme, AppThemeName } from '../specs/types'
4
4
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
5
5
  import { UnistylesRuntime } from './runtime'
6
6
  import { isServer, schemeToTheme } from './utils'
@@ -39,7 +39,7 @@ class UnistylesStateBuilder {
39
39
 
40
40
  private initThemes = (themes = {} as UnistylesThemes) => {
41
41
  Object.entries(themes).forEach(([themeName, theme]) => {
42
- this.themes.set(themeName, theme)
42
+ this.themes.set(themeName, theme as AppTheme)
43
43
  })
44
44
  }
45
45
 
@@ -61,7 +61,7 @@ class UnistylesStateBuilder {
61
61
 
62
62
  // Adaptive themes
63
63
  if (settings.adaptiveThemes) {
64
- this.themeName = schemeToTheme(UnistylesRuntime.colorScheme)
64
+ this.themeName = schemeToTheme(UnistylesRuntime.colorScheme) as AppThemeName
65
65
 
66
66
  return
67
67
  }
@@ -1,11 +1,11 @@
1
1
  import type { UnistyleDependency } from '../../specs/NativePlatform'
2
- import { type AppThemeName, ColorScheme, Orientation } from '../../specs/types'
2
+ import { ColorScheme, Orientation } from '../../specs/types'
3
3
  import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
4
4
  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): AppThemeName => {
8
+ export const schemeToTheme = (scheme: ColorScheme): string => {
9
9
  switch (scheme) {
10
10
  case ColorScheme.Dark:
11
11
  return 'dark'