react-native-unistyles 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/android/src/main/cxx/NativeUnistylesModule.cpp +2 -5
- package/android/src/main/cxx/NativeUnistylesModule.h +1 -7
- package/android/src/main/java/com/unistyles/Equatable.kt +5 -1
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +6 -1
- package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +21 -3
- package/cxx/core/UnistyleWrapper.h +2 -2
- package/cxx/core/UnistylesRegistry.cpp +57 -48
- package/cxx/core/UnistylesRegistry.h +16 -14
- package/cxx/core/UnistylesState.cpp +22 -20
- package/cxx/core/UnistylesState.h +5 -6
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +14 -3
- package/cxx/hybridObjects/HybridShadowRegistry.h +5 -0
- package/cxx/hybridObjects/HybridStyleSheet.cpp +71 -45
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +22 -32
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +3 -4
- package/cxx/parser/Parser.cpp +14 -14
- package/ios/UnistylesModuleOnLoad.mm +3 -10
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +4 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +20 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/web/convert/style.js +6 -6
- package/lib/commonjs/web/convert/style.js.map +1 -1
- package/lib/commonjs/web/listener.js +6 -0
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/utils/createUnistylesRef.js +1 -1
- package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +4 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +20 -1
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/web/convert/style.js +6 -6
- package/lib/module/web/convert/style.js.map +1 -1
- package/lib/module/web/listener.js +6 -0
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/utils/createUnistylesRef.js +1 -1
- package/lib/module/web/utils/createUnistylesRef.js.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
- package/nitrogen/generated/android/c++/JDimensions.hpp +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +2 -2
- package/nitrogen/generated/android/c++/JInsets.hpp +1 -1
- package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +1 -1
- package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +1 -1
- package/package.json +3 -3
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +4 -1
- package/src/specs/ShadowRegistry/index.ts +36 -2
- package/src/web/convert/style.ts +6 -6
- package/src/web/listener.ts +6 -0
- package/src/web/utils/createUnistylesRef.ts +1 -1
|
@@ -61,7 +61,7 @@ jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisV
|
|
|
61
61
|
|
|
62
62
|
verifyAndSelectTheme(rt);
|
|
63
63
|
|
|
64
|
-
auto& state = core::UnistylesRegistry::get().getState(
|
|
64
|
+
auto& state = core::UnistylesRegistry::get().getState();
|
|
65
65
|
|
|
66
66
|
state.hasUserConfig = true;
|
|
67
67
|
|
|
@@ -76,7 +76,7 @@ jsi::Value HybridStyleSheet::init(jsi::Runtime &rt, const jsi::Value &thisVal, c
|
|
|
76
76
|
// create new state
|
|
77
77
|
auto& registry = core::UnistylesRegistry::get();
|
|
78
78
|
|
|
79
|
-
registry.createState(
|
|
79
|
+
registry.createState();
|
|
80
80
|
|
|
81
81
|
loadExternalMethods(thisVal, rt);
|
|
82
82
|
|
|
@@ -95,7 +95,7 @@ void HybridStyleSheet::parseSettings(jsi::Runtime &rt, jsi::Object settings) {
|
|
|
95
95
|
if (propertyName == "adaptiveThemes") {
|
|
96
96
|
helpers::assertThat(rt, propertyValue.isBool(), "StyleSheet.configure's adaptiveThemes must be of boolean type.");
|
|
97
97
|
|
|
98
|
-
registry.setPrefersAdaptiveThemes(
|
|
98
|
+
registry.setPrefersAdaptiveThemes(propertyValue.asBool());
|
|
99
99
|
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
@@ -108,12 +108,12 @@ void HybridStyleSheet::parseSettings(jsi::Runtime &rt, jsi::Object settings) {
|
|
|
108
108
|
|
|
109
109
|
helpers::assertThat(rt, result.isString(), "StyleSheet.configure's initialTheme resolved from function is not a string. Please check your initialTheme function.");
|
|
110
110
|
|
|
111
|
-
return registry.setInitialThemeName(
|
|
111
|
+
return registry.setInitialThemeName(result.asString(rt).utf8(rt));
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
helpers::assertThat(rt, propertyValue.isString(), "StyleSheet.configure's initialTheme must be either a string or a function.");
|
|
115
115
|
|
|
116
|
-
registry.setInitialThemeName(
|
|
116
|
+
registry.setInitialThemeName(propertyValue.asString(rt).utf8(rt));
|
|
117
117
|
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
@@ -147,9 +147,9 @@ void HybridStyleSheet::parseBreakpoints(jsi::Runtime &rt, jsi::Object breakpoint
|
|
|
147
147
|
helpers::assertThat(rt, sortedBreakpoints.front().second == 0, "StyleSheet.configure's first breakpoint must start from 0.");
|
|
148
148
|
|
|
149
149
|
auto& registry = core::UnistylesRegistry::get();
|
|
150
|
-
auto& state = registry.getState(
|
|
150
|
+
auto& state = registry.getState();
|
|
151
151
|
|
|
152
|
-
registry.registerBreakpoints(
|
|
152
|
+
registry.registerBreakpoints(sortedBreakpoints);
|
|
153
153
|
|
|
154
154
|
auto rawWidth = this->_unistylesRuntime->getScreen().width;
|
|
155
155
|
auto width = registry.shouldUsePointsForBreakpoints
|
|
@@ -170,7 +170,7 @@ void HybridStyleSheet::parseThemes(jsi::Runtime &rt, jsi::Object themes) {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
void HybridStyleSheet::verifyAndSelectTheme(jsi::Runtime &rt) {
|
|
173
|
-
auto& state = core::UnistylesRegistry::get().getState(
|
|
173
|
+
auto& state = core::UnistylesRegistry::get().getState();
|
|
174
174
|
|
|
175
175
|
bool hasInitialTheme = state.hasInitialTheme();
|
|
176
176
|
bool prefersAdaptiveThemes = state.getPrefersAdaptiveThemes();
|
|
@@ -217,7 +217,7 @@ void HybridStyleSheet::verifyAndSelectTheme(jsi::Runtime &rt) {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
void HybridStyleSheet::setThemeFromColorScheme(jsi::Runtime& rt) {
|
|
220
|
-
auto& state = core::UnistylesRegistry::get().getState(
|
|
220
|
+
auto& state = core::UnistylesRegistry::get().getState();
|
|
221
221
|
auto colorScheme = static_cast<ColorScheme>(this->_unistylesRuntime->getColorScheme());
|
|
222
222
|
|
|
223
223
|
switch (colorScheme) {
|
|
@@ -250,7 +250,7 @@ void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Run
|
|
|
250
250
|
auto processColorFn = maybeProcessColorFn.asObject(rt).asFunction(rt);
|
|
251
251
|
auto parseBoxShadowStringFn = maybeParseBoxShadowStringFn.asObject(rt).asFunction(rt);
|
|
252
252
|
auto& registry = core::UnistylesRegistry::get();
|
|
253
|
-
auto& state = registry.getState(
|
|
253
|
+
auto& state = registry.getState();
|
|
254
254
|
|
|
255
255
|
state.registerProcessColorFunction(std::move(processColorFn));
|
|
256
256
|
state.registerParseBoxShadowString(std::move(parseBoxShadowStringFn));
|
|
@@ -262,32 +262,42 @@ void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependen
|
|
|
262
262
|
return;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
auto
|
|
266
|
-
auto& rt = this->_unistylesRuntime->getRuntime();
|
|
267
|
-
auto parser = parser::Parser(this->_unistylesRuntime);
|
|
268
|
-
auto dependencyMap = registry.buildDependencyMap(rt, dependencies);
|
|
265
|
+
auto weakSelf = weak_from_this();
|
|
269
266
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
267
|
+
this->_unistylesRuntime->runOnJSThread([weakSelf, dependencies](jsi::Runtime& rt) {
|
|
268
|
+
auto self = std::dynamic_pointer_cast<HybridStyleSheet>(weakSelf.lock());
|
|
273
269
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
auto dependentStyleSheets = registry.getStyleSheetsToRefresh(rt, dependencies);
|
|
270
|
+
if (!self) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
278
273
|
|
|
279
|
-
|
|
274
|
+
auto& registry = core::UnistylesRegistry::get();
|
|
275
|
+
auto parser = parser::Parser(self->_unistylesRuntime);
|
|
276
|
+
auto unistyleDependencies = dependencies;
|
|
277
|
+
auto dependencyMap = registry.buildDependencyMap(unistyleDependencies);
|
|
280
278
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
279
|
+
if (dependencyMap.empty()) {
|
|
280
|
+
self->notifyJSListeners(unistyleDependencies);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// in a later step, we will rebuild only Unistyles with mounted StyleSheets
|
|
284
|
+
// however, user may have StyleSheets with components that haven't mounted yet
|
|
285
|
+
// we need to rebuild all dependent StyleSheets as well
|
|
286
|
+
auto dependentStyleSheets = registry.getStyleSheetsToRefresh(unistyleDependencies);
|
|
287
|
+
|
|
288
|
+
parser.rebuildUnistylesInDependencyMap(rt, dependencyMap, dependentStyleSheets, std::nullopt);
|
|
289
|
+
|
|
290
|
+
// we need to stop here if there is nothing to update at the moment,
|
|
291
|
+
// but we need to compute dependentStyleSheets
|
|
292
|
+
if (dependencyMap.empty()) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
286
295
|
|
|
287
|
-
|
|
296
|
+
parser.rebuildShadowLeafUpdates(rt, dependencyMap);
|
|
288
297
|
|
|
289
|
-
|
|
290
|
-
|
|
298
|
+
self->notifyJSListeners(unistyleDependencies);
|
|
299
|
+
shadow::ShadowTreeManager::updateShadowTree(rt);
|
|
300
|
+
});
|
|
291
301
|
}
|
|
292
302
|
|
|
293
303
|
void HybridStyleSheet::onPlatformNativeDependenciesChange(std::vector<UnistyleDependency> dependencies, UnistylesNativeMiniRuntime miniRuntime) {
|
|
@@ -296,21 +306,29 @@ void HybridStyleSheet::onPlatformNativeDependenciesChange(std::vector<UnistyleDe
|
|
|
296
306
|
return;
|
|
297
307
|
}
|
|
298
308
|
|
|
299
|
-
|
|
309
|
+
auto weakSelf = weak_from_this();
|
|
310
|
+
|
|
311
|
+
this->_unistylesRuntime->runOnJSThread([weakSelf, dependencies, miniRuntime](jsi::Runtime& rt){
|
|
312
|
+
auto self = std::dynamic_pointer_cast<HybridStyleSheet>(weakSelf.lock());
|
|
313
|
+
|
|
314
|
+
if (!self) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
300
318
|
auto& registry = core::UnistylesRegistry::get();
|
|
301
|
-
auto parser = parser::Parser(
|
|
319
|
+
auto parser = parser::Parser(self->_unistylesRuntime);
|
|
302
320
|
auto unistyleDependencies = std::move(dependencies);
|
|
303
321
|
|
|
304
322
|
// re-compute new breakpoint
|
|
305
323
|
auto dimensionsIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::DIMENSIONS);
|
|
306
324
|
|
|
307
325
|
if (dimensionsIt != dependencies.end()) {
|
|
308
|
-
auto rawWidth =
|
|
326
|
+
auto rawWidth = self->_unistylesRuntime->getScreen().width;
|
|
309
327
|
auto width = registry.shouldUsePointsForBreakpoints
|
|
310
|
-
? rawWidth /
|
|
328
|
+
? rawWidth / self->_unistylesRuntime->getPixelRatio()
|
|
311
329
|
: rawWidth;
|
|
312
330
|
|
|
313
|
-
registry.getState(
|
|
331
|
+
registry.getState().computeCurrentBreakpoint(width);
|
|
314
332
|
}
|
|
315
333
|
|
|
316
334
|
// check if color scheme changed and then if Unistyles state depend on it (adaptive themes)
|
|
@@ -318,19 +336,19 @@ void HybridStyleSheet::onPlatformNativeDependenciesChange(std::vector<UnistyleDe
|
|
|
318
336
|
auto hasNewColorScheme = colorSchemeIt != dependencies.end();
|
|
319
337
|
|
|
320
338
|
if (hasNewColorScheme) {
|
|
321
|
-
|
|
339
|
+
self->_unistylesRuntime->includeDependenciesForColorSchemeChange(unistyleDependencies);
|
|
322
340
|
}
|
|
323
341
|
|
|
324
|
-
auto dependencyMap = registry.buildDependencyMap(
|
|
342
|
+
auto dependencyMap = registry.buildDependencyMap(unistyleDependencies);
|
|
325
343
|
|
|
326
344
|
if (dependencyMap.empty()) {
|
|
327
|
-
|
|
345
|
+
self->notifyJSListeners(unistyleDependencies);
|
|
328
346
|
}
|
|
329
347
|
|
|
330
348
|
// in a later step, we will rebuild only Unistyles with mounted StyleSheets
|
|
331
349
|
// however, user may have StyleSheets with components that haven't mounted yet
|
|
332
350
|
// we need to rebuild all dependent StyleSheets as well
|
|
333
|
-
auto dependentStyleSheets = registry.getStyleSheetsToRefresh(
|
|
351
|
+
auto dependentStyleSheets = registry.getStyleSheetsToRefresh(unistyleDependencies);
|
|
334
352
|
|
|
335
353
|
parser.rebuildUnistylesInDependencyMap(rt, dependencyMap, dependentStyleSheets, miniRuntime);
|
|
336
354
|
|
|
@@ -342,7 +360,7 @@ void HybridStyleSheet::onPlatformNativeDependenciesChange(std::vector<UnistyleDe
|
|
|
342
360
|
|
|
343
361
|
parser.rebuildShadowLeafUpdates(rt, dependencyMap);
|
|
344
362
|
|
|
345
|
-
|
|
363
|
+
self->notifyJSListeners(unistyleDependencies);
|
|
346
364
|
shadow::ShadowTreeManager::updateShadowTree(rt);
|
|
347
365
|
});
|
|
348
366
|
}
|
|
@@ -352,14 +370,22 @@ void HybridStyleSheet::onImeChange(UnistylesNativeMiniRuntime miniRuntime) {
|
|
|
352
370
|
return;
|
|
353
371
|
}
|
|
354
372
|
|
|
355
|
-
|
|
373
|
+
auto weakSelf = weak_from_this();
|
|
374
|
+
|
|
375
|
+
this->_unistylesRuntime->runOnJSThread([weakSelf, miniRuntime](jsi::Runtime& rt){
|
|
376
|
+
auto self = std::dynamic_pointer_cast<HybridStyleSheet>(weakSelf.lock());
|
|
377
|
+
|
|
378
|
+
if (!self) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
356
382
|
std::vector<UnistyleDependency> dependencies{UnistyleDependency::IME};
|
|
357
383
|
auto& registry = core::UnistylesRegistry::get();
|
|
358
|
-
auto parser = parser::Parser(
|
|
359
|
-
auto dependencyMap = registry.buildDependencyMap(
|
|
384
|
+
auto parser = parser::Parser(self->_unistylesRuntime);
|
|
385
|
+
auto dependencyMap = registry.buildDependencyMap(dependencies);
|
|
360
386
|
|
|
361
387
|
if (dependencyMap.empty()) {
|
|
362
|
-
|
|
388
|
+
self->notifyJSListeners(dependencies);
|
|
363
389
|
|
|
364
390
|
return;
|
|
365
391
|
}
|
|
@@ -371,7 +397,7 @@ void HybridStyleSheet::onImeChange(UnistylesNativeMiniRuntime miniRuntime) {
|
|
|
371
397
|
parser.rebuildUnistylesInDependencyMap(rt, dependencyMap, dependentStyleSheets, miniRuntime);
|
|
372
398
|
parser.rebuildShadowLeafUpdates(rt, dependencyMap);
|
|
373
399
|
|
|
374
|
-
|
|
400
|
+
self->notifyJSListeners(dependencies);
|
|
375
401
|
shadow::ShadowTreeManager::updateShadowTree(rt);
|
|
376
402
|
});
|
|
377
403
|
}
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
using namespace margelo::nitro::unistyles;
|
|
5
5
|
|
|
6
|
+
core::UnistylesState& HybridUnistylesRuntime::getState() {
|
|
7
|
+
return core::UnistylesRegistry::get().getState();
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
ColorScheme HybridUnistylesRuntime::getColorScheme() {
|
|
7
11
|
auto colorScheme = this->_nativePlatform->getColorScheme();
|
|
8
12
|
|
|
@@ -10,9 +14,7 @@ ColorScheme HybridUnistylesRuntime::getColorScheme() {
|
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
bool HybridUnistylesRuntime::getHasAdaptiveThemes() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return state.hasAdaptiveThemes();
|
|
17
|
+
return this->getState().hasAdaptiveThemes();
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
Dimensions HybridUnistylesRuntime::getScreen() {
|
|
@@ -22,14 +24,12 @@ Dimensions HybridUnistylesRuntime::getScreen() {
|
|
|
22
24
|
std::optional<std::string> HybridUnistylesRuntime::getThemeName() {
|
|
23
25
|
auto& registry = core::UnistylesRegistry::get();
|
|
24
26
|
auto maybeScopedTheme = registry.getScopedTheme();
|
|
25
|
-
|
|
27
|
+
|
|
26
28
|
if (maybeScopedTheme.has_value()) {
|
|
27
29
|
return maybeScopedTheme.value();
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return state.getCurrentThemeName();
|
|
31
|
+
|
|
32
|
+
return this->getState().getCurrentThemeName();
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
std::string HybridUnistylesRuntime::getContentSizeCategory() {
|
|
@@ -37,9 +37,7 @@ std::string HybridUnistylesRuntime::getContentSizeCategory() {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
std::optional<std::string> HybridUnistylesRuntime::getBreakpoint() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return state.getCurrentBreakpointName();
|
|
40
|
+
return this->getState().getCurrentBreakpointName();
|
|
43
41
|
};
|
|
44
42
|
|
|
45
43
|
bool HybridUnistylesRuntime::getRtl() {
|
|
@@ -73,8 +71,7 @@ double HybridUnistylesRuntime::getFontScale() {
|
|
|
73
71
|
};
|
|
74
72
|
|
|
75
73
|
std::unordered_map<std::string, double> HybridUnistylesRuntime::getBreakpoints() {
|
|
76
|
-
auto
|
|
77
|
-
auto sortedBreakpointPairs = state.getSortedBreakpointPairs();
|
|
74
|
+
auto sortedBreakpointPairs = this->getState().getSortedBreakpointPairs();
|
|
78
75
|
std::unordered_map<std::string, double> breakpoints{};
|
|
79
76
|
|
|
80
77
|
std::for_each(sortedBreakpointPairs.begin(), sortedBreakpointPairs.end(), [&breakpoints](std::pair<std::string, double>& pair){
|
|
@@ -85,12 +82,13 @@ std::unordered_map<std::string, double> HybridUnistylesRuntime::getBreakpoints()
|
|
|
85
82
|
}
|
|
86
83
|
|
|
87
84
|
void HybridUnistylesRuntime::setTheme(const std::string &themeName) {
|
|
88
|
-
|
|
85
|
+
if (this->getHasAdaptiveThemes()) {
|
|
86
|
+
throw std::runtime_error("Unistyles: You're trying to set theme to: '" + themeName + "', but adaptiveThemes are enabled.");
|
|
87
|
+
}
|
|
89
88
|
|
|
90
|
-
auto
|
|
91
|
-
auto currentThemeName = state.getCurrentThemeName();
|
|
89
|
+
auto currentThemeName = this->getState().getCurrentThemeName();
|
|
92
90
|
|
|
93
|
-
|
|
91
|
+
this->getState().setTheme(themeName);
|
|
94
92
|
|
|
95
93
|
if (currentThemeName.value() != themeName) {
|
|
96
94
|
this->_onDependenciesChange({UnistyleDependency::THEME, UnistyleDependency::THEMENAME});
|
|
@@ -106,7 +104,7 @@ void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
|
|
|
106
104
|
|
|
107
105
|
bool hadAdaptiveThemes = this->getHasAdaptiveThemes();
|
|
108
106
|
|
|
109
|
-
registry.setPrefersAdaptiveThemes(
|
|
107
|
+
registry.setPrefersAdaptiveThemes(isEnabled);
|
|
110
108
|
|
|
111
109
|
bool haveAdaptiveThemes = this->getHasAdaptiveThemes();
|
|
112
110
|
|
|
@@ -128,7 +126,6 @@ void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
|
|
|
128
126
|
};
|
|
129
127
|
|
|
130
128
|
void HybridUnistylesRuntime::calculateNewThemeAndDependencies(std::vector<UnistyleDependency>& changedDependencies) {
|
|
131
|
-
auto& state = core::UnistylesRegistry::get().getState(*_rt);
|
|
132
129
|
auto colorScheme = this->getColorScheme();
|
|
133
130
|
auto currentThemeName = this->getThemeName();
|
|
134
131
|
auto nextTheme = colorScheme == ColorScheme::LIGHT
|
|
@@ -139,18 +136,18 @@ void HybridUnistylesRuntime::calculateNewThemeAndDependencies(std::vector<Unisty
|
|
|
139
136
|
changedDependencies.push_back(UnistyleDependency::THEME);
|
|
140
137
|
changedDependencies.push_back(UnistyleDependency::THEMENAME);
|
|
141
138
|
|
|
142
|
-
|
|
139
|
+
this->getState().setTheme(nextTheme);
|
|
143
140
|
}
|
|
144
141
|
}
|
|
145
142
|
|
|
146
143
|
jsi::Value HybridUnistylesRuntime::getTheme(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
147
144
|
helpers::assertThat(rt, count <= 1, "UnistylesRuntime.getTheme expected to be called with 0 or 1 argument.");
|
|
148
145
|
|
|
149
|
-
auto& state =
|
|
146
|
+
auto& state = this->getState();
|
|
150
147
|
|
|
151
148
|
if (count == 1) {
|
|
152
149
|
if (args[0].isUndefined()) {
|
|
153
|
-
return state.getCurrentJSTheme();
|
|
150
|
+
return state.getCurrentJSTheme(rt);
|
|
154
151
|
}
|
|
155
152
|
|
|
156
153
|
helpers::assertThat(rt, args[0].isString(), "UnistylesRuntime.getTheme expected to be called with string.");
|
|
@@ -159,10 +156,10 @@ jsi::Value HybridUnistylesRuntime::getTheme(jsi::Runtime &rt, const jsi::Value &
|
|
|
159
156
|
|
|
160
157
|
helpers::assertThat(rt, state.hasTheme(themeName), "Unistyles: You're trying to get theme '" + themeName + "' but it wasn't registered.");
|
|
161
158
|
|
|
162
|
-
return state.getJSThemeByName(themeName);
|
|
159
|
+
return state.getJSThemeByName(rt, themeName);
|
|
163
160
|
}
|
|
164
161
|
|
|
165
|
-
return state.getCurrentJSTheme();
|
|
162
|
+
return state.getCurrentJSTheme(rt);
|
|
166
163
|
}
|
|
167
164
|
|
|
168
165
|
jsi::Value HybridUnistylesRuntime::updateTheme(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
@@ -292,17 +289,10 @@ void HybridUnistylesRuntime::unregisterNativePlatformListeners() {
|
|
|
292
289
|
}
|
|
293
290
|
|
|
294
291
|
void HybridUnistylesRuntime::includeDependenciesForColorSchemeChange(std::vector<UnistyleDependency>& deps) {
|
|
295
|
-
auto& registry = core::UnistylesRegistry::get();
|
|
296
|
-
auto& state = registry.getState(*this->_rt);
|
|
297
|
-
|
|
298
292
|
// ignore color scheme changes if user has no adaptive themes
|
|
299
|
-
if (!
|
|
293
|
+
if (!this->getState().hasAdaptiveThemes()) {
|
|
300
294
|
return;
|
|
301
295
|
}
|
|
302
296
|
|
|
303
297
|
this->calculateNewThemeAndDependencies(deps);
|
|
304
298
|
}
|
|
305
|
-
|
|
306
|
-
jsi::Runtime& HybridUnistylesRuntime::getRuntime() {
|
|
307
|
-
return *this->_rt;
|
|
308
|
-
}
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
namespace margelo::nitro::unistyles {
|
|
14
14
|
|
|
15
15
|
struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
|
|
16
|
-
HybridUnistylesRuntime(std::shared_ptr<HybridNativePlatformSpec> nativePlatform,
|
|
17
|
-
: HybridObject(TAG), _nativePlatform{nativePlatform},
|
|
16
|
+
HybridUnistylesRuntime(std::shared_ptr<HybridNativePlatformSpec> nativePlatform, std::function<void(std::function<void(jsi::Runtime&)>&&)> runOnJSThread)
|
|
17
|
+
: HybridObject(TAG), _nativePlatform{nativePlatform}, runOnJSThread(std::move(runOnJSThread)) {}
|
|
18
18
|
|
|
19
19
|
jsi::Value getTheme(jsi::Runtime& rt,
|
|
20
20
|
const jsi::Value& thisValue,
|
|
@@ -69,7 +69,7 @@ struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
|
|
|
69
69
|
UnistylesCxxMiniRuntime getMiniRuntime() override;
|
|
70
70
|
std::unordered_map<std::string, double> getBreakpoints() override;
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
core::UnistylesState& getState();
|
|
73
73
|
UnistylesCxxMiniRuntime buildMiniRuntimeFromNativeRuntime(UnistylesNativeMiniRuntime& nativeMiniRuntime);
|
|
74
74
|
jsi::Value getMiniRuntimeAsValue(jsi::Runtime& rt, std::optional<UnistylesNativeMiniRuntime> maybeMiniRuntime);
|
|
75
75
|
void includeDependenciesForColorSchemeChange(std::vector<UnistyleDependency>& deps);
|
|
@@ -77,7 +77,6 @@ struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
|
|
|
77
77
|
std::function<void(std::function<void(jsi::Runtime&)>&&)> runOnJSThread;
|
|
78
78
|
|
|
79
79
|
private:
|
|
80
|
-
jsi::Runtime* _rt;
|
|
81
80
|
std::shared_ptr<HybridNavigationBar> _navigationBar;
|
|
82
81
|
std::shared_ptr<HybridStatusBar> _statusBar;
|
|
83
82
|
std::shared_ptr<HybridNativePlatformSpec> _nativePlatform;
|
package/cxx/parser/Parser.cpp
CHANGED
|
@@ -101,8 +101,8 @@ jsi::Value parser::Parser::getParsedStyleSheetForScopedTheme(jsi::Runtime& rt, c
|
|
|
101
101
|
return jsi::Value::undefined();
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
auto& state = core::UnistylesRegistry::get().getState(
|
|
105
|
-
auto jsTheme = state.getJSThemeByName(scopedTheme);
|
|
104
|
+
auto& state = core::UnistylesRegistry::get().getState();
|
|
105
|
+
auto jsTheme = state.getJSThemeByName(rt, scopedTheme);
|
|
106
106
|
|
|
107
107
|
if (unistyle->parent->type == StyleSheetType::Themable) {
|
|
108
108
|
return unistyle->parent->rawValue
|
|
@@ -184,8 +184,8 @@ jsi::Object parser::Parser::unwrapStyleSheet(jsi::Runtime& rt, std::shared_ptr<S
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
// StyleSheet is a function
|
|
187
|
-
auto& state = core::UnistylesRegistry::get().getState(
|
|
188
|
-
auto theme = state.getCurrentJSTheme();
|
|
187
|
+
auto& state = core::UnistylesRegistry::get().getState();
|
|
188
|
+
auto theme = state.getCurrentJSTheme(rt);
|
|
189
189
|
|
|
190
190
|
if (styleSheet->type == StyleSheetType::Themable) {
|
|
191
191
|
return styleSheet->rawValue
|
|
@@ -497,7 +497,7 @@ jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared u
|
|
|
497
497
|
|
|
498
498
|
if (propertyValue.isBool() && propertyName == "includeFontPadding") {
|
|
499
499
|
parsedStyle.setProperty(rt, jsi::PropNameID::forUtf8(rt, propertyName), propertyValue);
|
|
500
|
-
|
|
500
|
+
|
|
501
501
|
return;
|
|
502
502
|
}
|
|
503
503
|
|
|
@@ -690,9 +690,9 @@ jsi::Value parser::Parser::parseBoxShadow(jsi::Runtime &rt, Unistyle::Shared uni
|
|
|
690
690
|
|
|
691
691
|
jsi::Array parser::Parser::parseBoxShadowString(jsi::Runtime& rt, std::string&& boxShadowString) {
|
|
692
692
|
auto& registry = core::UnistylesRegistry::get();
|
|
693
|
-
auto& state = registry.getState(
|
|
693
|
+
auto& state = registry.getState();
|
|
694
694
|
|
|
695
|
-
return state.parseBoxShadowString(std::move(boxShadowString));
|
|
695
|
+
return state.parseBoxShadowString(rt, std::move(boxShadowString));
|
|
696
696
|
}
|
|
697
697
|
|
|
698
698
|
// eg. [{ brightness: 0.5 }, { opacity: 0.25 }]
|
|
@@ -767,7 +767,7 @@ jsi::Value parser::Parser::parseFilters(jsi::Runtime &rt, Unistyle::Shared unist
|
|
|
767
767
|
// find value based on breakpoints and mq
|
|
768
768
|
jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Object& obj) {
|
|
769
769
|
auto& registry = core::UnistylesRegistry::get();
|
|
770
|
-
auto& state = registry.getState(
|
|
770
|
+
auto& state = registry.getState();
|
|
771
771
|
|
|
772
772
|
auto sortedBreakpoints = state.getSortedBreakpointPairs();
|
|
773
773
|
auto hasBreakpoints = !sortedBreakpoints.empty();
|
|
@@ -1039,7 +1039,7 @@ jsi::Value parser::Parser::parseSecondLevel(jsi::Runtime &rt, Unistyle::Shared u
|
|
|
1039
1039
|
return;
|
|
1040
1040
|
}
|
|
1041
1041
|
|
|
1042
|
-
if (propertyName == "shadowOffset" || propertyName == "textShadowOffset") {
|
|
1042
|
+
if (propertyName == "shadowOffset" || propertyName == "textShadowOffset" || propertyName == "dropShadow") {
|
|
1043
1043
|
parsedStyle.setProperty(rt, propertyName.c_str(), this->parseSecondLevel(rt, unistyle, propertyValue));
|
|
1044
1044
|
|
|
1045
1045
|
return;
|
|
@@ -1052,7 +1052,7 @@ jsi::Value parser::Parser::parseSecondLevel(jsi::Runtime &rt, Unistyle::Shared u
|
|
|
1052
1052
|
// convert unistyles to folly with int colors
|
|
1053
1053
|
folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles) {
|
|
1054
1054
|
jsi::Object convertedStyles(rt);
|
|
1055
|
-
auto& state = core::UnistylesRegistry::get().getState(
|
|
1055
|
+
auto& state = core::UnistylesRegistry::get().getState();
|
|
1056
1056
|
|
|
1057
1057
|
for (const auto& unistyleData : unistyles) {
|
|
1058
1058
|
if (!unistyleData->parsedStyle.has_value()) {
|
|
@@ -1068,7 +1068,7 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
|
|
|
1068
1068
|
convertedStyles.setProperty(
|
|
1069
1069
|
rt,
|
|
1070
1070
|
propertyName.c_str(),
|
|
1071
|
-
jsi::Value(state.parseColor(propertyValue))
|
|
1071
|
+
jsi::Value(state.parseColor(rt, propertyValue))
|
|
1072
1072
|
);
|
|
1073
1073
|
} else {
|
|
1074
1074
|
convertedStyles.setProperty(
|
|
@@ -1124,7 +1124,7 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
|
|
|
1124
1124
|
obj.setProperty(
|
|
1125
1125
|
rt,
|
|
1126
1126
|
nestedPropName.c_str(),
|
|
1127
|
-
state.parseColor(nestedPropValue)
|
|
1127
|
+
state.parseColor(rt, nestedPropValue)
|
|
1128
1128
|
);
|
|
1129
1129
|
} else {
|
|
1130
1130
|
obj.setProperty(
|
|
@@ -1156,7 +1156,7 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
|
|
|
1156
1156
|
parsedNestedObj.setProperty(
|
|
1157
1157
|
rt,
|
|
1158
1158
|
secondLevelPropName.c_str(),
|
|
1159
|
-
state.parseColor(secondLevelPropValue)
|
|
1159
|
+
state.parseColor(rt, secondLevelPropValue)
|
|
1160
1160
|
);
|
|
1161
1161
|
|
|
1162
1162
|
return;
|
|
@@ -1195,7 +1195,7 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
|
|
|
1195
1195
|
parsedArray.setValueAtIndex(
|
|
1196
1196
|
rt,
|
|
1197
1197
|
i,
|
|
1198
|
-
jsi::Value(state.parseColor(nestedValue))
|
|
1198
|
+
jsi::Value(state.parseColor(rt, nestedValue))
|
|
1199
1199
|
);
|
|
1200
1200
|
} else {
|
|
1201
1201
|
parsedArray.setValueAtIndex(rt, i, nestedValue);
|
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
using namespace margelo::nitro;
|
|
8
8
|
|
|
9
|
-
@implementation UnistylesModule
|
|
10
|
-
jsi::Runtime* _runtime;
|
|
11
|
-
}
|
|
9
|
+
@implementation UnistylesModule
|
|
12
10
|
|
|
13
11
|
RCT_EXPORT_MODULE(Unistyles)
|
|
14
12
|
|
|
@@ -17,8 +15,6 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
- (void)installJSIBindingsWithRuntime:(jsi::Runtime&)rt callInvoker:(const std::shared_ptr<facebook::react::CallInvoker> &)callInvoker {
|
|
20
|
-
_runtime = &rt;
|
|
21
|
-
|
|
22
18
|
// function is called on: first init and every live reload
|
|
23
19
|
// check if this is live reload, if so let's replace UnistylesRuntime with new runtime
|
|
24
20
|
auto hasUnistylesRuntime = HybridObjectRegistry::hasHybridObject("UnistylesRuntime");
|
|
@@ -38,7 +34,7 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
|
38
34
|
};
|
|
39
35
|
|
|
40
36
|
auto nativePlatform = Unistyles::NativePlatform::create().getCxxPart();
|
|
41
|
-
auto unistylesRuntime = std::make_shared<HybridUnistylesRuntime>(nativePlatform,
|
|
37
|
+
auto unistylesRuntime = std::make_shared<HybridUnistylesRuntime>(nativePlatform, runOnJSThread);
|
|
42
38
|
auto styleSheet = std::make_shared<HybridStyleSheet>(unistylesRuntime);
|
|
43
39
|
|
|
44
40
|
HybridObjectRegistry::registerHybridObjectConstructor("UnistylesRuntime", [unistylesRuntime]() -> std::shared_ptr<HybridObject>{
|
|
@@ -57,10 +53,7 @@ RCT_EXPORT_MODULE(Unistyles)
|
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
- (void)invalidate {
|
|
60
|
-
|
|
61
|
-
core::UnistylesRegistry::get().destroyState(_runtime);
|
|
62
|
-
_runtime = nullptr;
|
|
63
|
-
}
|
|
56
|
+
core::UnistylesRegistry::get().destroy();
|
|
64
57
|
|
|
65
58
|
[super invalidate];
|
|
66
59
|
}
|
|
@@ -57,7 +57,10 @@ const useProxifiedUnistyles = forcedTheme => {
|
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
59
|
(0, _react.useEffect)(() => {
|
|
60
|
-
return () =>
|
|
60
|
+
return () => {
|
|
61
|
+
disposeRef.current?.();
|
|
62
|
+
syncedDependenciesSizeRef.current = -1;
|
|
63
|
+
};
|
|
61
64
|
}, [disposeRef]);
|
|
62
65
|
const maybeNewScopedTheme = _specs.UnistylesShadowRegistry.getScopedTheme();
|
|
63
66
|
if (scopedTheme && maybeNewScopedTheme && scopedTheme !== maybeNewScopedTheme) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_specs","_NativePlatform","_listener","getMiniRuntime","UnistylesRuntime","miniRuntime","RTDependencyMap","breakpoint","UnistyleDependency","Breakpoints","colorScheme","ColorScheme","contentSizeCategory","ContentSizeCategory","hasAdaptiveThemes","AdaptiveThemes","insets","Insets","fontScale","FontScale","isLandscape","Orientation","isPortrait","navigationBar","NavigationBar","screen","Dimensions","statusBar","StatusBar","pixelRatio","PixelRatio","themeName","ThemeName","rtl","Rtl","useProxifiedUnistyles","forcedTheme","scopedTheme","setScopedTheme","useState","UnistylesShadowRegistry","getScopedTheme","dependencies","Set","theme","setTheme","getTheme","_","runtimeChanged","useReducer","disposeRef","useRef","undefined","syncedDependenciesSizeRef","syncedScopedThemeRef","reinitListener","current","listener","Array","from","updateTheme","updateRuntime","hasThemeNameChange","useEffect","maybeNewScopedTheme","proxifiedTheme","Proxy","get","target","prop","add","Theme","proxifiedRuntime","Ime","useLayoutEffect","sameDeps","size","sameScopedTheme","addDependencies","newDependencies","dependenciesSize","forEach","dependency","exports"],"sourceRoot":"../../../../src","sources":["core/useProxifiedUnistyles/useProxifiedUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,G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CAAC,CAAC;EACtD,MAAMC,UAAU,GAAG,IAAAC,aAAM,EAAeC,SAAS,CAAC;EAClD,MAAMC,yBAAyB,GAAG,IAAAF,aAAM,EAAC,CAAC,CAAC,CAAC;EAC5C,MAAMG,oBAAoB,GAAG,IAAAH,aAAM,EAA6BC,SAAS,CAAC;EAE1E,MAAMG,cAAc,GAAGA,CAAA,KAAM;IACzBL,UAAU,CAACM,OAAO,GAAG,CAAC;IACtBN,UAAU,CAACM,OAAO,GAAG,IAAAC,kBAAQ,EAAC;MAC1Bf,YAAY,EAAEgB,KAAK,CAACC,IAAI,CAACjB,YAAY,CAAC;MACtCkB,WAAW,EAAEA,CAAA,KAAM;QACf,IAAIvB,WAAW,EAAE;UACb;QACJ;QAEAQ,QAAQ,CAACzC,uBAAgB,CAAC0C,QAAQ,CAACT,WAAW,CAAC,CAAC;MACpD,CAAC;MACDwB,aAAa,EAAGC,kBAA2B,IAAK;QAC5C,IAAIA,kBAAkB,IAAIzB,WAAW,EAAE;UACnC;QACJ;QAEAW,cAAc,CAAC,CAAC;MACpB;IACJ,CAAC,CAAC;EACN,CAAC;EAED,IAAAe,gBAAS,EAAC,MAAM;IACZ,OAAO,
|
|
1
|
+
{"version":3,"names":["_react","require","_specs","_NativePlatform","_listener","getMiniRuntime","UnistylesRuntime","miniRuntime","RTDependencyMap","breakpoint","UnistyleDependency","Breakpoints","colorScheme","ColorScheme","contentSizeCategory","ContentSizeCategory","hasAdaptiveThemes","AdaptiveThemes","insets","Insets","fontScale","FontScale","isLandscape","Orientation","isPortrait","navigationBar","NavigationBar","screen","Dimensions","statusBar","StatusBar","pixelRatio","PixelRatio","themeName","ThemeName","rtl","Rtl","useProxifiedUnistyles","forcedTheme","scopedTheme","setScopedTheme","useState","UnistylesShadowRegistry","getScopedTheme","dependencies","Set","theme","setTheme","getTheme","_","runtimeChanged","useReducer","disposeRef","useRef","undefined","syncedDependenciesSizeRef","syncedScopedThemeRef","reinitListener","current","listener","Array","from","updateTheme","updateRuntime","hasThemeNameChange","useEffect","maybeNewScopedTheme","proxifiedTheme","Proxy","get","target","prop","add","Theme","proxifiedRuntime","Ime","useLayoutEffect","sameDeps","size","sameScopedTheme","addDependencies","newDependencies","dependenciesSize","forEach","dependency","exports"],"sourceRoot":"../../../../src","sources":["core/useProxifiedUnistyles/useProxifiedUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAFA;;AAIA,MAAMI,cAAc,GAAGA,CAAA,KAA4B;EAC/C;EACA,OAAOC,uBAAgB,CAACC,WAAW;AACvC,CAAC;AAED,MAAMC,eAAe,GAAG;EACpBC,UAAU,EAAEC,kCAAkB,CAACC,WAAW;EAC1CC,WAAW,EAAEF,kCAAkB,CAACG,WAAW;EAC3CC,mBAAmB,EAAEJ,kCAAkB,CAACK,mBAAmB;EAC3DC,iBAAiB,EAAEN,kCAAkB,CAACO,cAAc;EACpDC,MAAM,EAAER,kCAAkB,CAACS,MAAM;EACjCC,SAAS,EAAEV,kCAAkB,CAACW,SAAS;EACvCC,WAAW,EAAEZ,kCAAkB,CAACa,WAAW;EAC3CC,UAAU,EAAEd,kCAAkB,CAACa,WAAW;EAC1CE,aAAa,EAAEf,kCAAkB,CAACgB,aAAa;EAC/CC,MAAM,EAAEjB,kCAAkB,CAACkB,UAAU;EACrCC,SAAS,EAAEnB,kCAAkB,CAACoB,SAAS;EACvCC,UAAU,EAAErB,kCAAkB,CAACsB,UAAU;EACzCC,SAAS,EAAEvB,kCAAkB,CAACwB,SAAS;EACvCC,GAAG,EAAEzB,kCAAkB,CAAC0B;AAC5B,CAA2E;AAEpE,MAAMC,qBAAqB,GAAIC,WAA4B,IAAK;EACnE,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAG,IAAAC,eAAQ,EAC1CH,WAAW,IAAKI,8BAAuB,CAACC,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EF,IAAAK,sBAAe,EAAC,MAAM;IAClB,MAAMC,QAAQ,GAAGtB,yBAAyB,CAACG,OAAO,KAAKd,YAAY,CAACkC,IAAI;IACxE,MAAMC,eAAe,GAAGvB,oBAAoB,CAACE,OAAO,KAAKnB,WAAW;IAEpE,IAAIsC,QAAQ,IAAIE,eAAe,EAAE;MAC7B;IACJ;IAEAxB,yBAAyB,CAACG,OAAO,GAAGd,YAAY,CAACkC,IAAI;IACrDtB,oBAAoB,CAACE,OAAO,GAAGnB,WAAW;IAE1CkB,cAAc,CAAC,CAAC;EACpB,CAAC,EAAE,CAACU,cAAc,EAAEO,gBAAgB,EAAEnC,WAAW,CAAC,CAAC;EAEnD,OAAO;IACH4B,cAAc;IACdO,gBAAgB;IAChBM,eAAe,EAAGC,eAA0C,IAAK;MAC7D,MAAMC,gBAAgB,GAAGtC,YAAY,CAACkC,IAAI;MAE1CG,eAAe,CAACE,OAAO,CAAEC,UAAU,IAAK;QACpCxC,YAAY,CAAC4B,GAAG,CAACY,UAAU,CAAC;MAChC,CAAC,CAAC;MAEF,IAAIF,gBAAgB,KAAKtC,YAAY,CAACkC,IAAI,EAAE;QACxC;MACJ;MAEAvB,yBAAyB,CAACG,OAAO,GAAGd,YAAY,CAACkC,IAAI;MACrDtB,oBAAoB,CAACE,OAAO,GAAGnB,WAAW;MAC1CkB,cAAc,CAAC,CAAC;IACpB;EACJ,CAAC;AACL,CAAC;AAAA4B,OAAA,CAAAhD,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -6,6 +6,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.UnistylesShadowRegistry = void 0;
|
|
7
7
|
var _reactNativeNitroModules = require("react-native-nitro-modules");
|
|
8
8
|
const HybridShadowRegistry = _reactNativeNitroModules.NitroModules.createHybridObject('UnistylesShadowRegistry');
|
|
9
|
+
const SUSPENSE_TAG = 13;
|
|
10
|
+
const isInsideSuspendedBoundary = fiber => {
|
|
11
|
+
let current = fiber?.return;
|
|
12
|
+
while (current) {
|
|
13
|
+
if (current.tag === SUSPENSE_TAG && current.memoizedState !== null) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
current = current.return;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
const findFiberForHandle = handle => {
|
|
21
|
+
return handle?.__internalInstanceHandle ?? handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle ?? handle?.getNativeScrollRef?.()?.__internalInstanceHandle ?? handle?._viewRef?.__internalInstanceHandle ?? handle?.viewRef?.current?.__internalInstanceHandle ?? handle?._nativeRef?.__internalInstanceHandle;
|
|
22
|
+
};
|
|
9
23
|
const findShadowNodeForHandle = handle => {
|
|
10
24
|
const node = handle?.__internalInstanceHandle?.stateNode?.node ?? handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node ?? handle?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node ?? handle?._viewRef?.__internalInstanceHandle?.stateNode?.node ?? handle?.viewRef?.current?.__internalInstanceHandle?.stateNode?.node ?? handle?._nativeRef?.__internalInstanceHandle?.stateNode?.node;
|
|
11
25
|
|
|
@@ -38,7 +52,12 @@ HybridShadowRegistry.remove = handle => {
|
|
|
38
52
|
}
|
|
39
53
|
const maybeNode = findShadowNodeForHandle(handle);
|
|
40
54
|
if (maybeNode) {
|
|
41
|
-
|
|
55
|
+
const fiber = findFiberForHandle(handle);
|
|
56
|
+
if (fiber && isInsideSuspendedBoundary(fiber)) {
|
|
57
|
+
HybridShadowRegistry.suspend(maybeNode);
|
|
58
|
+
} else {
|
|
59
|
+
HybridShadowRegistry.unlink(maybeNode);
|
|
60
|
+
}
|
|
42
61
|
}
|
|
43
62
|
};
|
|
44
63
|
const UnistylesShadowRegistry = exports.UnistylesShadowRegistry = HybridShadowRegistry;
|