react-native-unistyles 2.4.0-rc.2 → 2.5.0-rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. package/lib/commonjs/common.js +3 -1
  2. package/lib/commonjs/common.js.map +1 -1
  3. package/lib/commonjs/core/UnistyleRegistry.js +8 -4
  4. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
  5. package/lib/commonjs/core/Unistyles.js +7 -0
  6. package/lib/commonjs/core/Unistyles.js.map +1 -1
  7. package/lib/commonjs/core/mocks/UnistylesMockedBridge.js +32 -0
  8. package/lib/commonjs/core/mocks/UnistylesMockedBridge.js.map +1 -0
  9. package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js +46 -0
  10. package/lib/commonjs/core/mocks/UnistylesMockedRegistry.js.map +1 -0
  11. package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js +77 -0
  12. package/lib/commonjs/core/mocks/UnistylesMockedRuntime.js.map +1 -0
  13. package/lib/commonjs/core/mocks/index.js +27 -0
  14. package/lib/commonjs/core/mocks/index.js.map +1 -0
  15. package/lib/commonjs/hooks/useUnistyles.js +2 -2
  16. package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
  17. package/lib/commonjs/useStyles.js +1 -1
  18. package/lib/commonjs/useStyles.js.map +1 -1
  19. package/lib/module/common.js +2 -0
  20. package/lib/module/common.js.map +1 -1
  21. package/lib/module/core/UnistyleRegistry.js +9 -5
  22. package/lib/module/core/UnistyleRegistry.js.map +1 -1
  23. package/lib/module/core/Unistyles.js +8 -1
  24. package/lib/module/core/Unistyles.js.map +1 -1
  25. package/lib/module/core/mocks/UnistylesMockedBridge.js +25 -0
  26. package/lib/module/core/mocks/UnistylesMockedBridge.js.map +1 -0
  27. package/lib/module/core/mocks/UnistylesMockedRegistry.js +39 -0
  28. package/lib/module/core/mocks/UnistylesMockedRegistry.js.map +1 -0
  29. package/lib/module/core/mocks/UnistylesMockedRuntime.js +69 -0
  30. package/lib/module/core/mocks/UnistylesMockedRuntime.js.map +1 -0
  31. package/lib/module/core/mocks/index.js +4 -0
  32. package/lib/module/core/mocks/index.js.map +1 -0
  33. package/lib/module/hooks/useUnistyles.js +2 -2
  34. package/lib/module/hooks/useUnistyles.js.map +1 -1
  35. package/lib/module/useStyles.js +1 -1
  36. package/lib/module/useStyles.js.map +1 -1
  37. package/lib/typescript/src/common.d.ts +2 -0
  38. package/lib/typescript/src/common.d.ts.map +1 -1
  39. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
  40. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -1
  41. package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts +24 -0
  42. package/lib/typescript/src/core/mocks/UnistylesMockedBridge.d.ts.map +1 -0
  43. package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts +21 -0
  44. package/lib/typescript/src/core/mocks/UnistylesMockedRegistry.d.ts.map +1 -0
  45. package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts +41 -0
  46. package/lib/typescript/src/core/mocks/UnistylesMockedRuntime.d.ts.map +1 -0
  47. package/lib/typescript/src/core/mocks/index.d.ts +4 -0
  48. package/lib/typescript/src/core/mocks/index.d.ts.map +1 -0
  49. package/lib/typescript/src/hooks/useUnistyles.d.ts +1 -1
  50. package/lib/typescript/src/types/breakpoints.d.ts +2 -1
  51. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  52. package/lib/typescript/src/types/stylesheet.d.ts +2 -1
  53. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/src/common.ts +2 -0
  56. package/src/core/UnistyleRegistry.ts +11 -5
  57. package/src/core/Unistyles.ts +10 -1
  58. package/src/core/mocks/UnistylesMockedBridge.ts +26 -0
  59. package/src/core/mocks/UnistylesMockedRegistry.ts +47 -0
  60. package/src/core/mocks/UnistylesMockedRuntime.ts +92 -0
  61. package/src/core/mocks/index.ts +3 -0
  62. package/src/hooks/useUnistyles.ts +2 -2
  63. package/src/types/breakpoints.ts +2 -1
  64. package/src/types/stylesheet.ts +2 -1
  65. package/src/useStyles.ts +1 -1
  66. package/windows/ReactNativeUnistyles/ReactNativeUnistyles.h +33 -27
@@ -2,6 +2,7 @@ import type { ColorValue, OpaqueColorValue } from 'react-native'
2
2
  import type { UnistylesTheme } from '../types'
3
3
  import type { BreakpointsOrMediaQueries, ToDeepUnistyles } from './stylesheet'
4
4
  import type { TransformStyles } from './core'
5
+ import type { UnistylesRuntime } from '../core'
5
6
 
6
7
  type ExtractTransformArray<T> = T extends object
7
8
  ? { [K in keyof T]: ExtractBreakpoints<T[K]> }
@@ -56,6 +57,6 @@ type ParseStyleKeys<T> = T extends object
56
57
  ? { [K in keyof T]: ParseNestedObject<T[K]> }
57
58
  : never
58
59
 
59
- export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme) => infer R
60
+ export type ReactNativeStyleSheet<T> = T extends (theme: UnistylesTheme, runtime: UnistylesRuntime) => infer R
60
61
  ? ParseStyleKeys<R>
61
62
  : ParseStyleKeys<T>
@@ -1,6 +1,7 @@
1
1
  import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
2
2
  import type { ShadowOffset, TransformStyles, UnistylesTheme } from './core'
3
3
  import type { UnistylesBreakpoints } from '../global'
4
+ import type { UnistylesRuntime } from '../core'
4
5
 
5
6
  // these props are treated differently to nest breakpoints and media queries
6
7
  type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
@@ -46,4 +47,4 @@ export type StyleSheet = {
46
47
  [styleName: string]: UnistylesValues | ((...args: any) => UnistylesValues)
47
48
  }
48
49
 
49
- export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme) => StyleSheet) | StyleSheet
50
+ export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme, runtime: UnistylesRuntime) => StyleSheet) | StyleSheet
package/src/useStyles.ts CHANGED
@@ -26,7 +26,7 @@ export const useStyles = <ST extends StyleSheetWithSuperPowers>(
26
26
  const { theme, layout, plugins } = useUnistyles()
27
27
  const variants = useVariants(variantsMap)
28
28
  const parsedStyles = useMemo(() => typeof stylesheet === 'function'
29
- ? stylesheet(theme)
29
+ ? stylesheet(theme, unistyles.runtime)
30
30
  : stylesheet, [theme, stylesheet, layout])
31
31
 
32
32
  const dynamicStyleSheet = useMemo(() => Object
@@ -18,8 +18,7 @@ using namespace winrt::Windows::UI::Core;
18
18
  using namespace facebook;
19
19
 
20
20
  struct UIInitialInfo {
21
- int screenWidth;
22
- int screenHeight;
21
+ Dimensions screen;
23
22
  std::string colorScheme;
24
23
  std::string contentSizeCategory;
25
24
  };
@@ -39,7 +38,9 @@ struct Unistyles {
39
38
  auto bounds = Window::Current().Bounds();
40
39
 
41
40
  if (this->unistylesRuntime != nullptr) {
42
- ((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange((int)bounds.Width, (int)bounds.Height, this->getInsets(), this->getStatusBarDimensions());
41
+ Dimensions screenDimensions = Dimensions{(int)bounds.Width, (int)bounds.Height};
42
+
43
+ ((UnistylesRuntime*)this->unistylesRuntime)->handleScreenSizeChange(screenDimensions, this->getInsets(), this->getStatusBarDimensions(), this->getNavigationBarDimensions());
43
44
  }
44
45
  }));
45
46
 
@@ -80,8 +81,7 @@ struct Unistyles {
80
81
  UIInitialInfo uiMetadata;
81
82
  auto bounds = Window::Current().Bounds();
82
83
 
83
- uiMetadata.screenWidth = bounds.Width;
84
- uiMetadata.screenHeight = bounds.Height;
84
+ uiMetadata.screen = Dimensions{(int)bounds.Width, (int)bounds.Height};
85
85
  uiMetadata.colorScheme = this->getColorScheme();
86
86
  uiMetadata.contentSizeCategory = UnistylesUnspecifiedScheme;
87
87
 
@@ -91,12 +91,12 @@ struct Unistyles {
91
91
  UIInitialInfo uiInfo = uiInfoFuture.get();
92
92
 
93
93
  auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
94
- uiInfo.screenWidth,
95
- uiInfo.screenHeight,
94
+ uiInfo.screen,
96
95
  uiInfo.colorScheme,
97
96
  uiInfo.contentSizeCategory,
98
97
  this->getInsets(),
99
- this->getStatusBarDimensions()
98
+ this->getStatusBarDimensions(),
99
+ this->getNavigationBarDimensions()
100
100
  );
101
101
 
102
102
  unistylesRuntime->onThemeChange([this](std::string theme) {
@@ -110,16 +110,30 @@ struct Unistyles {
110
110
  this->OnThemeChange(payload);
111
111
  });
112
112
 
113
- unistylesRuntime.get()->onLayoutChange([this](std::string breakpoint, std::string orientation, int width, int height) {
113
+ unistylesRuntime.get()->onLayoutChange([this](std::string breakpoint, std::string orientation, Dimensions& screen, Dimensions& statusBar, Insets& insets, Dimensions& navigationBar) {
114
114
  auto payload = winrt::Microsoft::ReactNative::JSValueObject{
115
115
  {"type", "layout"},
116
116
  {"payload", winrt::Microsoft::ReactNative::JSValueObject{
117
117
  {"breakpoint", breakpoint},
118
118
  {"orientation", orientation},
119
119
  {"screen", winrt::Microsoft::ReactNative::JSValueObject{
120
- {"width", width},
121
- {"height", height}
122
- }}
120
+ {"width", screen.width},
121
+ {"height", screen.height}
122
+ }},
123
+ {"statusBar", winrt::Microsoft::ReactNative::JSValueObject{
124
+ {"width", statusBar.width},
125
+ {"height", statusBar.height}
126
+ }},
127
+ {"navigationBar", winrt::Microsoft::ReactNative::JSValueObject{
128
+ {"width", navigationBar.width},
129
+ {"height", navigationBar.height}
130
+ }},
131
+ {"insets", winrt::Microsoft::ReactNative::JSValueObject{
132
+ {"top", insets.top},
133
+ {"bottom", insets.bottom},
134
+ {"left", insets.left},
135
+ {"right", insets.right}
136
+ }},
123
137
  }}
124
138
  };
125
139
 
@@ -195,24 +209,16 @@ struct Unistyles {
195
209
  return UnistylesUnspecifiedScheme;
196
210
  }
197
211
 
198
- std::map<std::string, int>getInsets() {
199
- std::map<std::string, int> insets;
200
-
201
- insets.insert({ "top", 0 });
202
- insets.insert({ "bottom", 0 });
203
- insets.insert({ "left", 0 });
204
- insets.insert({ "right", 0 });
205
-
206
- return insets;
212
+ Insets getInsets() {
213
+ return Insets{ 0, 0, 0, 0 };
207
214
  }
208
215
 
209
- std::map<std::string, int>getStatusBarDimensions() {
210
- std::map<std::string, int> statusBar;
211
-
212
- statusBar.insert({ "height", 0 });
213
- statusBar.insert({ "width", 0 });
216
+ Dimensions getStatusBarDimensions() {
217
+ return {0, 0};
218
+ }
214
219
 
215
- return statusBar;
220
+ Dimensions getNavigationBarDimensions() {
221
+ return { 0, 0 };
216
222
  }
217
223
  };
218
224