react-native-unistyles 3.0.0-alpha.12 → 3.0.0-alpha.13
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/core/UnistylesCommitHook.cpp +7 -1
- package/cxx/core/UnistylesCommitHook.h +1 -0
- package/cxx/core/UnistylesMountHook.cpp +15 -1
- package/cxx/core/UnistylesRegistry.h +3 -1
- package/cxx/hybridObjects/HybridStyleSheet.cpp +2 -0
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +33 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +7 -0
- package/cxx/shadowTree/ShadowTreeManager.h +1 -0
- package/lib/commonjs/specs/ShadowRegistry/index.js +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +1 -1
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/typescript/example/App.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/specs/ShadowRegistry/index.ts +1 -1
@@ -25,12 +25,18 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
|
|
25
25
|
|
26
26
|
return newRootShadowNode;
|
27
27
|
}
|
28
|
-
|
28
|
+
|
29
|
+
unistylesRootNode->removeUnistylesMountTrait();
|
30
|
+
|
31
|
+
auto& registry = core::UnistylesRegistry::get();
|
29
32
|
auto shadowLeafUpdates = this->getUnistylesUpdates();
|
30
33
|
|
31
34
|
if (shadowLeafUpdates.size() == 0) {
|
32
35
|
return newRootShadowNode;
|
33
36
|
}
|
37
|
+
|
38
|
+
// this is required, otherwise we end up with old shadow tree in mount hook
|
39
|
+
registry.trafficController.stopUnistylesTraffic();
|
34
40
|
|
35
41
|
auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
|
36
42
|
|
@@ -12,13 +12,27 @@ void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &
|
|
12
12
|
auto rootNode = std::const_pointer_cast<RootShadowNode>(rootShadowNode);
|
13
13
|
auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(rootNode);
|
14
14
|
|
15
|
-
//
|
15
|
+
// if this is Unistyles commit, do nothing
|
16
16
|
if (unistylesRootNode->hasUnistylesMountTrait()) {
|
17
17
|
unistylesRootNode->removeUnistylesMountTrait();
|
18
18
|
|
19
19
|
return;
|
20
20
|
}
|
21
21
|
|
22
|
+
// this is React Native commit
|
23
|
+
auto& registry = core::UnistylesRegistry::get();
|
24
|
+
|
25
|
+
registry.trafficController.resumeUnistylesTraffic();
|
26
|
+
|
27
|
+
// this will prevent crash when re-rendering view
|
28
|
+
// as Unistyles has nothing to commit yet, but dependency map
|
29
|
+
// will build all the shadow nodes
|
30
|
+
if (!registry.trafficController.hasUnistylesCommit()) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
34
|
+
registry.trafficController.setHasUnistylesCommit(false);
|
35
|
+
|
22
36
|
auto shadowLeafUpdates = this->getUnistylesUpdates();
|
23
37
|
|
24
38
|
if (shadowLeafUpdates.size() == 0) {
|
@@ -11,6 +11,7 @@
|
|
11
11
|
#include "StyleSheet.h"
|
12
12
|
#include "Unistyle.h"
|
13
13
|
#include "UnistyleData.h"
|
14
|
+
#include "ShadowTrafficController.h"
|
14
15
|
|
15
16
|
namespace margelo::nitro::unistyles::core {
|
16
17
|
|
@@ -40,7 +41,8 @@ struct UnistylesRegistry: public StyleSheetRegistry {
|
|
40
41
|
std::shared_ptr<core::StyleSheet> addStyleSheet(jsi::Runtime& rt, int tag, core::StyleSheetType type, jsi::Object&& rawValue);
|
41
42
|
DependencyMap buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps);
|
42
43
|
DependencyMap buildDependencyMap(jsi::Runtime& rt);
|
43
|
-
|
44
|
+
shadow::ShadowTrafficController trafficController{};
|
45
|
+
|
44
46
|
private:
|
45
47
|
UnistylesRegistry() = default;
|
46
48
|
|
@@ -35,6 +35,8 @@ jsi::Value HybridStyleSheet::create(jsi::Runtime& rt, const jsi::Value &thisVal,
|
|
35
35
|
auto style = std::make_shared<core::HostStyle>(registeredStyleSheet, this->_unistylesRuntime);
|
36
36
|
auto styleHostObject = jsi::Object::createFromHostObject(rt, style);
|
37
37
|
|
38
|
+
registry.trafficController.setHasUnistylesCommit(true);
|
39
|
+
|
38
40
|
return styleHostObject;
|
39
41
|
}
|
40
42
|
|
@@ -192,7 +192,7 @@ jsi::Value HybridUnistylesRuntime::getMiniRuntimeAsValue(jsi::Runtime& rt) {
|
|
192
192
|
obj.setProperty(rt, "rtl", JSIConverter<bool>::toJSI(rt, miniRuntime.rtl));
|
193
193
|
obj.setProperty(rt, "statusBar", JSIConverter<Dimensions>::toJSI(rt, miniRuntime.statusBar));
|
194
194
|
obj.setProperty(rt, "navigationBar", JSIConverter<Dimensions>::toJSI(rt, miniRuntime.navigationBar));
|
195
|
-
|
195
|
+
|
196
196
|
return obj;
|
197
197
|
}
|
198
198
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
namespace margelo::nitro::unistyles::shadow {
|
4
|
+
|
5
|
+
// Like a traffic officer managing a jam, this struct ensures everything
|
6
|
+
// is synchronized within a set timeframe, controlling flow and preventing chaos.
|
7
|
+
struct ShadowTrafficController {
|
8
|
+
inline bool hasUnistylesCommit() {
|
9
|
+
return _hasCommit;
|
10
|
+
}
|
11
|
+
|
12
|
+
inline void setHasUnistylesCommit(bool hasCommit) {
|
13
|
+
this->_hasCommit = hasCommit;
|
14
|
+
}
|
15
|
+
|
16
|
+
inline bool shouldStop() {
|
17
|
+
return !_canCommit;
|
18
|
+
}
|
19
|
+
|
20
|
+
inline void stopUnistylesTraffic() {
|
21
|
+
this->_canCommit = false;
|
22
|
+
}
|
23
|
+
|
24
|
+
inline void resumeUnistylesTraffic() {
|
25
|
+
this->_canCommit = true;
|
26
|
+
}
|
27
|
+
|
28
|
+
private:
|
29
|
+
bool _hasCommit = false;
|
30
|
+
bool _canCommit = false;
|
31
|
+
};
|
32
|
+
|
33
|
+
}
|
@@ -9,6 +9,13 @@ using AffectedNodes = std::unordered_map<const ShadowNodeFamily*, std::unordered
|
|
9
9
|
void shadow::ShadowTreeManager::updateShadowTree(facebook::jsi::Runtime& rt, shadow::ShadowLeafUpdates& updates) {
|
10
10
|
auto& uiManager = UIManagerBinding::getBinding(rt)->getUIManager();
|
11
11
|
const auto &shadowTreeRegistry = uiManager.getShadowTreeRegistry();
|
12
|
+
auto& registry = core::UnistylesRegistry::get();
|
13
|
+
|
14
|
+
if (registry.trafficController.shouldStop()) {
|
15
|
+
registry.trafficController.setHasUnistylesCommit(true);
|
16
|
+
|
17
|
+
return;
|
18
|
+
}
|
12
19
|
|
13
20
|
shadowTreeRegistry.enumerate([&updates, &rt](const ShadowTree& shadowTree, bool& stop){
|
14
21
|
// we could iterate via updates and create multiple commits
|
@@ -15,7 +15,7 @@ const findShadowNodeForHandle = handle => {
|
|
15
15
|
return node;
|
16
16
|
};
|
17
17
|
HybridShadowRegistry.add = (handle, style, variants, args) => {
|
18
|
-
if (!handle) {
|
18
|
+
if (!handle || typeof style !== 'object') {
|
19
19
|
return;
|
20
20
|
}
|
21
21
|
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","link","remove","__unid","unlink","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAaA,MAAMC,oBAAoB,GAAGC,qCAAY,CAACC,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDL,oBAAoB,CAACW,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,EAAEC,IAAI,KAAK;EAC1D,IAAI,CAACV,MAAM,EAAE;
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","HybridShadowRegistry","NitroModules","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","link","remove","__unid","unlink","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAaA,MAAMC,oBAAoB,GAAGC,qCAAY,CAACC,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDL,oBAAoB,CAACW,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,EAAEC,IAAI,KAAK;EAC1D,IAAI,CAACV,MAAM,IAAI,OAAOQ,KAAK,KAAK,QAAQ,EAAE;IACtC;EACJ;EAEAZ,oBAAoB,CAACe,IAAI,CAACZ,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,CAAC;AACjG,CAAC;AAEDd,oBAAoB,CAACgB,MAAM,GAAG,CAACZ,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEK,MAAM,EAAE;IAC3B;EACJ;EAEAjB,oBAAoB,CAACkB,MAAM,CAACf,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQM,MAAMO,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAGnB,oBAA4D","ignoreList":[]}
|
@@ -11,7 +11,7 @@ const findShadowNodeForHandle = handle => {
|
|
11
11
|
return node;
|
12
12
|
};
|
13
13
|
HybridShadowRegistry.add = (handle, style, variants, args) => {
|
14
|
-
if (!handle) {
|
14
|
+
if (!handle || typeof style !== 'object') {
|
15
15
|
return;
|
16
16
|
}
|
17
17
|
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? []);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","link","remove","__unid","unlink","UnistylesShadowRegistry"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAazD,MAAMC,oBAAoB,GAAGD,YAAY,CAACE,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDJ,oBAAoB,CAACU,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,EAAEC,IAAI,KAAK;EAC1D,IAAI,CAACV,MAAM,EAAE;
|
1
|
+
{"version":3,"names":["NitroModules","HybridShadowRegistry","createHybridObject","findShadowNodeForHandle","handle","node","__internalInstanceHandle","stateNode","getScrollResponder","getNativeScrollRef","Error","add","style","variants","args","link","remove","__unid","unlink","UnistylesShadowRegistry"],"sourceRoot":"../../../../src","sources":["specs/ShadowRegistry/index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAazD,MAAMC,oBAAoB,GAAGD,YAAY,CAACE,kBAAkB,CAAiB,yBAAyB,CAAC;AAEvG,MAAMC,uBAAuB,GAAIC,MAAkB,IAAK;EACpD,MAAMC,IAAI,GAAGD,MAAM,EAAEE,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACvDD,MAAM,EAAEI,kBAAkB,GAAG,CAAC,EAAEC,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI,IACjGD,MAAM,EAAEK,kBAAkB,GAAG,CAAC,EAAEH,wBAAwB,EAAEC,SAAS,EAAEF,IAAI;EAEhF,IAAI,CAACA,IAAI,EAAE;IACP;IACA,MAAM,IAAIK,KAAK,CAAC,uDAAuD,CAAC;EAC5E;EAEA,OAAOL,IAAI;AACf,CAAC;AAEDJ,oBAAoB,CAACU,GAAG,GAAG,CAACP,MAAM,EAAEQ,KAAK,EAAEC,QAAQ,EAAEC,IAAI,KAAK;EAC1D,IAAI,CAACV,MAAM,IAAI,OAAOQ,KAAK,KAAK,QAAQ,EAAE;IACtC;EACJ;EAEAX,oBAAoB,CAACc,IAAI,CAACZ,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,EAAEC,QAAQ,IAAI,CAAC,CAAC,EAAEC,IAAI,IAAI,EAAE,CAAC;AACjG,CAAC;AAEDb,oBAAoB,CAACe,MAAM,GAAG,CAACZ,MAAM,EAAEQ,KAAK,KAAK;EAC7C,IAAI,CAACR,MAAM,IAAI,CAACQ,KAAK,EAAEK,MAAM,EAAE;IAC3B;EACJ;EAEAhB,oBAAoB,CAACiB,MAAM,CAACf,uBAAuB,CAACC,MAAM,CAAC,EAAEQ,KAAK,CAAC;AACvE,CAAC;AAQD,OAAO,MAAMO,uBAAuB,GAAGlB,oBAA4D","ignoreList":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../../example/App.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,aAAa,CAAA;AAGpB,eAAO,MAAM,GAAG,
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../../example/App.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,aAAa,CAAA;AAGpB,eAAO,MAAM,GAAG,yBAcf,CAAA"}
|
package/package.json
CHANGED