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
package/README.md CHANGED
@@ -28,6 +28,7 @@ Install CocoaPods dependencies / generate native folders with Expo:
28
28
 
29
29
  ```shell
30
30
  pod install
31
+ or
31
32
  npx expo prebuild
32
33
  ```
33
34
 
@@ -68,6 +69,12 @@ npx expo prebuild
68
69
  <a href="https://github.com/mwarger">
69
70
  <img src="https://avatars.githubusercontent.com/u/686823?v=4" height="70px" width="70px" alt="mwarger" />
70
71
  </a>
72
+ <a href="https://github.com/biw">
73
+ <img src="https://avatars.githubusercontent.com/u/6139501?v=4" height="70px" width="70px" alt="biw" />
74
+ </a>
75
+ <a href="https://github.com/happyfloat">
76
+ <img src="https://avatars.githubusercontent.com/u/186333704?s=200&v=4" height="70px" width="70px" alt="happyfloat" />
77
+ </a>
71
78
 
72
79
  ## Past sponsors
73
80
 
@@ -35,28 +35,19 @@ set_target_properties(unistyles PROPERTIES
35
35
  find_package(ReactAndroid REQUIRED CONFIG)
36
36
  find_package(fbjni REQUIRED CONFIG)
37
37
 
38
- target_include_directories(
39
- unistyles
40
- PRIVATE
41
- "../node_modules/react-native/ReactCommon"
42
- "../node_modules/react-native/ReactAndroid/src/main/jni/react/turbomodule"
43
- "../node_modules/react-native/ReactCommon/callinvoker"
44
- "../node_modules/react-native/ReactCommon/runtimeexecutor"
45
- "../node_modules/react-native/ReactCommon/yoga"
46
- "../node_modules/react-native/ReactCommon/react/renderer/graphics/platform/cxx"
47
- )
38
+ # REACTNATIVE_MERGED_SO doesnt work as of RN 0.76.0-rc.3
39
+ if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
40
+ target_link_libraries(unistyles ReactAndroid::reactnative)
41
+ else()
42
+ target_link_libraries(unistyles
43
+ ReactAndroid::turbomodulejsijni
44
+ ReactAndroid::react_nativemodule_core
45
+ android
46
+ fbjni::fbjni
47
+ )
48
+ endif()
48
49
 
49
50
  target_link_libraries(unistyles
50
51
  ReactAndroid::jsi
51
- ReactAndroid::turbomodulejsijni
52
- ReactAndroid::react_nativemodule_core
53
- android
54
- ReactAndroid::react_render_core
55
- ReactAndroid::runtimeexecutor
56
- ReactAndroid::fabricjni
57
- ReactAndroid::react_debug
58
- ReactAndroid::react_render_core
59
- ReactAndroid::react_render_componentregistry
60
- ReactAndroid::rrc_view
61
- ReactAndroid::folly_runtime
52
+ fbjni::fbjni
62
53
  )
@@ -25,13 +25,3 @@ void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &
25
25
  // so, resume Unistyles commits
26
26
  registry.trafficController.resumeUnistylesTraffic();
27
27
  }
28
-
29
- shadow::ShadowLeafUpdates core::UnistylesMountHook::getUnistylesUpdates() {
30
- auto& registry = core::UnistylesRegistry::get();
31
- auto parser = parser::Parser(this->_unistylesRuntime);
32
- auto dependencyMap = registry.buildDependencyMap(*this->_rt);
33
-
34
- // don't rebuild dependency map, at this point it's already done
35
-
36
- return parser.dependencyMapToShadowLeafUpdates(dependencyMap);
37
- }
@@ -11,20 +11,15 @@ namespace margelo::nitro::unistyles::core {
11
11
  using namespace facebook::react;
12
12
 
13
13
  struct UnistylesMountHook : public UIManagerMountHook {
14
- UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, jsi::Runtime& rt)
15
- : _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager}, _rt{&rt} {
16
- _uiManager->registerMountHook(*this);
17
- }
14
+ UnistylesMountHook(std::shared_ptr<UIManager> uiManager) : _uiManager{uiManager} {
15
+ _uiManager->registerMountHook(*this);
16
+ }
18
17
 
19
18
  ~UnistylesMountHook() noexcept override;
20
19
 
21
20
  void shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept override;
22
21
 
23
- shadow::ShadowLeafUpdates getUnistylesUpdates();
24
-
25
22
  private:
26
- jsi::Runtime* _rt;
27
- std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
28
23
  std::shared_ptr<UIManager> _uiManager;
29
24
  };
30
25
 
@@ -5,10 +5,10 @@ using namespace margelo::nitro::unistyles;
5
5
  using namespace facebook;
6
6
  using namespace facebook::react;
7
7
 
8
- void core::UnistylesRegistry::registerTheme(jsi::Runtime& rt, std::string name, jsi::Object&& theme) {
8
+ void core::UnistylesRegistry::registerTheme(jsi::Runtime& rt, std::string name, jsi::Value& theme) {
9
9
  auto& state = this->getState(rt);
10
10
 
11
- state._jsThemes.emplace(name, jsi::WeakObject(rt, std::move(theme)));
11
+ state._jsThemes.emplace(name, std::move(theme));
12
12
  state._registeredThemeNames.push_back(name);
13
13
  }
14
14
 
@@ -60,15 +60,11 @@ void core::UnistylesRegistry::updateTheme(jsi::Runtime& rt, std::string& themeNa
60
60
 
61
61
  helpers::assertThat(rt, it != state._jsThemes.end(), "Unistyles: You're trying to update theme '" + themeName + "' but it wasn't registered.");
62
62
 
63
- auto currentThemeValue = it->second.lock(rt);
64
-
65
- helpers::assertThat(rt, currentThemeValue.isObject(), "Unistyles: Unable to update your theme from C++. It was already garbage collected.");
66
-
67
- auto result = callback.call(rt, currentThemeValue.asObject(rt));
63
+ auto result = callback.call(rt, it->second);
68
64
 
69
65
  helpers::assertThat(rt, result.isObject(), "Unistyles: Returned theme is not an object. Please check your updateTheme function.");
70
66
 
71
- it->second = jsi::WeakObject(rt, result.asObject(rt));
67
+ it->second = result.asObject(rt);
72
68
  }
73
69
 
74
70
  void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
@@ -28,7 +28,7 @@ struct UnistylesRegistry: public StyleSheetRegistry {
28
28
  UnistylesRegistry(const UnistylesRegistry&) = delete;
29
29
  UnistylesRegistry(const UnistylesRegistry&&) = delete;
30
30
 
31
- void registerTheme(jsi::Runtime& rt, std::string name, jsi::Object&& theme);
31
+ void registerTheme(jsi::Runtime& rt, std::string name, jsi::Value& theme);
32
32
  void registerBreakpoints(jsi::Runtime& rt, std::vector<std::pair<std::string, double>>& sortedBreakpoints);
33
33
  void setPrefersAdaptiveThemes(jsi::Runtime& rt, bool prefersAdaptiveThemes);
34
34
  void setInitialThemeName(jsi::Runtime& rt, std::string themeName);
@@ -41,11 +41,7 @@ jsi::Object core::UnistylesState::getCurrentJSTheme() {
41
41
 
42
42
  helpers::assertThat(*_rt, it != this->_jsThemes.end(), "Unistyles: You're trying to get theme '" + _currentThemeName.value() + "', but it was not registered. Did you forget to register it with StyleSheet.configure?");
43
43
 
44
- auto maybeTheme = it->second.lock(*_rt);
45
-
46
- 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.");
47
-
48
- return maybeTheme.asObject(*_rt);
44
+ return it->second.asObject(*_rt);
49
45
  }
50
46
 
51
47
  jsi::Object core::UnistylesState::getJSThemeByName(std::string& themeName) {
@@ -53,11 +49,7 @@ jsi::Object core::UnistylesState::getJSThemeByName(std::string& themeName) {
53
49
 
54
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?");
55
51
 
56
- auto maybeTheme = it->second.lock(*_rt);
57
-
58
- 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.");
59
-
60
- return maybeTheme.asObject(*_rt);
52
+ return it->second.asObject(*_rt);
61
53
  }
62
54
 
63
55
  void core::UnistylesState::computeCurrentBreakpoint(int screenWidth) {
@@ -37,7 +37,7 @@ struct UnistylesState {
37
37
 
38
38
  private:
39
39
  jsi::Runtime* _rt;
40
- std::unordered_map<std::string, jsi::WeakObject> _jsThemes{};
40
+ std::unordered_map<std::string, jsi::Value> _jsThemes{};
41
41
  std::optional<bool> _prefersAdaptiveThemes = std::nullopt;
42
42
  std::optional<std::string> _initialThemeName = std::nullopt;
43
43
  std::optional<std::string> _currentBreakpointName = std::nullopt;
@@ -67,9 +67,9 @@ jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisV
67
67
  });
68
68
 
69
69
  verifyAndSelectTheme(rt);
70
-
70
+
71
71
  auto& state = core::UnistylesRegistry::get().getState(rt);
72
-
72
+
73
73
  state.hasUserConfig = true;
74
74
 
75
75
  return jsi::Value::undefined();
@@ -80,10 +80,10 @@ jsi::Value HybridStyleSheet::init(jsi::Runtime &rt, const jsi::Value &thisVal, c
80
80
  auto& registry = core::UnistylesRegistry::get();
81
81
 
82
82
  registry.createState(rt);
83
-
83
+
84
84
  loadExternalMethods(thisVal, rt);
85
85
  registerHooks(rt);
86
-
86
+
87
87
  return jsi::Value::undefined();
88
88
  }
89
89
 
@@ -140,11 +140,10 @@ void HybridStyleSheet::parseThemes(jsi::Runtime &rt, jsi::Object themes) {
140
140
  helpers::enumerateJSIObject(rt, themes, [&](const std::string& propertyName, jsi::Value& propertyValue){
141
141
  helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's registered theme '" + propertyName + "' must be an object.");
142
142
 
143
- registry.registerTheme(rt, propertyName, propertyValue.asObject(rt));
143
+ registry.registerTheme(rt, propertyName, propertyValue);
144
144
  });
145
145
  }
146
146
 
147
-
148
147
  void HybridStyleSheet::verifyAndSelectTheme(jsi::Runtime &rt) {
149
148
  auto& state = core::UnistylesRegistry::get().getState(rt);
150
149
 
@@ -228,50 +227,84 @@ void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Run
228
227
 
229
228
  void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
230
229
  this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager, this->_unistylesRuntime, rt);
231
- this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime, rt);
230
+ this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager);
232
231
  }
233
232
 
234
233
  void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies) {
235
- auto& registry = core::UnistylesRegistry::get();
236
- auto parser = parser::Parser(this->_unistylesRuntime);
237
- auto& rt = this->_unistylesRuntime->getRuntime();
238
-
239
- // re-compute new breakpoint
240
- auto dimensionsIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::DIMENSIONS);
241
-
242
- if (dimensionsIt != dependencies.end()) {
243
- registry.getState(rt).computeCurrentBreakpoint(this->_unistylesRuntime->getScreen().width);
234
+ if (this->_unistylesRuntime == nullptr) {
235
+ return;
244
236
  }
245
237
 
246
- // check if color scheme changed and then if Unistyles state depend on it (adaptive themes)
247
- auto colorSchemeIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::COLORSCHEME);
248
- auto hasNewColorScheme = colorSchemeIt != dependencies.end();
238
+ this->_unistylesRuntime->runOnJSThread([this, &dependencies](jsi::Runtime& rt){
239
+ auto& registry = core::UnistylesRegistry::get();
240
+ auto parser = parser::Parser(this->_unistylesRuntime);
249
241
 
250
- // in a later step, we will rebuild only Unistyles with mounted StyleSheets
251
- // however, user may have StyleSheets with components that haven't mounted yet
252
- // we need to rebuild all dependent StyleSheets as well
253
- auto dependentStyleSheets = registry.getStyleSheetsToRefresh(rt, hasNewColorScheme, dependencies.size() > 1);
242
+ // re-compute new breakpoint
243
+ auto dimensionsIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::DIMENSIONS);
254
244
 
255
- if (hasNewColorScheme) {
256
- this->_unistylesRuntime->includeDependenciesForColorSchemeChange(dependencies);
257
- }
245
+ if (dimensionsIt != dependencies.end()) {
246
+ registry.getState(rt).computeCurrentBreakpoint(this->_unistylesRuntime->getScreen().width);
247
+ }
248
+
249
+ // check if color scheme changed and then if Unistyles state depend on it (adaptive themes)
250
+ auto colorSchemeIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::COLORSCHEME);
251
+ auto hasNewColorScheme = colorSchemeIt != dependencies.end();
252
+
253
+ // in a later step, we will rebuild only Unistyles with mounted StyleSheets
254
+ // however, user may have StyleSheets with components that haven't mounted yet
255
+ // we need to rebuild all dependent StyleSheets as well
256
+ auto dependentStyleSheets = registry.getStyleSheetsToRefresh(rt, hasNewColorScheme, dependencies.size() > 1);
257
+
258
+ if (hasNewColorScheme) {
259
+ this->_unistylesRuntime->includeDependenciesForColorSchemeChange(dependencies);
260
+ }
261
+
262
+ this->notifyJSListeners(dependencies);
258
263
 
259
- this->notifyJSListeners(dependencies);
264
+ auto dependencyMap = registry.buildDependencyMap(rt, dependencies);
260
265
 
261
- auto dependencyMap = registry.buildDependencyMap(rt, dependencies);
266
+ if (dependencyMap.size() == 0) {
267
+ return;
268
+ }
269
+
270
+ parser.rebuildUnistylesInDependencyMap(rt, dependencyMap, dependentStyleSheets);
271
+
272
+ // this is required, otherwise shadow tree will ignore Unistyles commit
273
+ registry.trafficController.setHasUnistylesCommit(true);
274
+
275
+ auto shadowLeafUpdates = parser.dependencyMapToShadowLeafUpdates(dependencyMap);
276
+
277
+ shadow::ShadowTreeManager::updateShadowTree(rt, shadowLeafUpdates);
278
+ });
279
+ }
262
280
 
263
- if (dependencyMap.size() == 0) {
281
+ void HybridStyleSheet::onImeChange() {
282
+ if (this->_unistylesRuntime == nullptr) {
264
283
  return;
265
284
  }
266
285
 
267
- parser.rebuildUnistylesInDependencyMap(rt, dependencyMap, dependentStyleSheets);
286
+ this->_unistylesRuntime->runOnJSThread([this](jsi::Runtime& rt){
287
+ auto& registry = core::UnistylesRegistry::get();
288
+ auto parser = parser::Parser(this->_unistylesRuntime);
289
+ std::vector<UnistyleDependency> dependencies{UnistyleDependency::IME};
268
290
 
269
- // this is required, otherwise shadow tree will ignore Unistyles commit
270
- registry.trafficController.setHasUnistylesCommit(true);
291
+ this->notifyJSListeners(dependencies);
271
292
 
272
- auto shadowLeafUpdates = parser.dependencyMapToShadowLeafUpdates(dependencyMap);
293
+ auto dependencyMap = registry.buildDependencyMap(rt, dependencies);
273
294
 
274
- shadow::ShadowTreeManager::updateShadowTree(rt, shadowLeafUpdates);
295
+ if (dependencyMap.size() == 0) {
296
+ return;
297
+ }
298
+
299
+ parser.rebuildUnistylesInDependencyMap(rt, dependencyMap, {});
300
+
301
+ // this is required, otherwise shadow tree will ignore Unistyles commit
302
+ registry.trafficController.setHasUnistylesCommit(true);
303
+
304
+ auto shadowLeafUpdates = parser.dependencyMapToShadowLeafUpdates(dependencyMap);
305
+
306
+ shadow::ShadowTreeManager::updateShadowTree(rt, shadowLeafUpdates);
307
+ });
275
308
  }
276
309
 
277
310
  void HybridStyleSheet::notifyJSListeners(std::vector<UnistyleDependency>& dependencies) {
@@ -22,7 +22,14 @@ struct HybridStyleSheet: public HybridUnistylesStyleSheetSpec {
22
22
  this->_unistylesRuntime->registerPlatformListener(
23
23
  std::bind(&HybridStyleSheet::onPlatformDependenciesChange, this, std::placeholders::_1)
24
24
  );
25
+ this->_unistylesRuntime->registerImeListener(
26
+ std::bind(&HybridStyleSheet::onImeChange, this)
27
+ );
25
28
  }
29
+
30
+ ~HybridStyleSheet() {
31
+ this->_unistylesRuntime->unregisterPlatformListeners();
32
+ }
26
33
 
27
34
  jsi::Value create(jsi::Runtime& rt,
28
35
  const jsi::Value& thisValue,
@@ -50,7 +57,7 @@ struct HybridStyleSheet: public HybridUnistylesStyleSheetSpec {
50
57
  double getHairlineWidth() override;
51
58
  double getUnid() override;
52
59
  std::function<void ()> addChangeListener(const std::function<void (const std::vector<UnistyleDependency> &)>& onChanged) override;
53
-
60
+
54
61
  private:
55
62
  void parseSettings(jsi::Runtime& rt, jsi::Object settings);
56
63
  void parseBreakpoints(jsi::Runtime& rt, jsi::Object breakpoints);
@@ -60,6 +67,7 @@ private:
60
67
  void loadExternalMethods(const jsi::Value& thisValue, jsi::Runtime& rt);
61
68
  void registerHooks(jsi::Runtime& rt);
62
69
  void onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies);
70
+ void onImeChange();
63
71
  void notifyJSListeners(std::vector<UnistyleDependency>& dependencies);
64
72
 
65
73
  double __unid = -1;
@@ -114,19 +114,19 @@ void HybridUnistylesRuntime::calculateNewThemeAndDependencies(std::vector<Unisty
114
114
 
115
115
  jsi::Value HybridUnistylesRuntime::getTheme(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
116
116
  helpers::assertThat(rt, count <= 1, "UnistylesRuntime.getTheme expected to be called with 0 or 1 argument.");
117
-
117
+
118
118
  auto& state = core::UnistylesRegistry::get().getState(*_rt);
119
-
119
+
120
120
  if (count == 1) {
121
121
  helpers::assertThat(rt, args[0].isString(), "UnistylesRuntime.getTheme expected to be called with string.");
122
-
122
+
123
123
  auto themeName = args[0].asString(rt).utf8(rt);
124
-
124
+
125
125
  helpers::assertThat(rt, state.hasTheme(themeName), "Unistyles: You're trying to get theme '" + themeName + "' but it wasn't registered.");
126
-
126
+
127
127
  return state.getJSThemeByName(themeName);
128
128
  }
129
-
129
+
130
130
  return state.getCurrentJSTheme();
131
131
  }
132
132
 
@@ -212,7 +212,7 @@ jsi::Value HybridUnistylesRuntime::getMiniRuntimeAsValue(jsi::Runtime& rt) {
212
212
  obj.setProperty(rt, "navigationBar", JSIConverter<Dimensions>::toJSI(rt, miniRuntime.navigationBar));
213
213
  obj.setProperty(rt, "isPortrait", JSIConverter<bool>::toJSI(rt, miniRuntime.isPortrait));
214
214
  obj.setProperty(rt, "isLandscape", JSIConverter<bool>::toJSI(rt, miniRuntime.isLandscape));
215
-
215
+
216
216
  return obj;
217
217
  }
218
218
 
@@ -225,6 +225,14 @@ void HybridUnistylesRuntime::registerPlatformListener(const std::function<void(s
225
225
  this->_onDependenciesChange = listener;
226
226
  }
227
227
 
228
+ void HybridUnistylesRuntime::registerImeListener(const std::function<void()>& listener) {
229
+ this->_nativePlatform.registerImeListener(listener);
230
+ }
231
+
232
+ void HybridUnistylesRuntime::unregisterPlatformListeners() {
233
+ this->_nativePlatform.unregisterPlatformListeners();
234
+ }
235
+
228
236
  void HybridUnistylesRuntime::includeDependenciesForColorSchemeChange(std::vector<UnistyleDependency>& deps) {
229
237
  auto& registry = core::UnistylesRegistry::get();
230
238
  auto& state = registry.getState(*this->_rt);
@@ -13,7 +13,8 @@
13
13
  namespace margelo::nitro::unistyles {
14
14
 
15
15
  struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
16
- HybridUnistylesRuntime(Unistyles::HybridNativePlatformSpecCxx nativePlatform, jsi::Runtime& rt) : HybridObject(TAG), _nativePlatform{nativePlatform}, _rt{&rt} {}
16
+ HybridUnistylesRuntime(Unistyles::HybridNativePlatformSpecCxx nativePlatform, jsi::Runtime& rt, std::function<void(std::function<void(jsi::Runtime&)>&&)> runOnJSThread)
17
+ : HybridObject(TAG), _nativePlatform{nativePlatform}, _rt{&rt}, runOnJSThread(std::move(runOnJSThread)) {}
17
18
 
18
19
  jsi::Value getTheme(jsi::Runtime& rt,
19
20
  const jsi::Value& thisValue,
@@ -55,6 +56,8 @@ struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
55
56
  double getPixelRatio() override;
56
57
  double getFontScale() override;
57
58
  void registerPlatformListener(const std::function<void(std::vector<UnistyleDependency>)>& listener);
59
+ void registerImeListener(const std::function<void()>& listener);
60
+ void unregisterPlatformListeners();
58
61
 
59
62
  void setTheme(const std::string &themeName) override;
60
63
  void setAdaptiveThemes(bool isEnabled) override;
@@ -65,6 +68,7 @@ struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
65
68
  jsi::Runtime& getRuntime();
66
69
  void includeDependenciesForColorSchemeChange(std::vector<UnistyleDependency>& deps);
67
70
  void calculateNewThemeAndDependencies(std::vector<UnistyleDependency>& deps);
71
+ std::function<void(std::function<void(jsi::Runtime&)>&&)> runOnJSThread;
68
72
 
69
73
  private:
70
74
  jsi::Runtime* _rt;
@@ -15,7 +15,6 @@ void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
15
15
 
16
16
  jsi::Object styleValue = propertyValue.asObject(rt);
17
17
 
18
-
19
18
  if (styleValue.isFunction(rt)) {
20
19
  styleSheet->unistyles[styleKey] = std::make_shared<UnistyleDynamicFunction>(
21
20
  UnistyleType::DynamicFunction,
@@ -270,6 +269,18 @@ jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared u
270
269
 
271
270
  return;
272
271
  }
272
+
273
+ if (propertyName == "boxShadow" && propertyValueObject.isArray(rt)) {
274
+ parsedStyle.setProperty(rt, jsi::PropNameID::forUtf8(rt, propertyName), parseBoxShadow(rt, unistyle, propertyValueObject));
275
+
276
+ return;
277
+ }
278
+
279
+ if (propertyName == "filter" && propertyValueObject.isArray(rt)) {
280
+ parsedStyle.setProperty(rt, jsi::PropNameID::forUtf8(rt, propertyName), parseFilters(rt, unistyle, propertyValueObject));
281
+
282
+ return;
283
+ }
273
284
 
274
285
  if (propertyName == "fontVariant" && propertyValueObject.isArray(rt)) {
275
286
  parsedStyle.setProperty(rt, jsi::PropNameID::forUtf8(rt, propertyName), propertyValue);
@@ -365,10 +376,6 @@ std::vector<UnistyleDependency> parser::Parser::parseDependencies(jsi::Runtime &
365
376
 
366
377
  // eg. [{ scale: 2 }, { translateX: 100 }]
367
378
  jsi::Value parser::Parser::parseTransforms(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj) {
368
- if (!obj.isArray(rt)) {
369
- return jsi::Value::undefined();
370
- }
371
-
372
379
  std::vector<jsi::Value> parsedTransforms{};
373
380
 
374
381
  parsedTransforms.reserve(2);
@@ -398,6 +405,67 @@ jsi::Value parser::Parser::parseTransforms(jsi::Runtime& rt, Unistyle::Shared un
398
405
  return result;
399
406
  }
400
407
 
408
+ // eg [{offsetX: 5, offsetY: 5, blurRadius: 5, spreadDistance: 0, color: ‘rgba(255, 0, 0, 0.5)’}]
409
+ jsi::Value parser::Parser::parseBoxShadow(jsi::Runtime &rt, Unistyle::Shared unistyle, jsi::Object &obj) {
410
+ std::vector<jsi::Value> parsedBoxShadows{};
411
+
412
+ parsedBoxShadows.reserve(2);
413
+
414
+ helpers::iterateJSIArray(rt, obj.asArray(rt), [&](size_t i, jsi::Value& value){
415
+ if (!value.isObject()) {
416
+ return;
417
+ }
418
+
419
+ auto parsedResult = this->parseSecondLevel(rt, unistyle, value);
420
+
421
+ parsedBoxShadows.emplace_back(std::move(parsedResult));
422
+ });
423
+
424
+ // create jsi::Array result with correct box shadows
425
+ jsi::Array result = jsi::Array(rt, parsedBoxShadows.size());
426
+
427
+ for (size_t i = 0; i < parsedBoxShadows.size(); i++) {
428
+ result.setValueAtIndex(rt, i, parsedBoxShadows[i]);
429
+ }
430
+
431
+ return result;
432
+ }
433
+
434
+ // eg. [{ brightness: 0.5 }, { opacity: 0.25 }]
435
+ jsi::Value parser::Parser::parseFilters(jsi::Runtime &rt, Unistyle::Shared unistyle, jsi::Object &obj) {
436
+ std::vector<jsi::Value> parsedFilters{};
437
+
438
+ parsedFilters.reserve(2);
439
+
440
+ helpers::iterateJSIArray(rt, obj.asArray(rt), [&](size_t i, jsi::Value& value){
441
+ if (!value.isObject()) {
442
+ return;
443
+ }
444
+
445
+ auto parsedResult = this->parseSecondLevel(rt, unistyle, value);
446
+
447
+ // take only one filter per object
448
+ jsi::Array propertyNames = parsedResult.asObject(rt).getPropertyNames(rt);
449
+ size_t length = propertyNames.size(rt);
450
+
451
+ // ignore no filters
452
+ if (length == 0) {
453
+ return;
454
+ }
455
+
456
+ parsedFilters.emplace_back(std::move(parsedResult));
457
+ });
458
+
459
+ // create jsi::Array result with correct filters
460
+ jsi::Array result = jsi::Array(rt, parsedFilters.size());
461
+
462
+ for (size_t i = 0; i < parsedFilters.size(); i++) {
463
+ result.setValueAtIndex(rt, i, parsedFilters[i]);
464
+ }
465
+
466
+ return result;
467
+ }
468
+
401
469
  // find value based on breakpoints and mq
402
470
  jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj) {
403
471
  auto& registry = core::UnistylesRegistry::get();
@@ -35,6 +35,8 @@ private:
35
35
  jsi::Function createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle);
36
36
  std::vector<UnistyleDependency> parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies);
37
37
  jsi::Value parseTransforms(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
38
+ jsi::Value parseBoxShadow(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
39
+ jsi::Value parseFilters(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
38
40
  jsi::Value getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj);
39
41
  jsi::Object parseVariants(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj, Variants& variants);
40
42
  jsi::Value getStylesForVariant(jsi::Runtime& rt, const std::string groupName, jsi::Object&& groupValue, std::optional<std::string> selectedVariant, Variants& variants);
@@ -4,13 +4,16 @@ import Foundation
4
4
  import Combine
5
5
  import NitroModules
6
6
 
7
- typealias CxxListener = (Array<UnistyleDependency>) -> Void
7
+ typealias CxxDependencyListener = (Array<UnistyleDependency>) -> Void
8
+ typealias CxxImeListener = () -> Void
8
9
 
9
10
  class NativeIOSPlatform: HybridNativePlatformSpec {
10
11
  var miniRuntime: UnistylesNativeMiniRuntime?
12
+ var keyboardAnimation = KeyboardAnimation()
11
13
  var cancellables = Set<AnyCancellable>()
12
14
 
13
- var listeners: Array<CxxListener> = []
15
+ var dependencyListeners: Array<CxxDependencyListener> = []
16
+ var imeListeners: Array<CxxImeListener> = []
14
17
  var hybridContext = margelo.nitro.HybridContext()
15
18
  var memorySize: Int {
16
19
  return getSizeOf(self)
@@ -20,10 +23,12 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
20
23
  self.miniRuntime = self.buildMiniRuntime()
21
24
 
22
25
  setupPlatformListeners()
26
+ setupKeyboardListeners()
23
27
  }
24
28
 
25
29
  deinit {
26
30
  removePlatformListeners()
31
+ removeKeyboardListeners()
27
32
  }
28
33
 
29
34
  func getMiniRuntime() -> UnistylesNativeMiniRuntime {
@@ -32,7 +37,7 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
32
37
 
33
38
  func buildMiniRuntime() -> UnistylesNativeMiniRuntime {
34
39
  let orientation = self.getOrientation()
35
-
40
+
36
41
  return UnistylesNativeMiniRuntime(
37
42
  colorScheme: self.getColorScheme(),
38
43
  screen: self.getScreenDimensions(),
@@ -193,7 +198,13 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
193
198
 
194
199
  let safeArea = window.safeAreaInsets
195
200
 
196
- return Insets(top: safeArea.top, bottom: safeArea.bottom, left: safeArea.left, right: safeArea.right, ime: 0)
201
+ return Insets(
202
+ top: safeArea.top,
203
+ bottom: safeArea.bottom,
204
+ left: safeArea.left,
205
+ right: safeArea.right,
206
+ ime: keyboardAnimation.animatedImeInset
207
+ )
197
208
  }
198
209
 
199
210
  if Thread.isMainThread {
@@ -279,7 +290,7 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
279
290
  func getNavigationBarDimensions() -> Dimensions {
280
291
  return Dimensions(width: 0, height: 0);
281
292
  }
282
-
293
+
283
294
  func setStatusBarHidden(isHidden: Bool) throws {
284
295
  self.onWindowChange(Notification(name: NSNotification.Name("RCTWindowFrameDidChangeNotification")))
285
296
  }