react-native-unistyles 3.0.0-alpha.23 → 3.0.0-alpha.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. package/cxx/common/Helpers.h +10 -0
  2. package/cxx/core/UnistylesState.cpp +13 -1
  3. package/cxx/core/UnistylesState.h +2 -1
  4. package/cxx/hybridObjects/HybridStyleSheet.cpp +38 -5
  5. package/cxx/hybridObjects/HybridStyleSheet.h +3 -0
  6. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +23 -3
  7. package/cxx/hybridObjects/HybridUnistylesRuntime.h +5 -0
  8. package/cxx/parser/Parser.cpp +1 -1
  9. package/ios/Equatable.swift +2 -1
  10. package/ios/NativePlatform+ios.swift +6 -1
  11. package/ios/NativePlatformListener+ios.swift +19 -19
  12. package/lib/commonjs/core/index.js +20 -0
  13. package/lib/commonjs/core/index.js.map +1 -0
  14. package/lib/commonjs/core/useBreakpoint.js +22 -0
  15. package/lib/commonjs/core/useBreakpoint.js.map +1 -0
  16. package/lib/commonjs/core/useBreakpoint.native.js +24 -0
  17. package/lib/commonjs/core/useBreakpoint.native.js.map +1 -0
  18. package/lib/commonjs/core/useTheme.js +22 -0
  19. package/lib/commonjs/core/useTheme.js.map +1 -0
  20. package/lib/commonjs/core/useTheme.native.js +24 -0
  21. package/lib/commonjs/core/useTheme.native.js.map +1 -0
  22. package/lib/commonjs/index.js +16 -1
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  25. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
  26. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  27. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  28. package/lib/commonjs/specs/index.js +7 -0
  29. package/lib/commonjs/specs/index.js.map +1 -1
  30. package/lib/commonjs/web/runtime.js +13 -9
  31. package/lib/commonjs/web/runtime.js.map +1 -1
  32. package/lib/module/core/index.js +5 -0
  33. package/lib/module/core/index.js.map +1 -0
  34. package/lib/module/core/useBreakpoint.js +17 -0
  35. package/lib/module/core/useBreakpoint.js.map +1 -0
  36. package/lib/module/core/useBreakpoint.native.js +19 -0
  37. package/lib/module/core/useBreakpoint.native.js.map +1 -0
  38. package/lib/module/core/useTheme.js +17 -0
  39. package/lib/module/core/useTheme.js.map +1 -0
  40. package/lib/module/core/useTheme.native.js +19 -0
  41. package/lib/module/core/useTheme.native.js.map +1 -0
  42. package/lib/module/index.js +1 -0
  43. package/lib/module/index.js.map +1 -1
  44. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  45. package/lib/module/specs/NavigtionBar/index.js.map +1 -1
  46. package/lib/module/specs/StatusBar/index.js.map +1 -1
  47. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  48. package/lib/module/specs/index.js +2 -1
  49. package/lib/module/specs/index.js.map +1 -1
  50. package/lib/module/web/runtime.js +13 -9
  51. package/lib/module/web/runtime.js.map +1 -1
  52. package/lib/typescript/example/App.d.ts.map +1 -1
  53. package/lib/typescript/example/Typography.d.ts +28 -5
  54. package/lib/typescript/example/Typography.d.ts.map +1 -1
  55. package/lib/typescript/src/core/index.d.ts +3 -0
  56. package/lib/typescript/src/core/index.d.ts.map +1 -0
  57. package/lib/typescript/src/core/useBreakpoint.d.ts +2 -0
  58. package/lib/typescript/src/core/useBreakpoint.d.ts.map +1 -0
  59. package/lib/typescript/src/core/useBreakpoint.native.d.ts +2 -0
  60. package/lib/typescript/src/core/useBreakpoint.native.d.ts.map +1 -0
  61. package/lib/typescript/src/core/useTheme.d.ts +41 -0
  62. package/lib/typescript/src/core/useTheme.d.ts.map +1 -0
  63. package/lib/typescript/src/core/useTheme.native.d.ts +41 -0
  64. package/lib/typescript/src/core/useTheme.native.d.ts.map +1 -0
  65. package/lib/typescript/src/index.d.ts +2 -0
  66. package/lib/typescript/src/index.d.ts.map +1 -1
  67. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
  68. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  69. package/lib/typescript/src/specs/NavigtionBar/index.d.ts +5 -0
  70. package/lib/typescript/src/specs/NavigtionBar/index.d.ts.map +1 -1
  71. package/lib/typescript/src/specs/StatusBar/index.d.ts +5 -0
  72. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  73. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +2 -0
  74. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
  75. package/lib/typescript/src/specs/StyleSheet/index.d.ts +1 -1
  76. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  77. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +0 -1
  78. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  79. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +3 -1
  80. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  81. package/lib/typescript/src/specs/index.d.ts +4 -2
  82. package/lib/typescript/src/specs/index.d.ts.map +1 -1
  83. package/lib/typescript/src/types/index.d.ts +1 -1
  84. package/lib/typescript/src/types/index.d.ts.map +1 -1
  85. package/lib/typescript/src/types/variants.d.ts +3 -0
  86. package/lib/typescript/src/types/variants.d.ts.map +1 -1
  87. package/lib/typescript/src/web/runtime.d.ts +1 -0
  88. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  89. package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +8 -6
  90. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +2 -1
  91. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +2 -2
  92. package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +16 -5
  93. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -0
  94. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +6 -3
  95. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +10 -9
  96. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +9 -8
  97. package/package.json +1 -1
  98. package/plugin/common.js +3 -1
  99. package/plugin/stylesheet.js +2 -1
  100. package/src/core/index.ts +2 -0
  101. package/src/core/useBreakpoint.native.ts +21 -0
  102. package/src/core/useBreakpoint.ts +18 -0
  103. package/src/core/useTheme.native.ts +21 -0
  104. package/src/core/useTheme.ts +18 -0
  105. package/src/index.ts +3 -0
  106. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
  107. package/src/specs/NavigtionBar/index.ts +5 -0
  108. package/src/specs/StatusBar/index.ts +5 -0
  109. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +3 -0
  110. package/src/specs/StyleSheet/index.ts +1 -1
  111. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +0 -1
  112. package/src/specs/UnistylesRuntime/index.ts +3 -1
  113. package/src/specs/index.ts +6 -2
  114. package/src/types/index.ts +1 -1
  115. package/src/types/variants.ts +6 -0
  116. package/src/web/runtime.ts +17 -12
@@ -90,6 +90,16 @@ inline bool isPlatformColor(jsi::Runtime& rt, jsi::Object& maybePlatformColor) {
90
90
  return true;
91
91
  }
92
92
 
93
+ auto isIOSDynamicColor =
94
+ maybePlatformColor.hasProperty(rt, "dynamic") &&
95
+ maybePlatformColor.getProperty(rt, "dynamic").isObject() &&
96
+ maybePlatformColor.getProperty(rt, "dynamic").asObject(rt).hasProperty(rt, "dark") &&
97
+ maybePlatformColor.getProperty(rt, "dynamic").asObject(rt).hasProperty(rt, "light");
98
+
99
+ if (isIOSDynamicColor) {
100
+ return true;
101
+ }
102
+
93
103
  // Android
94
104
  return maybePlatformColor.hasProperty(rt, "resource_paths") && maybePlatformColor.getProperty(rt, "resource_paths").isObject();
95
105
  }
@@ -23,7 +23,7 @@ std::optional<std::string>& core::UnistylesState::getCurrentThemeName() {
23
23
  return this->_currentThemeName;
24
24
  }
25
25
 
26
- jsi::Object core::UnistylesState::getJSTheme() {
26
+ jsi::Object core::UnistylesState::getCurrentJSTheme() {
27
27
  auto hasSomeThemes = _registeredThemeNames.size() > 0;
28
28
 
29
29
  // return empty object, if user didn't register any themes
@@ -44,6 +44,18 @@ jsi::Object core::UnistylesState::getJSTheme() {
44
44
  return maybeTheme.asObject(*_rt);
45
45
  }
46
46
 
47
+ jsi::Object core::UnistylesState::getJSThemeByName(std::string& themeName) {
48
+ auto it = this->_jsThemes.find(themeName);
49
+
50
+ helpers::assertThat(*_rt, it != this->_jsThemes.end(), "Unistyles: You're trying to get theme '" + themeName + "', but it was not registered. Did you forget to register it with StyleSheet.configure?");
51
+
52
+ auto maybeTheme = it->second.lock(*_rt);
53
+
54
+ helpers::assertThat(*_rt, maybeTheme.isObject(), "Unistyles: Unable to retrieve your theme from C++ as it has already been garbage collected, likely due to multiple hot reloads. Please live reload the app.");
55
+
56
+ return maybeTheme.asObject(*_rt);
57
+ }
58
+
47
59
  void core::UnistylesState::computeCurrentBreakpoint(int screenWidth) {
48
60
  this->_currentBreakpointName = helpers::getBreakpointFromScreenWidth(
49
61
  screenWidth,
@@ -28,7 +28,8 @@ struct UnistylesState {
28
28
  std::optional<std::string> getCurrentBreakpointName();
29
29
  std::vector<std::pair<std::string, double>> getSortedBreakpointPairs();
30
30
 
31
- jsi::Object getJSTheme();
31
+ jsi::Object getCurrentJSTheme();
32
+ jsi::Object getJSThemeByName(std::string& themeName);
32
33
  int parseColor(jsi::Value& color);
33
34
  void computeCurrentBreakpoint(int screenWidth);
34
35
  void registerProcessColorFunction(jsi::Function&& fn);
@@ -216,15 +216,27 @@ void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Run
216
216
  state.registerProcessColorFunction(std::move(processColorFn));
217
217
  }
218
218
 
219
+ void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
220
+ this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager, this->_unistylesRuntime, rt);
221
+ this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime, rt);
222
+ }
223
+
219
224
  void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies) {
220
225
  auto& registry = core::UnistylesRegistry::get();
221
226
  auto parser = parser::Parser(this->_unistylesRuntime);
222
227
  auto& rt = this->_unistylesRuntime->getRuntime();
228
+
229
+ // re-compute new breakpoint
230
+ auto dimensionsIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::DIMENSIONS);
231
+
232
+ if (dimensionsIt != dependencies.end()) {
233
+ registry.getState(rt).computeCurrentBreakpoint(this->_unistylesRuntime->getScreen().width);
234
+ }
223
235
 
224
236
  // check if color scheme changed and then if Unistyles state depend on it (adaptive themes)
225
237
  auto colorSchemeIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::COLORSCHEME);
226
238
  auto hasNewColorScheme = colorSchemeIt != dependencies.end();
227
-
239
+
228
240
  // in a later step, we will rebuild only Unistyles with mounted StyleSheets
229
241
  // however, user may have StyleSheets with components that haven't mounted yet
230
242
  // we need to rebuild all dependent StyleSheets as well
@@ -233,7 +245,9 @@ void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependen
233
245
  if (hasNewColorScheme) {
234
246
  this->_unistylesRuntime->includeDependenciesForColorSchemeChange(dependencies);
235
247
  }
236
-
248
+
249
+ this->notifyJSListeners(dependencies);
250
+
237
251
  auto dependencyMap = registry.buildDependencyMap(rt, dependencies);
238
252
 
239
253
  if (dependencyMap.size() == 0) {
@@ -250,7 +264,26 @@ void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependen
250
264
  shadow::ShadowTreeManager::updateShadowTree(rt, shadowLeafUpdates);
251
265
  }
252
266
 
253
- void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
254
- this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager, this->_unistylesRuntime, rt);
255
- this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime, rt);
267
+ void HybridStyleSheet::notifyJSListeners(std::vector<UnistyleDependency>& dependencies) {
268
+ if (dependencies.size() > 0) {
269
+ std::for_each(this->_changeListeners.begin(), this->_changeListeners.end(), [&](auto& listener){
270
+ (*listener)(dependencies);
271
+ });
272
+ }
273
+ }
274
+
275
+ std::function<void ()> HybridStyleSheet::addChangeListener(const std::function<void (const std::vector<UnistyleDependency>&)>& onChanged) {
276
+ auto listener = std::make_unique<std::function<void(std::vector<UnistyleDependency>&)>>(onChanged);
277
+
278
+ this->_changeListeners.push_back(std::move(listener));
279
+
280
+ return [this, listenerPtr = this->_changeListeners.back().get()](){
281
+ auto it = std::find_if(this->_changeListeners.begin(), this->_changeListeners.end(), [listenerPtr](auto& ptr) {
282
+ return ptr.get() == listenerPtr;
283
+ });
284
+
285
+ if (it != this->_changeListeners.end()) {
286
+ this->_changeListeners.erase(it);
287
+ }
288
+ };
256
289
  }
@@ -44,6 +44,7 @@ struct HybridStyleSheet: public HybridUnistylesStyleSheetSpec {
44
44
 
45
45
  double getHairlineWidth() override;
46
46
  double getUnid() override;
47
+ std::function<void ()> addChangeListener(const std::function<void (const std::vector<UnistyleDependency> &)>& onChanged) override;
47
48
 
48
49
  private:
49
50
  void parseSettings(jsi::Runtime& rt, jsi::Object settings);
@@ -54,8 +55,10 @@ private:
54
55
  void loadExternalMethods(const jsi::Value& thisValue, jsi::Runtime& rt);
55
56
  void registerHooks(jsi::Runtime& rt);
56
57
  void onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies);
58
+ void notifyJSListeners(std::vector<UnistyleDependency>& dependencies);
57
59
 
58
60
  double __unid = -1;
61
+ std::vector<std::unique_ptr<const std::function<void(std::vector<UnistyleDependency>&)>>> _changeListeners{};
59
62
  std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
60
63
  std::shared_ptr<core::UnistylesCommitHook> _unistylesCommitHook;
61
64
  std::shared_ptr<core::UnistylesMountHook> _unistylesMountHook;
@@ -112,6 +112,24 @@ void HybridUnistylesRuntime::calculateNewThemeAndDependencies(std::vector<Unisty
112
112
  }
113
113
  }
114
114
 
115
+ jsi::Value HybridUnistylesRuntime::getTheme(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
116
+ helpers::assertThat(rt, count <= 1, "UnistylesRuntime.getTheme expected to be called with 0 or 1 argument.");
117
+
118
+ auto& state = core::UnistylesRegistry::get().getState(*_rt);
119
+
120
+ if (count == 1) {
121
+ helpers::assertThat(rt, args[0].isString(), "UnistylesRuntime.getTheme expected to be called with string.");
122
+
123
+ auto themeName = args[0].asString(rt).utf8(rt);
124
+
125
+ helpers::assertThat(rt, state.hasTheme(themeName), "Unistyles: You're trying to get theme '" + themeName + "' but it wasn't registered.");
126
+
127
+ return state.getJSThemeByName(themeName);
128
+ }
129
+
130
+ return state.getCurrentJSTheme();
131
+ }
132
+
115
133
  jsi::Value HybridUnistylesRuntime::updateTheme(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
116
134
  helpers::assertThat(rt, count == 2, "UnistylesRuntime.updateTheme expected to be called with 2 arguments.");
117
135
  helpers::assertThat(rt, args[0].isString(), "UnistylesRuntime.updateTheme expected first argument to be a string.");
@@ -158,7 +176,6 @@ UnistylesCxxMiniRuntime HybridUnistylesRuntime::getMiniRuntime() {
158
176
  UnistylesCxxMiniRuntime cxxMiniRuntime{
159
177
  this->getThemeName(),
160
178
  this->getBreakpoint(),
161
- nativeMiniRuntime.orientation,
162
179
  this->getHasAdaptiveThemes(),
163
180
  nativeMiniRuntime.colorScheme,
164
181
  nativeMiniRuntime.screen,
@@ -168,7 +185,9 @@ UnistylesCxxMiniRuntime HybridUnistylesRuntime::getMiniRuntime() {
168
185
  nativeMiniRuntime.fontScale,
169
186
  nativeMiniRuntime.rtl,
170
187
  nativeMiniRuntime.statusBar,
171
- nativeMiniRuntime.navigationBar
188
+ nativeMiniRuntime.navigationBar,
189
+ nativeMiniRuntime.isPortrait,
190
+ nativeMiniRuntime.isLandscape
172
191
  };
173
192
 
174
193
  return cxxMiniRuntime;
@@ -181,7 +200,6 @@ jsi::Value HybridUnistylesRuntime::getMiniRuntimeAsValue(jsi::Runtime& rt) {
181
200
  // auto generated by nitro, but can't be accessed due to static inline function
182
201
  obj.setProperty(rt, "themeName", JSIConverter<std::optional<std::string>>::toJSI(rt, miniRuntime.themeName));
183
202
  obj.setProperty(rt, "breakpoint", JSIConverter<std::optional<std::string>>::toJSI(rt, miniRuntime.breakpoint));
184
- obj.setProperty(rt, "orientation", JSIConverter<Orientation>::toJSI(rt, miniRuntime.orientation));
185
203
  obj.setProperty(rt, "hasAdaptiveThemes", JSIConverter<bool>::toJSI(rt, miniRuntime.hasAdaptiveThemes));
186
204
  obj.setProperty(rt, "colorScheme", JSIConverter<ColorScheme>::toJSI(rt, miniRuntime.colorScheme));
187
205
  obj.setProperty(rt, "screen", JSIConverter<Dimensions>::toJSI(rt, miniRuntime.screen));
@@ -192,6 +210,8 @@ jsi::Value HybridUnistylesRuntime::getMiniRuntimeAsValue(jsi::Runtime& rt) {
192
210
  obj.setProperty(rt, "rtl", JSIConverter<bool>::toJSI(rt, miniRuntime.rtl));
193
211
  obj.setProperty(rt, "statusBar", JSIConverter<Dimensions>::toJSI(rt, miniRuntime.statusBar));
194
212
  obj.setProperty(rt, "navigationBar", JSIConverter<Dimensions>::toJSI(rt, miniRuntime.navigationBar));
213
+ obj.setProperty(rt, "isPortrait", JSIConverter<bool>::toJSI(rt, miniRuntime.isPortrait));
214
+ obj.setProperty(rt, "isLandscape", JSIConverter<bool>::toJSI(rt, miniRuntime.isLandscape));
195
215
 
196
216
  return obj;
197
217
  }
@@ -15,6 +15,10 @@ namespace margelo::nitro::unistyles {
15
15
  struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
16
16
  HybridUnistylesRuntime(Unistyles::HybridNativePlatformSpecCxx nativePlatform, jsi::Runtime& rt) : HybridObject(TAG), _nativePlatform{nativePlatform}, _rt{&rt} {}
17
17
 
18
+ jsi::Value getTheme(jsi::Runtime& rt,
19
+ const jsi::Value& thisValue,
20
+ const jsi::Value* args,
21
+ size_t count);
18
22
  jsi::Value updateTheme(jsi::Runtime& rt,
19
23
  const jsi::Value& thisValue,
20
24
  const jsi::Value* args,
@@ -32,6 +36,7 @@ struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
32
36
  HybridUnistylesRuntimeSpec::loadHybridMethods();
33
37
 
34
38
  registerHybrids(this, [](Prototype& prototype) {
39
+ prototype.registerRawHybridMethod("getTheme", 1, &HybridUnistylesRuntime::getTheme);
35
40
  prototype.registerRawHybridMethod("updateTheme", 1, &HybridUnistylesRuntime::updateTheme);
36
41
  prototype.registerRawHybridMethod("createHybridStatusBar", 0, &HybridUnistylesRuntime::createHybridStatusBar);
37
42
  prototype.registerRawHybridMethod("createHybridNavigationBar", 0, &HybridUnistylesRuntime::createHybridNavigationBar);
@@ -47,7 +47,7 @@ jsi::Object parser::Parser::unwrapStyleSheet(jsi::Runtime& rt, std::shared_ptr<S
47
47
 
48
48
  // StyleSheet is a function
49
49
  auto& state = core::UnistylesRegistry::get().getState(rt);
50
- auto theme = state.getJSTheme();
50
+ auto theme = state.getCurrentJSTheme();
51
51
 
52
52
  if (styleSheet->type == StyleSheetType::Themable) {
53
53
  return styleSheet->rawValue
@@ -36,7 +36,8 @@ extension UnistylesNativeMiniRuntime {
36
36
  dependencies.append(UnistyleDependency.breakpoints)
37
37
  }
38
38
 
39
- if (lhs.orientation != rhs.orientation) {
39
+ // no need to check isLandscape, as it's always opposite
40
+ if (lhs.isPortrait != rhs.isPortrait) {
40
41
  dependencies.append(UnistyleDependency.orientation)
41
42
  }
42
43
 
@@ -1,12 +1,14 @@
1
1
  #if os(iOS)
2
2
 
3
3
  import Foundation
4
+ import Combine
4
5
  import NitroModules
5
6
 
6
7
  typealias CxxListener = (Array<UnistyleDependency>) -> Void
7
8
 
8
9
  class NativeIOSPlatform: HybridNativePlatformSpec {
9
10
  var miniRuntime: UnistylesNativeMiniRuntime?
11
+ var cancellables = Set<AnyCancellable>()
10
12
 
11
13
  var listeners: Array<CxxListener> = []
12
14
  var hybridContext = margelo.nitro.HybridContext()
@@ -29,6 +31,8 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
29
31
  }
30
32
 
31
33
  func buildMiniRuntime() -> UnistylesNativeMiniRuntime {
34
+ let orientation = self.getOrientation()
35
+
32
36
  return UnistylesNativeMiniRuntime(
33
37
  colorScheme: self.getColorScheme(),
34
38
  screen: self.getScreenDimensions(),
@@ -39,7 +43,8 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
39
43
  rtl: self.getPrefersRtlDirection(),
40
44
  statusBar: self.getStatusBarDimensions(),
41
45
  navigationBar: self.getNavigationBarDimensions(),
42
- orientation: self.getOrientation()
46
+ isPortrait: orientation == .portrait,
47
+ isLandscape: orientation == .landscape
43
48
  )
44
49
  }
45
50
 
@@ -2,16 +2,18 @@ import Foundation
2
2
 
3
3
  extension NativeIOSPlatform {
4
4
  func setupPlatformListeners() {
5
- NotificationCenter.default.addObserver(
6
- self,
7
- selector: #selector(onWindowChange(_:)),
8
- name: NSNotification.Name("RCTWindowFrameDidChangeNotification"),
9
- object: nil
10
- )
5
+ NotificationCenter.default.publisher(for: NSNotification.Name("RCTWindowFrameDidChangeNotification"))
6
+ // add small delay (10ms) to make sure all values are up ot date
7
+ // we MUST call it on current thread, otherwise random crashes occurs
8
+ .delay(for: .milliseconds(10), scheduler: RunLoop.current)
9
+ .sink { [weak self] notification in
10
+ self?.onWindowChange(notification)
11
+ }
12
+ .store(in: &cancellables)
11
13
  }
12
14
 
13
15
  func removePlatformListeners() {
14
- NotificationCenter.default.removeObserver(self, name: NSNotification.Name("RCTWindowFrameDidChangeNotification"), object: nil)
16
+ cancellables.removeAll()
15
17
  }
16
18
 
17
19
  func registerPlatformListener(callback: @escaping (CxxListener)) throws {
@@ -24,18 +26,16 @@ extension NativeIOSPlatform {
24
26
 
25
27
  @objc func onWindowChange(_ notification: Notification) {
26
28
  // add small delay (10ms) to make sure all values are up ot date
27
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
28
- guard let currentMiniRuntime = self.miniRuntime else {
29
- return
30
- }
31
-
32
- let newMiniRuntime = self.buildMiniRuntime()
33
- let changedDependencies = UnistylesNativeMiniRuntime.diff(lhs: currentMiniRuntime, rhs: newMiniRuntime)
34
-
35
- if (changedDependencies.count > 0) {
36
- self.miniRuntime = newMiniRuntime
37
- self.emitCxxEvent(dependencies: changedDependencies)
38
- }
29
+ guard let currentMiniRuntime = self.miniRuntime else {
30
+ return
31
+ }
32
+
33
+ let newMiniRuntime = self.buildMiniRuntime()
34
+ let changedDependencies = UnistylesNativeMiniRuntime.diff(lhs: currentMiniRuntime, rhs: newMiniRuntime)
35
+
36
+ if (changedDependencies.count > 0) {
37
+ self.miniRuntime = newMiniRuntime
38
+ self.emitCxxEvent(dependencies: changedDependencies)
39
39
  }
40
40
  }
41
41
  }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useBreakpoint", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _useBreakpoint.useBreakpoint;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "useTheme", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _useTheme.useTheme;
16
+ }
17
+ });
18
+ var _useBreakpoint = require("./useBreakpoint");
19
+ var _useTheme = require("./useTheme");
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_useBreakpoint","require","_useTheme"],"sourceRoot":"../../../src","sources":["core/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useBreakpoint = void 0;
7
+ var _react = require("react");
8
+ var _web = require("../web");
9
+ var _listener = require("../web/listener");
10
+ var _NativePlatform = require("../specs/NativePlatform");
11
+ const useBreakpoint = () => {
12
+ const [breakpoint, setBreakpoint] = (0, _react.useState)(_web.UnistylesRuntime.breakpoint);
13
+ (0, _react.useEffect)(() => {
14
+ const removeChangeListener = _listener.UnistylesListener.addListeners([_NativePlatform.UnistyleDependency.Breakpoints], () => setBreakpoint(_web.UnistylesRuntime.breakpoint));
15
+ return () => {
16
+ removeChangeListener();
17
+ };
18
+ }, []);
19
+ return breakpoint;
20
+ };
21
+ exports.useBreakpoint = useBreakpoint;
22
+ //# sourceMappingURL=useBreakpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_web","_listener","_NativePlatform","useBreakpoint","breakpoint","setBreakpoint","useState","UnistylesRuntime","useEffect","removeChangeListener","UnistylesListener","addListeners","UnistyleDependency","Breakpoints","exports"],"sourceRoot":"../../../src","sources":["core/useBreakpoint.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAEO,MAAMI,aAAa,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAACC,qBAAgB,CAACH,UAAU,CAAC;EAEzE,IAAAI,gBAAS,EAAC,MAAM;IACZ,MAAMC,oBAAoB,GAAGC,2BAAiB,CAACC,YAAY,CAAC,CAACC,kCAAkB,CAACC,WAAW,CAAC,EAAE,MAAMR,aAAa,CAACE,qBAAgB,CAACH,UAAU,CAAC,CAAC;IAE/I,OAAO,MAAM;MACTK,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOL,UAAU;AACrB,CAAC;AAAAU,OAAA,CAAAX,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useBreakpoint = void 0;
7
+ var _react = require("react");
8
+ var _specs = require("../specs");
9
+ const useBreakpoint = () => {
10
+ const [breakpoint, setBreakpoint] = (0, _react.useState)(_specs.UnistylesRuntime.breakpoint);
11
+ (0, _react.useEffect)(() => {
12
+ const removeChangeListener = _specs.StyleSheet.addChangeListener(dependencies => {
13
+ if (dependencies.includes(_specs.UnistyleDependency.Breakpoints)) {
14
+ setBreakpoint(_specs.UnistylesRuntime.breakpoint);
15
+ }
16
+ });
17
+ return () => {
18
+ removeChangeListener();
19
+ };
20
+ }, []);
21
+ return breakpoint;
22
+ };
23
+ exports.useBreakpoint = useBreakpoint;
24
+ //# sourceMappingURL=useBreakpoint.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_specs","useBreakpoint","breakpoint","setBreakpoint","useState","UnistylesRuntime","useEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","includes","UnistyleDependency","Breakpoints","exports"],"sourceRoot":"../../../src","sources":["core/useBreakpoint.native.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAGO,MAAME,aAAa,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAACC,uBAAgB,CAACH,UAAU,CAAC;EAEzE,IAAAI,gBAAS,EAAC,MAAM;IACZ,MAAMC,oBAAoB,GAAIC,iBAAU,CAAyBC,iBAAiB,CAACC,YAAY,IAAI;MAC/F,IAAIA,YAAY,CAACC,QAAQ,CAACC,yBAAkB,CAACC,WAAW,CAAC,EAAE;QACvDV,aAAa,CAACE,uBAAgB,CAACH,UAAU,CAAC;MAC9C;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM;MACTK,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOL,UAAU;AACrB,CAAC;AAAAY,OAAA,CAAAb,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTheme = void 0;
7
+ var _react = require("react");
8
+ var _web = require("../web");
9
+ var _listener = require("../web/listener");
10
+ var _NativePlatform = require("../specs/NativePlatform");
11
+ const useTheme = () => {
12
+ const [theme, setTheme] = (0, _react.useState)(_web.UnistylesRuntime.getTheme());
13
+ (0, _react.useEffect)(() => {
14
+ const removeChangeListener = _listener.UnistylesListener.addListeners([_NativePlatform.UnistyleDependency.Theme], () => setTheme(_web.UnistylesRuntime.getTheme()));
15
+ return () => {
16
+ removeChangeListener();
17
+ };
18
+ }, []);
19
+ return theme;
20
+ };
21
+ exports.useTheme = useTheme;
22
+ //# sourceMappingURL=useTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_web","_listener","_NativePlatform","useTheme","theme","setTheme","useState","UnistylesRuntime","getTheme","useEffect","removeChangeListener","UnistylesListener","addListeners","UnistyleDependency","Theme","exports"],"sourceRoot":"../../../src","sources":["core/useTheme.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAEO,MAAMI,QAAQ,GAAGA,CAAA,KAAM;EAC1B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACC,qBAAgB,CAACC,QAAQ,CAAC,CAAC,CAAC;EAE/D,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,oBAAoB,GAAGC,2BAAiB,CAACC,YAAY,CAAC,CAACC,kCAAkB,CAACC,KAAK,CAAC,EAAE,MAAMT,QAAQ,CAACE,qBAAgB,CAACC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEpI,OAAO,MAAM;MACTE,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAON,KAAK;AAChB,CAAC;AAAAW,OAAA,CAAAZ,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useTheme = void 0;
7
+ var _react = require("react");
8
+ var _specs = require("../specs");
9
+ const useTheme = () => {
10
+ const [theme, setTheme] = (0, _react.useState)(_specs.UnistylesRuntime.getTheme());
11
+ (0, _react.useEffect)(() => {
12
+ const removeChangeListener = _specs.StyleSheet.addChangeListener(dependencies => {
13
+ if (dependencies.includes(_specs.UnistyleDependency.Theme)) {
14
+ setTheme(_specs.UnistylesRuntime.getTheme());
15
+ }
16
+ });
17
+ return () => {
18
+ removeChangeListener();
19
+ };
20
+ }, []);
21
+ return theme;
22
+ };
23
+ exports.useTheme = useTheme;
24
+ //# sourceMappingURL=useTheme.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_specs","useTheme","theme","setTheme","useState","UnistylesRuntime","getTheme","useEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","includes","UnistyleDependency","Theme","exports"],"sourceRoot":"../../../src","sources":["core/useTheme.native.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAGO,MAAME,QAAQ,GAAGA,CAAA,KAAM;EAC1B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACC,uBAAgB,CAACC,QAAQ,CAAC,CAAC,CAAC;EAE/D,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,oBAAoB,GAAIC,iBAAU,CAAyBC,iBAAiB,CAACC,YAAY,IAAI;MAC/F,IAAIA,YAAY,CAACC,QAAQ,CAACC,yBAAkB,CAACC,KAAK,CAAC,EAAE;QACjDX,QAAQ,CAACE,uBAAgB,CAACC,QAAQ,CAAC,CAAC,CAAC;MACzC;IACJ,CAAC,CAAC;IAEF,OAAO,MAAM;MACTE,oBAAoB,CAAC,CAAC;IAC1B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAON,KAAK;AAChB,CAAC;AAAAa,OAAA,CAAAd,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- mq: true
7
+ mq: true,
8
+ useTheme: true,
9
+ useBreakpoint: true
8
10
  };
9
11
  Object.defineProperty(exports, "mq", {
10
12
  enumerable: true,
@@ -12,6 +14,18 @@ Object.defineProperty(exports, "mq", {
12
14
  return _mq.mq;
13
15
  }
14
16
  });
17
+ Object.defineProperty(exports, "useBreakpoint", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _core.useBreakpoint;
21
+ }
22
+ });
23
+ Object.defineProperty(exports, "useTheme", {
24
+ enumerable: true,
25
+ get: function () {
26
+ return _core.useTheme;
27
+ }
28
+ });
15
29
  var _react = _interopRequireDefault(require("react"));
16
30
  var _specs = require("./specs");
17
31
  Object.keys(_specs).forEach(function (key) {
@@ -26,6 +40,7 @@ Object.keys(_specs).forEach(function (key) {
26
40
  });
27
41
  });
28
42
  var _mq = require("./mq");
43
+ var _core = require("./core");
29
44
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
30
45
  // TODO: export Native createUnistylesComponent
31
46
  // can't import it this way, it will break native build
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_specs","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_mq","e","__esModule","default","minReactVersionRequiredByUnistyles","React","version","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,GAAA,GAAAd,OAAA;AAAyB,SAAAD,uBAAAgB,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEzB;AACA;AACA;;AAEA;AACA,MAAMG,kCAAkC,GAAG,QAAQ;AAEnD,IAAIC,cAAK,CAACC,OAAO,GAAGF,kCAAkC,EAAE;EACpD,MAAM,IAAIG,KAAK,CAAC;AACpB,sDAAsDF,cAAK,CAACC,OAAO;AACnE,4CAA4CF,kCAAkC;AAC9E,KAAK,CAAC;AACN","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_specs","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_mq","_core","e","__esModule","default","minReactVersionRequiredByUnistyles","React","version","Error"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,GAAA,GAAAd,OAAA;AAEA,IAAAe,KAAA,GAAAf,OAAA;AAAgD,SAAAD,uBAAAiB,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAGhD;AACA;AACA;;AAEA;AACA,MAAMG,kCAAkC,GAAG,QAAQ;AAEnD,IAAIC,cAAK,CAACC,OAAO,GAAGF,kCAAkC,EAAE;EACpD,MAAM,IAAIG,KAAK,CAAC;AACpB,sDAAsDF,cAAK,CAACC,OAAO;AACnE,4CAA4CF,kCAAkC;AAC9E,KAAK,CAAC;AACN","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["UnistyleDependency","exports"],"sourceRoot":"../../../../src","sources":["specs/NativePlatform/NativePlatform.nitro.ts"],"mappings":";;;;;;IAMYA,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,0BAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA,OA8B9B;AACA","ignoreList":[]}
1
+ {"version":3,"names":["UnistyleDependency","exports"],"sourceRoot":"../../../../src","sources":["specs/NativePlatform/NativePlatform.nitro.ts"],"mappings":";;;;;;IAMYA,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,0BAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA,OA+B9B;AACA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","attachNavigationBarJSMethods","hybridObject","privateHybrid","_setBackgroundColor","setBackgroundColor","color","parsedColor","processColor","exports"],"sourceRoot":"../../../../src","sources":["specs/NavigtionBar/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AASO,MAAMC,4BAA4B,GAAIC,YAAoC,IAAK;EAClF,MAAMC,aAAa,GAAGD,YAA6C;EAEnEC,aAAa,CAACC,mBAAmB,GAAGF,YAAY,CAACG,kBAAkB;EACnEH,YAAY,CAACG,kBAAkB,GAAIC,KAAc,IAAK;IAClD,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC,IAAI,CAAC;IAE5CH,aAAa,CAACC,mBAAmB,CAACG,WAAqB,CAAC;EAC5D,CAAC;AACL,CAAC;AAAAE,OAAA,CAAAR,4BAAA,GAAAA,4BAAA","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","attachNavigationBarJSMethods","hybridObject","privateHybrid","_setBackgroundColor","setBackgroundColor","color","parsedColor","processColor","exports"],"sourceRoot":"../../../../src","sources":["specs/NavigtionBar/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAcO,MAAMC,4BAA4B,GAAIC,YAAoC,IAAK;EAClF,MAAMC,aAAa,GAAGD,YAA6C;EAEnEC,aAAa,CAACC,mBAAmB,GAAGF,YAAY,CAACG,kBAAkB;EACnEH,YAAY,CAACG,kBAAkB,GAAIC,KAAc,IAAK;IAClD,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC,IAAI,CAAC;IAE5CH,aAAa,CAACC,mBAAmB,CAACG,WAAqB,CAAC;EAC5D,CAAC;AACL,CAAC;AAAAE,OAAA,CAAAR,4BAAA,GAAAA,4BAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_types","attachStatusBarJSMethods","hybridObject","setStyle","style","animated","StatusBarStyle","Light","NativeStatusBar","setBarStyle","Dark","Default","privateHybrid","_setHidden","setHidden","isHidden","animation","_setBackgroundColor","setBackgroundColor","color","parsedColor","processColor","exports"],"sourceRoot":"../../../../src","sources":["specs/StatusBar/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAYO,MAAME,wBAAwB,GAAIC,YAAgC,IAAK;EAC1EA,YAAY,CAACC,QAAQ,GAAG,CAACC,KAAqB,EAAEC,QAAkB,KAAK;IACnE,QAAQD,KAAK;MACT,KAAKE,qBAAc,CAACC,KAAK;QACrB,OAAOC,sBAAe,CAACC,WAAW,CAAC,eAAe,EAAEJ,QAAQ,CAAC;MACjE,KAAKC,qBAAc,CAACI,IAAI;QACpB,OAAOF,sBAAe,CAACC,WAAW,CAAC,cAAc,EAAEJ,QAAQ,CAAC;MAChE,KAAKC,qBAAc,CAACK,OAAO;QACvB,OAAOH,sBAAe,CAACC,WAAW,CAAC,SAAS,EAAEJ,QAAQ,CAAC;IAC/D;EACJ,CAAC;EAED,MAAMO,aAAa,GAAGV,YAAyC;EAE/DU,aAAa,CAACC,UAAU,GAAGX,YAAY,CAACY,SAAS;EACjDZ,YAAY,CAACY,SAAS,GAAG,CAACC,QAAiB,EAAEC,SAAoC,KAAK;IAClFR,sBAAe,CAACM,SAAS,CAACC,QAAQ,EAAEC,SAAS,CAAC;IAC9CJ,aAAa,CAACC,UAAU,CAACE,QAAQ,CAAC;EACtC,CAAC;EAEDH,aAAa,CAACK,mBAAmB,GAAGf,YAAY,CAACgB,kBAAkB;EACnEhB,YAAY,CAACgB,kBAAkB,GAAIC,KAAc,IAAK;IAClD,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC,IAAI,CAAC;IAE5CP,aAAa,CAACK,mBAAmB,CAACG,WAAqB,CAAC;EAC5D,CAAC;AACL,CAAC;AAAAE,OAAA,CAAArB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_types","attachStatusBarJSMethods","hybridObject","setStyle","style","animated","StatusBarStyle","Light","NativeStatusBar","setBarStyle","Dark","Default","privateHybrid","_setHidden","setHidden","isHidden","animation","_setBackgroundColor","setBackgroundColor","color","parsedColor","processColor","exports"],"sourceRoot":"../../../../src","sources":["specs/StatusBar/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAiBO,MAAME,wBAAwB,GAAIC,YAAgC,IAAK;EAC1EA,YAAY,CAACC,QAAQ,GAAG,CAACC,KAAqB,EAAEC,QAAkB,KAAK;IACnE,QAAQD,KAAK;MACT,KAAKE,qBAAc,CAACC,KAAK;QACrB,OAAOC,sBAAe,CAACC,WAAW,CAAC,eAAe,EAAEJ,QAAQ,CAAC;MACjE,KAAKC,qBAAc,CAACI,IAAI;QACpB,OAAOF,sBAAe,CAACC,WAAW,CAAC,cAAc,EAAEJ,QAAQ,CAAC;MAChE,KAAKC,qBAAc,CAACK,OAAO;QACvB,OAAOH,sBAAe,CAACC,WAAW,CAAC,SAAS,EAAEJ,QAAQ,CAAC;IAC/D;EACJ,CAAC;EAED,MAAMO,aAAa,GAAGV,YAAyC;EAE/DU,aAAa,CAACC,UAAU,GAAGX,YAAY,CAACY,SAAS;EACjDZ,YAAY,CAACY,SAAS,GAAG,CAACC,QAAiB,EAAEC,SAAoC,KAAK;IAClFR,sBAAe,CAACM,SAAS,CAACC,QAAQ,EAAEC,SAAS,CAAC;IAC9CJ,aAAa,CAACC,UAAU,CAACE,QAAQ,CAAC;EACtC,CAAC;EAEDH,aAAa,CAACK,mBAAmB,GAAGf,YAAY,CAACgB,kBAAkB;EACnEhB,YAAY,CAACgB,kBAAkB,GAAIC,KAAc,IAAK;IAClD,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC,IAAI,CAAC;IAE5CP,aAAa,CAACK,mBAAmB,CAACG,WAAqB,CAAC;EAC5D,CAAC;AACL,CAAC;AAAAE,OAAA,CAAArB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_reactNativeNitroModules","_StatusBar","_NavigtionBar","_common","HybridUnistylesRuntime","NitroModules","createHybridObject","statusBar","createHybridStatusBar","navigationBar","createHybridNavigationBar","_setRootViewBackgroundColor","setRootViewBackgroundColor","color","parsedColor","processColor","isIOS","setImmersiveMode","isEnabled","setHidden","attachStatusBarJSMethods","attachNavigationBarJSMethods","Runtime","exports"],"sourceRoot":"../../../../src","sources":["specs/UnistylesRuntime/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,wBAAA,GAAAD,OAAA;AAGA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AAgCA,MAAMK,sBAAsB,GAAGC,qCAAY,CACtCC,kBAAkB,CAA0B,kBAAkB,CAAC;AAEpEF,sBAAsB,CAACG,SAAS,GAAGH,sBAAsB,CAACI,qBAAqB,CAAC,CAAC;AACjFJ,sBAAsB,CAACK,aAAa,GAAGL,sBAAsB,CAACM,yBAAyB,CAAC,CAAC;AACzFN,sBAAsB,CAACO,2BAA2B,GAAGP,sBAAsB,CAACQ,0BAA0B;AAEtGR,sBAAsB,CAACQ,0BAA0B,GAAIC,KAAc,IAAK;EACpE,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC,IAAI,CAAC;EAE5CT,sBAAsB,CAACO,2BAA2B,CAACG,WAAqB,CAAC;AAC7E,CAAC;AAED,IAAIE,aAAK,EAAE;EACPZ,sBAAsB,CAACa,gBAAgB,GAAIC,SAAkB,IAAKd,sBAAsB,CAACG,SAAS,CAACY,SAAS,CAACD,SAAS,EAAE,MAAM,CAAC;AACnI;AAEA,IAAAE,mCAAwB,EAAChB,sBAAsB,CAACG,SAAS,CAAC;AAC1D,IAAAc,0CAA4B,EAACjB,sBAAsB,CAACK,aAAa,CAAC;AAE3D,MAAMa,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAGlB,sBAA0C","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_reactNativeNitroModules","_StatusBar","_NavigtionBar","_common","HybridUnistylesRuntime","NitroModules","createHybridObject","statusBar","createHybridStatusBar","navigationBar","createHybridNavigationBar","_setRootViewBackgroundColor","setRootViewBackgroundColor","color","parsedColor","processColor","isIOS","setImmersiveMode","isEnabled","setHidden","attachStatusBarJSMethods","attachNavigationBarJSMethods","Runtime","exports"],"sourceRoot":"../../../../src","sources":["specs/UnistylesRuntime/index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,wBAAA,GAAAD,OAAA;AAGA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AAkCA,MAAMK,sBAAsB,GAAGC,qCAAY,CACtCC,kBAAkB,CAA0B,kBAAkB,CAAC;AAEpEF,sBAAsB,CAACG,SAAS,GAAGH,sBAAsB,CAACI,qBAAqB,CAAC,CAAC;AACjFJ,sBAAsB,CAACK,aAAa,GAAGL,sBAAsB,CAACM,yBAAyB,CAAC,CAAC;AACzFN,sBAAsB,CAACO,2BAA2B,GAAGP,sBAAsB,CAACQ,0BAA0B;AAEtGR,sBAAsB,CAACQ,0BAA0B,GAAIC,KAAc,IAAK;EACpE,MAAMC,WAAW,GAAG,IAAAC,yBAAY,EAACF,KAAK,CAAC,IAAI,CAAC;EAE5CT,sBAAsB,CAACO,2BAA2B,CAACG,WAAqB,CAAC;AAC7E,CAAC;AAED,IAAIE,aAAK,EAAE;EACPZ,sBAAsB,CAACa,gBAAgB,GAAIC,SAAkB,IAAKd,sBAAsB,CAACG,SAAS,CAACY,SAAS,CAACD,SAAS,EAAE,MAAM,CAAC;AACnI;AAEA,IAAAE,mCAAwB,EAAChB,sBAAsB,CAACG,SAAS,CAAC;AAC1D,IAAAc,0CAA4B,EAACjB,sBAAsB,CAACK,aAAa,CAAC;AAE3D,MAAMa,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAGlB,sBAA0C","ignoreList":[]}
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "StyleSheet", {
27
27
  return _StyleSheet.StyleSheet;
28
28
  }
29
29
  });
30
+ Object.defineProperty(exports, "UnistyleDependency", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _NativePlatform.UnistyleDependency;
34
+ }
35
+ });
30
36
  Object.defineProperty(exports, "UnistylesRuntime", {
31
37
  enumerable: true,
32
38
  get: function () {
@@ -44,4 +50,5 @@ var _UnistylesRuntime = require("./UnistylesRuntime");
44
50
  var _StyleSheet = require("./StyleSheet");
45
51
  var _ShadowRegistry = require("./ShadowRegistry");
46
52
  var _types = require("./types");
53
+ var _NativePlatform = require("./NativePlatform");
47
54
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["require","_UnistylesRuntime","_StyleSheet","_ShadowRegistry","_types"],"sourceRoot":"../../../src","sources":["specs/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["require","_UnistylesRuntime","_StyleSheet","_ShadowRegistry","_types","_NativePlatform"],"sourceRoot":"../../../src","sources":["specs/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA,OAAA;AAEA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAAG,eAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA","ignoreList":[]}
@@ -58,14 +58,7 @@ class UnistylesRuntimeBuilder {
58
58
  return screen.orientation.type.includes('portrait') ? _types.Orientation.Portrait : _types.Orientation.Landscape;
59
59
  }
60
60
  get theme() {
61
- if (!this.themeName) {
62
- throw new Error('🦄 No theme selected!');
63
- }
64
- const theme = _state.UnistylesState.themes.get(this.themeName);
65
- if (!theme) {
66
- throw new Error(`🦄 Theme "${this.themeName}" is not registered!`);
67
- }
68
- return theme;
61
+ return this.getTheme(this.themeName);
69
62
  }
70
63
  get pixelRatio() {
71
64
  return (0, _utils.isServer)() ? 1 : window.devicePixelRatio;
@@ -112,7 +105,8 @@ class UnistylesRuntimeBuilder {
112
105
  themeName: this.themeName,
113
106
  contentSizeCategory: this.contentSizeCategory,
114
107
  breakpoint: this.breakpoint,
115
- orientation: this.orientation,
108
+ isLandscape: this.orientation === _types.Orientation.Landscape,
109
+ isPortrait: this.orientation === _types.Orientation.Portrait,
116
110
  pixelRatio: this.pixelRatio,
117
111
  screen: this.screen,
118
112
  fontScale: this.fontScale,
@@ -158,6 +152,16 @@ class UnistylesRuntimeBuilder {
158
152
  }
159
153
  _state.UnistylesState.themes.set(themeName, updater(oldTheme));
160
154
  };
155
+ getTheme = (themeName = this.themeName) => {
156
+ if (!themeName) {
157
+ throw new Error('🦄 No theme selected!');
158
+ }
159
+ const theme = _state.UnistylesState.themes.get(themeName);
160
+ if (!theme) {
161
+ throw new Error(`🦄 Theme "${this.themeName}" is not registered!`);
162
+ }
163
+ return theme;
164
+ };
161
165
  }
162
166
  const UnistylesRuntime = exports.UnistylesRuntime = new UnistylesRuntimeBuilder();
163
167
  //# sourceMappingURL=runtime.js.map