react-native-unistyles 3.5.1 → 3.5.3
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/Unistyles.podspec +1 -0
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +44 -7
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +1 -1
- package/cxx/core/UnistylesRegistry.cpp +5 -5
- package/cxx/core/UnistylesRegistry.h +3 -3
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +48 -14
- package/cxx/hybridObjects/HybridShadowRegistry.h +3 -2
- package/cxx/hybridObjects/HybridStyleSheet.cpp +3 -3
- package/cxx/parser/Parser.cpp +18 -2
- package/cxx/shadowTree/ShadowTreeManager.cpp +5 -5
- package/cxx/shadowTree/ShadowTreeManager.h +1 -1
- package/ios/NativePlatform+ios.swift +6 -4
- package/lib/commonjs/components/AdaptiveTheme.js +9 -1
- package/lib/commonjs/components/AdaptiveTheme.js.map +1 -1
- package/lib/commonjs/components/NamedTheme.js +9 -1
- package/lib/commonjs/components/NamedTheme.js.map +1 -1
- package/lib/commonjs/components/ScopedThemeContext.js +9 -0
- package/lib/commonjs/components/ScopedThemeContext.js.map +1 -0
- package/lib/commonjs/components/native/Pressable.native.js +6 -5
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/components/scopeChildren.js +29 -0
- package/lib/commonjs/components/scopeChildren.js.map +1 -0
- package/lib/commonjs/components/scopeChildren.native.js +9 -0
- package/lib/commonjs/components/scopeChildren.native.js.map +1 -0
- package/lib/commonjs/core/createUnistylesActivityIndicator.js +5 -3
- package/lib/commonjs/core/createUnistylesActivityIndicator.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +3 -1
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +7 -4
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/createUnistylesTouchableHighlight.js +6 -8
- package/lib/commonjs/core/createUnistylesTouchableHighlight.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +20 -5
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +28 -17
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/reanimated/useAnimatedTheme.js +8 -5
- package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -1
- package/lib/commonjs/reanimated/useAnimatedTheme.native.js +8 -5
- package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +76 -74
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/web/css/core.js +30 -5
- package/lib/commonjs/web/css/core.js.map +1 -1
- package/lib/commonjs/web/css/state.js +9 -3
- package/lib/commonjs/web/css/state.js.map +1 -1
- package/lib/commonjs/web/registry.js +1 -1
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +3 -1
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/module/components/AdaptiveTheme.js +10 -2
- package/lib/module/components/AdaptiveTheme.js.map +1 -1
- package/lib/module/components/NamedTheme.js +10 -2
- package/lib/module/components/NamedTheme.js.map +1 -1
- package/lib/module/components/ScopedThemeContext.js +5 -0
- package/lib/module/components/ScopedThemeContext.js.map +1 -0
- package/lib/module/components/native/Pressable.native.js +7 -6
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/components/scopeChildren.js +23 -0
- package/lib/module/components/scopeChildren.js.map +1 -0
- package/lib/module/components/scopeChildren.native.js +4 -0
- package/lib/module/components/scopeChildren.native.js.map +1 -0
- package/lib/module/core/createUnistylesActivityIndicator.js +4 -2
- package/lib/module/core/createUnistylesActivityIndicator.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +4 -2
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +6 -3
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/createUnistylesTouchableHighlight.js +7 -9
- package/lib/module/core/createUnistylesTouchableHighlight.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +22 -7
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +27 -17
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/reanimated/useAnimatedTheme.js +10 -7
- package/lib/module/reanimated/useAnimatedTheme.js.map +1 -1
- package/lib/module/reanimated/useAnimatedTheme.native.js +10 -7
- package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +76 -74
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/web/css/core.js +28 -4
- package/lib/module/web/css/core.js.map +1 -1
- package/lib/module/web/css/state.js +10 -4
- package/lib/module/web/css/state.js.map +1 -1
- package/lib/module/web/registry.js +1 -1
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +3 -1
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/web-child-selector.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/web-child-selector.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/web-pointer-events.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/web-pointer-events.spec.d.ts.map +1 -0
- package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts +2 -0
- package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts.map +1 -0
- package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -1
- package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -1
- package/lib/typescript/src/components/ScopedThemeContext.d.ts +6 -0
- package/lib/typescript/src/components/ScopedThemeContext.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/components/scopeChildren.d.ts +4 -0
- package/lib/typescript/src/components/scopeChildren.d.ts.map +1 -0
- package/lib/typescript/src/components/scopeChildren.native.d.ts +4 -0
- package/lib/typescript/src/components/scopeChildren.native.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesActivityIndicator.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesTouchableHighlight.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +1 -2
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +6 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +4 -3
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/web/css/core.d.ts +1 -0
- package/lib/typescript/src/web/css/core.d.ts.map +1 -1
- package/lib/typescript/src/web/css/state.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/AdaptiveTheme.tsx +8 -2
- package/src/components/NamedTheme.tsx +8 -2
- package/src/components/ScopedThemeContext.ts +9 -0
- package/src/components/native/Pressable.native.tsx +8 -7
- package/src/components/scopeChildren.native.ts +5 -0
- package/src/components/scopeChildren.tsx +19 -0
- package/src/core/createUnistylesActivityIndicator.tsx +5 -2
- package/src/core/createUnistylesElement.native.tsx +4 -2
- package/src/core/createUnistylesImageBackground.tsx +6 -3
- package/src/core/createUnistylesTouchableHighlight.tsx +7 -11
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +22 -10
- package/src/core/withUnistyles/withUnistyles.native.tsx +46 -30
- package/src/reanimated/useAnimatedTheme.native.ts +9 -9
- package/src/reanimated/useAnimatedTheme.ts +9 -9
- package/src/specs/ShadowRegistry/index.ts +93 -91
- package/src/web/css/core.ts +29 -4
- package/src/web/css/state.ts +16 -4
- package/src/web/registry.ts +1 -1
- package/src/web/shadowRegistry.ts +3 -1
package/Unistyles.podspec
CHANGED
|
@@ -3,11 +3,16 @@ package com.unistyles
|
|
|
3
3
|
import android.os.Build
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.content.res.Configuration
|
|
6
|
+
import android.content.res.Resources
|
|
7
|
+
import android.os.Handler
|
|
8
|
+
import android.os.Looper
|
|
6
9
|
import android.util.DisplayMetrics
|
|
7
10
|
import android.view.View
|
|
8
11
|
import android.view.WindowManager
|
|
9
12
|
import androidx.annotation.Keep
|
|
13
|
+
import androidx.core.content.OnConfigurationChangedProvider
|
|
10
14
|
import androidx.core.text.TextUtilsCompat
|
|
15
|
+
import androidx.core.util.Consumer
|
|
11
16
|
import androidx.core.view.ViewCompat
|
|
12
17
|
import androidx.core.view.WindowCompat
|
|
13
18
|
import androidx.core.view.WindowInsetsCompat
|
|
@@ -22,6 +27,7 @@ import com.margelo.nitro.unistyles.Insets
|
|
|
22
27
|
import com.margelo.nitro.unistyles.Orientation
|
|
23
28
|
import com.margelo.nitro.unistyles.UnistyleDependency
|
|
24
29
|
import com.margelo.nitro.unistyles.UnistylesNativeMiniRuntime
|
|
30
|
+
import java.lang.ref.WeakReference
|
|
25
31
|
import java.util.Locale
|
|
26
32
|
|
|
27
33
|
@Keep
|
|
@@ -30,6 +36,14 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
30
36
|
private val _insets = NativePlatformInsets(reactContext, this::getMiniRuntime) { this.onConfigChange() }
|
|
31
37
|
private var _miniRuntime: UnistylesNativeMiniRuntime = buildMiniRuntime()
|
|
32
38
|
private val _listener = NativePlatformListener(reactContext, this::getMiniRuntime) { this.diffMiniRuntime() }
|
|
39
|
+
private var _configurationProvider: WeakReference<OnConfigurationChangedProvider>? = null
|
|
40
|
+
private val _activityConfigurationListener = Consumer<Configuration> {
|
|
41
|
+
Handler(Looper.getMainLooper()).post { this.onConfigChange() }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Application resources can lag behind configuration changes
|
|
45
|
+
private val configurationResources: Resources
|
|
46
|
+
get() = reactContext.currentActivity?.resources ?: reactContext.resources
|
|
33
47
|
|
|
34
48
|
init {
|
|
35
49
|
checkEdgeToEdge()
|
|
@@ -37,12 +51,16 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
37
51
|
}
|
|
38
52
|
|
|
39
53
|
fun onDestroy() {
|
|
54
|
+
stopObservingActivityConfiguration()
|
|
40
55
|
_listener.onDestroy()
|
|
41
56
|
_insets.onDestroy()
|
|
42
57
|
reactContext.removeLifecycleEventListener(this)
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
override fun onHostResume() {
|
|
61
|
+
observeActivityConfiguration()
|
|
62
|
+
// catch configuration changes missed while no Activity was attached
|
|
63
|
+
onConfigChange()
|
|
46
64
|
_insets.getInitialInsets(false)
|
|
47
65
|
_insets.startInsetsListener()
|
|
48
66
|
}
|
|
@@ -51,7 +69,26 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
51
69
|
_insets.stopInsetsListener()
|
|
52
70
|
}
|
|
53
71
|
|
|
54
|
-
override fun onHostDestroy() {
|
|
72
|
+
override fun onHostDestroy() {
|
|
73
|
+
stopObservingActivityConfiguration()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private fun observeActivityConfiguration() {
|
|
77
|
+
val provider = reactContext.currentActivity as? OnConfigurationChangedProvider
|
|
78
|
+
|
|
79
|
+
if (_configurationProvider?.get() === provider) {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
stopObservingActivityConfiguration()
|
|
84
|
+
provider?.addOnConfigurationChangedListener(_activityConfigurationListener)
|
|
85
|
+
_configurationProvider = provider?.let { WeakReference(it) }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private fun stopObservingActivityConfiguration() {
|
|
89
|
+
_configurationProvider?.get()?.removeOnConfigurationChangedListener(_activityConfigurationListener)
|
|
90
|
+
_configurationProvider = null
|
|
91
|
+
}
|
|
55
92
|
|
|
56
93
|
override val memorySize: Long
|
|
57
94
|
get() = 0
|
|
@@ -61,7 +98,7 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
61
98
|
}
|
|
62
99
|
|
|
63
100
|
override fun getColorScheme(): ColorScheme {
|
|
64
|
-
val uiMode =
|
|
101
|
+
val uiMode = configurationResources.configuration.uiMode
|
|
65
102
|
|
|
66
103
|
val colorScheme = when (uiMode.and(Configuration.UI_MODE_NIGHT_MASK)) {
|
|
67
104
|
Configuration.UI_MODE_NIGHT_YES -> ColorScheme.DARK
|
|
@@ -73,15 +110,15 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
73
110
|
}
|
|
74
111
|
|
|
75
112
|
override fun getFontScale(): Double {
|
|
76
|
-
return
|
|
113
|
+
return configurationResources.configuration.fontScale.toDouble()
|
|
77
114
|
}
|
|
78
115
|
|
|
79
116
|
override fun getPixelRatio(): Double {
|
|
80
|
-
return
|
|
117
|
+
return configurationResources.displayMetrics.density.toDouble()
|
|
81
118
|
}
|
|
82
119
|
|
|
83
120
|
override fun getOrientation(): Orientation {
|
|
84
|
-
val orientation = when (
|
|
121
|
+
val orientation = when (configurationResources.configuration.orientation) {
|
|
85
122
|
Configuration.ORIENTATION_PORTRAIT -> Orientation.PORTRAIT
|
|
86
123
|
Configuration.ORIENTATION_LANDSCAPE -> Orientation.LANDSCAPE
|
|
87
124
|
else -> Orientation.PORTRAIT
|
|
@@ -122,7 +159,7 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
122
159
|
return Dimensions(screenWidth, screenHeight)
|
|
123
160
|
}
|
|
124
161
|
else -> {
|
|
125
|
-
val displayMetrics =
|
|
162
|
+
val displayMetrics = configurationResources.displayMetrics
|
|
126
163
|
|
|
127
164
|
reactContext.currentActivity?.windowManager?.currentWindowMetrics?.bounds?.let {
|
|
128
165
|
val boundsWidth = (it.width() / displayMetrics.density).toDouble()
|
|
@@ -157,7 +194,7 @@ class NativePlatformAndroid(private val reactContext: ReactApplicationContext):
|
|
|
157
194
|
"com.facebook.react.modules.i18nmanager.I18nUtil",
|
|
158
195
|
Context.MODE_PRIVATE
|
|
159
196
|
)
|
|
160
|
-
val resourcesLocale =
|
|
197
|
+
val resourcesLocale = configurationResources.configuration.locales[0]
|
|
161
198
|
val hasForcedRtl = sharedPrefs.getBoolean("RCTI18nUtil_forceRTL", false)
|
|
162
199
|
// user preferences
|
|
163
200
|
val isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL
|
|
@@ -38,7 +38,7 @@ class NativePlatformInsets(
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
fun getInsets(): Insets {
|
|
41
|
-
val density = reactContext.resources.displayMetrics.density
|
|
41
|
+
val density = (reactContext.currentActivity?.resources ?: reactContext.resources).displayMetrics.density
|
|
42
42
|
|
|
43
43
|
return Insets(
|
|
44
44
|
this._insets.top / density,
|
|
@@ -407,7 +407,7 @@ core::UnistylesRegistry::OwnedState core::UnistylesRegistry::takeOwnedState() {
|
|
|
407
407
|
ownedState.styleSheets = std::exchange(this->_styleSheetRegistry, {});
|
|
408
408
|
ownedState.state = std::move(this->_state);
|
|
409
409
|
this->_scopedTheme = std::nullopt;
|
|
410
|
-
this->
|
|
410
|
+
this->_committedInstanceHandles.clear();
|
|
411
411
|
_nextStyleSheetTag.store(0);
|
|
412
412
|
|
|
413
413
|
return ownedState;
|
|
@@ -435,10 +435,10 @@ size_t core::UnistylesRegistry::getPendingUpdatesCount() {
|
|
|
435
435
|
});
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
-
void core::UnistylesRegistry::
|
|
439
|
-
this->
|
|
438
|
+
void core::UnistylesRegistry::setCommittedInstanceHandles(std::vector<InstanceHandle::Shared>&& instanceHandles) {
|
|
439
|
+
this->_committedInstanceHandles = std::move(instanceHandles);
|
|
440
440
|
}
|
|
441
441
|
|
|
442
|
-
std::vector<
|
|
443
|
-
return std::exchange(this->
|
|
442
|
+
std::vector<InstanceHandle::Shared> core::UnistylesRegistry::takeCommittedInstanceHandles() {
|
|
443
|
+
return std::exchange(this->_committedInstanceHandles, {});
|
|
444
444
|
}
|
|
@@ -70,8 +70,8 @@ struct UnistylesRegistry: public StyleSheetRegistry {
|
|
|
70
70
|
core::Unistyle::Shared getUnistyleById(std::string unistyleID);
|
|
71
71
|
std::vector<LinkedFamilySnapshot> getLinkedFamiliesSnapshot();
|
|
72
72
|
size_t getPendingUpdatesCount();
|
|
73
|
-
void
|
|
74
|
-
std::vector<
|
|
73
|
+
void setCommittedInstanceHandles(std::vector<InstanceHandle::Shared>&& instanceHandles);
|
|
74
|
+
std::vector<InstanceHandle::Shared> takeCommittedInstanceHandles();
|
|
75
75
|
|
|
76
76
|
// newest installed runtime owns the registry, generation 0 means no owner
|
|
77
77
|
// previous runtime's state is kept aside until it releases ownership, as it may still run JS
|
|
@@ -119,7 +119,7 @@ private:
|
|
|
119
119
|
std::unordered_map<int, std::shared_ptr<core::StyleSheet>> _styleSheetRegistry{};
|
|
120
120
|
std::unordered_map<const ShadowNodeFamily*, LinkedFamily> _shadowRegistry{};
|
|
121
121
|
size_t _sweepThreshold = MIN_SWEEP_THRESHOLD;
|
|
122
|
-
std::vector<
|
|
122
|
+
std::vector<InstanceHandle::Shared> _committedInstanceHandles{};
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
inline UnistylesRegistry& UnistylesRegistry::get() {
|
|
@@ -33,8 +33,7 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
|
33
33
|
try {
|
|
34
34
|
auto rawStyle = args[1].asObject(rt).asArray(rt).getValueAtIndex(rt, i);
|
|
35
35
|
auto rawStyleObj = rawStyle.getObject(rt);
|
|
36
|
-
auto
|
|
37
|
-
auto secrets = rawStyleObj.getProperty(rt, unistyleHashKeys.at(0).c_str()).asObject(rt);
|
|
36
|
+
auto secrets = getUnistyleSecrets(rt, rawStyleObj, unistyleWrappers[i]).value();
|
|
38
37
|
auto secretArguments = secrets.getProperty(rt, helpers::ARGUMENTS.c_str()).asObject(rt).asArray(rt);
|
|
39
38
|
|
|
40
39
|
arguments.push_back(helpers::parseDynamicFunctionArguments(rt, secretArguments));
|
|
@@ -65,15 +64,14 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
|
65
64
|
core::Unistyle::Shared& unistyle = unistyleWrappers[i];
|
|
66
65
|
auto rawStyle = args[1].asObject(rt).asArray(rt).getValueAtIndex(rt, i);
|
|
67
66
|
auto rawStyleObj = rawStyle.getObject(rt);
|
|
68
|
-
auto
|
|
67
|
+
auto secrets = getUnistyleSecrets(rt, rawStyleObj, unistyle);
|
|
69
68
|
core::Variants variants{};
|
|
70
69
|
|
|
71
|
-
if (
|
|
72
|
-
auto
|
|
73
|
-
auto hasVariants = secrets.hasProperty(rt, helpers::STYLESHEET_VARIANTS.c_str());
|
|
70
|
+
if (secrets.has_value()) {
|
|
71
|
+
auto rawVariants = secrets->getProperty(rt, helpers::STYLESHEET_VARIANTS.c_str());
|
|
74
72
|
|
|
75
|
-
if (
|
|
76
|
-
variants = helpers::variantsToPairs(rt,
|
|
73
|
+
if (rawVariants.isObject()) {
|
|
74
|
+
variants = helpers::variantsToPairs(rt, rawVariants.asObject(rt));
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
77
|
|
|
@@ -94,8 +92,18 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
|
94
92
|
|
|
95
93
|
// The shared cache can belong to another view by the time React attaches refs.
|
|
96
94
|
// Restore this view's arguments and variants before saving its native styles.
|
|
95
|
+
// An object style without variants is the same for every view, so it's reused unless it's stale (dirty).
|
|
97
96
|
if (!unistyleData->parsedStyle.has_value() && unistyle->parsedStyle.has_value()) {
|
|
98
|
-
|
|
97
|
+
auto isSharedStyle = unistyle->type == core::UnistyleType::Object &&
|
|
98
|
+
unistyle->styleKey != helpers::EXOTIC_STYLE_KEY &&
|
|
99
|
+
!unistyle->isDirty &&
|
|
100
|
+
!unistyle->rawValue.hasProperty(rt, "variants");
|
|
101
|
+
|
|
102
|
+
if (isSharedStyle) {
|
|
103
|
+
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
|
104
|
+
} else {
|
|
105
|
+
parser.rebuildUnistyleWithVariants(rt, unistyleData);
|
|
106
|
+
}
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
unistylesData.emplace_back(unistyleData);
|
|
@@ -131,6 +139,29 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
|
131
139
|
return jsi::Value::undefined();
|
|
132
140
|
}
|
|
133
141
|
|
|
142
|
+
// a style made by Unistyles keeps its secrets (variants, arguments) under the unistyle's id,
|
|
143
|
+
// reading it directly spares enumerating (and converting to strings) every prop of every linked style
|
|
144
|
+
std::optional<jsi::Object> HybridShadowRegistry::getUnistyleSecrets(jsi::Runtime& rt, jsi::Object& style, const core::Unistyle::Shared& unistyle) {
|
|
145
|
+
// inline and React Native styles have no secrets
|
|
146
|
+
if (unistyle->styleKey == helpers::EXOTIC_STYLE_KEY) {
|
|
147
|
+
return std::nullopt;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
auto secrets = style.getProperty(rt, unistyle->unid.c_str());
|
|
151
|
+
|
|
152
|
+
if (secrets.isObject()) {
|
|
153
|
+
return secrets.asObject(rt);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
auto unistyleHashKeys = core::getUnistylesHashKeys(rt, style);
|
|
157
|
+
|
|
158
|
+
if (unistyleHashKeys.size() != 1) {
|
|
159
|
+
return std::nullopt;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return style.getProperty(rt, unistyleHashKeys.at(0).c_str()).asObject(rt);
|
|
163
|
+
}
|
|
164
|
+
|
|
134
165
|
void HybridShadowRegistry::scheduleShadowTreeUpdate(jsi::Runtime& rt) {
|
|
135
166
|
if (this->_isShadowTreeUpdateScheduled->exchange(true)) {
|
|
136
167
|
return;
|
|
@@ -232,12 +263,15 @@ jsi::Value HybridShadowRegistry::verify(jsi::Runtime &rt, const jsi::Value &this
|
|
|
232
263
|
return shadow::ShadowTreeDiagnostics::verify(rt, this->_unistylesRuntime);
|
|
233
264
|
}
|
|
234
265
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
auto
|
|
266
|
+
// the fibers React created the committed nodes with (weak, null once collected)
|
|
267
|
+
jsi::Value HybridShadowRegistry::takeCommittedInstanceHandles(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
268
|
+
auto instanceHandles = core::UnistylesRegistry::get().takeCommittedInstanceHandles();
|
|
269
|
+
auto result = jsi::Array(rt, instanceHandles.size());
|
|
270
|
+
|
|
271
|
+
for (size_t i = 0; i < instanceHandles.size(); i++) {
|
|
272
|
+
auto& instanceHandle = instanceHandles[i];
|
|
238
273
|
|
|
239
|
-
|
|
240
|
-
result.setValueAtIndex(rt, i, jsi::Value(static_cast<double>(tags[i])));
|
|
274
|
+
result.setValueAtIndex(rt, i, instanceHandle ? instanceHandle->getInstanceHandle(rt) : jsi::Value::null());
|
|
241
275
|
}
|
|
242
276
|
|
|
243
277
|
return result;
|
|
@@ -44,7 +44,7 @@ struct HybridShadowRegistry: public HybridUnistylesShadowRegistrySpec {
|
|
|
44
44
|
const jsi::Value& thisValue,
|
|
45
45
|
const jsi::Value* args,
|
|
46
46
|
size_t count);
|
|
47
|
-
jsi::Value
|
|
47
|
+
jsi::Value takeCommittedInstanceHandles(jsi::Runtime& rt,
|
|
48
48
|
const jsi::Value& thisValue,
|
|
49
49
|
const jsi::Value* args,
|
|
50
50
|
size_t count);
|
|
@@ -64,7 +64,7 @@ struct HybridShadowRegistry: public HybridUnistylesShadowRegistrySpec {
|
|
|
64
64
|
prototype.registerRawHybridMethod("setScopedTheme", 1, &HybridShadowRegistry::setScopedTheme);
|
|
65
65
|
prototype.registerRawHybridMethod("getScopedTheme", 0, &HybridShadowRegistry::getScopedTheme);
|
|
66
66
|
prototype.registerRawHybridMethod("verify", 0, &HybridShadowRegistry::verify);
|
|
67
|
-
prototype.registerRawHybridMethod("
|
|
67
|
+
prototype.registerRawHybridMethod("takeCommittedInstanceHandles", 0, &HybridShadowRegistry::takeCommittedInstanceHandles);
|
|
68
68
|
prototype.registerRawHybridMethod("refreshReactNodes", 1, &HybridShadowRegistry::refreshReactNodes);
|
|
69
69
|
});
|
|
70
70
|
};
|
|
@@ -73,6 +73,7 @@ struct HybridShadowRegistry: public HybridUnistylesShadowRegistrySpec {
|
|
|
73
73
|
|
|
74
74
|
private:
|
|
75
75
|
void scheduleShadowTreeUpdate(jsi::Runtime& rt);
|
|
76
|
+
static std::optional<jsi::Object> getUnistyleSecrets(jsi::Runtime& rt, jsi::Object& style, const core::Unistyle::Shared& unistyle);
|
|
76
77
|
|
|
77
78
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
|
78
79
|
std::shared_ptr<std::atomic<bool>> _isShadowTreeUpdateScheduled = std::make_shared<std::atomic<bool>>(false);
|
|
@@ -362,14 +362,14 @@ void HybridStyleSheet::applyDependencyChanges(jsi::Runtime& rt, std::vector<Unis
|
|
|
362
362
|
parser.rebuildShadowLeafUpdates(rt, dependencyMap);
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
std::vector<
|
|
365
|
+
std::vector<InstanceHandle::Shared> committedInstanceHandles;
|
|
366
366
|
|
|
367
367
|
if (!dependencyMap.empty()) {
|
|
368
|
-
|
|
368
|
+
committedInstanceHandles = shadow::ShadowTreeManager::updateShadowTree(rt);
|
|
369
369
|
}
|
|
370
370
|
|
|
371
371
|
// after the commit, so listeners can point React at the committed nodes
|
|
372
|
-
registry.
|
|
372
|
+
registry.setCommittedInstanceHandles(std::move(committedInstanceHandles));
|
|
373
373
|
// also when no StyleSheet depends on the change, hooks (useUnistyles, withUnistyles, Display, Hide) may
|
|
374
374
|
this->notifyJSListeners(dependencies);
|
|
375
375
|
}
|
package/cxx/parser/Parser.cpp
CHANGED
|
@@ -281,6 +281,7 @@ void parser::Parser::rebuildUnistylesInDependencyMap(
|
|
|
281
281
|
std::unordered_map<std::shared_ptr<StyleSheet>, jsi::Value> parsedStyleSheetsWithDefaultTheme;
|
|
282
282
|
std::unordered_map<std::string, std::unordered_map<std::shared_ptr<StyleSheet>, jsi::Value>> parsedStyleSheetsWithScopedTheme;
|
|
283
283
|
std::unordered_set<std::shared_ptr<core::Unistyle>> parsedUnistyles;
|
|
284
|
+
std::unordered_set<std::shared_ptr<core::Unistyle>> sharedUnistyles;
|
|
284
285
|
|
|
285
286
|
// Parse all stylesheets that depend on changes
|
|
286
287
|
for (const auto& styleSheet : styleSheets) {
|
|
@@ -355,6 +356,8 @@ void parser::Parser::rebuildUnistylesInDependencyMap(
|
|
|
355
356
|
}
|
|
356
357
|
|
|
357
358
|
this->rebuildUnistyleWithScopedTheme(rt, parsedStyleSheet, unistyleData);
|
|
359
|
+
} else if (sharedUnistyles.contains(unistyle)) {
|
|
360
|
+
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
|
358
361
|
} else {
|
|
359
362
|
unistyle->rawValue = parsedSheetObj
|
|
360
363
|
.getProperty(rt, unistyle->styleKey.c_str())
|
|
@@ -365,9 +368,14 @@ void parser::Parser::rebuildUnistylesInDependencyMap(
|
|
|
365
368
|
);
|
|
366
369
|
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
|
367
370
|
unistyle->isDirty = true;
|
|
368
|
-
}
|
|
369
371
|
|
|
370
|
-
|
|
372
|
+
if (unistyle->type == core::UnistyleType::Object && !unistyle->rawValue.hasProperty(rt, "variants")) {
|
|
373
|
+
sharedUnistyles.insert(unistyle);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// unistyles rebuilt only for a scoped theme stay out of this set, so the loop below refreshes their global rawValue
|
|
377
|
+
parsedUnistyles.insert(unistyle);
|
|
378
|
+
}
|
|
371
379
|
}
|
|
372
380
|
}
|
|
373
381
|
|
|
@@ -1273,6 +1281,14 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
|
|
|
1273
1281
|
// so a value captured at link time would undo what React rendered since
|
|
1274
1282
|
folly::dynamic parser::Parser::parseStylesToShadowTreeUpdates(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles) {
|
|
1275
1283
|
auto props = this->parseStylesToShadowTreeStyles(rt, unistyles);
|
|
1284
|
+
auto hasInlineStyle = std::any_of(unistyles.begin(), unistyles.end(), [](const std::shared_ptr<UnistyleData>& unistyleData) {
|
|
1285
|
+
return unistyleData->parsedStyle.has_value() && unistyleData->unistyle->styleKey == helpers::EXOTIC_STYLE_KEY;
|
|
1286
|
+
});
|
|
1287
|
+
|
|
1288
|
+
if (!hasInlineStyle) {
|
|
1289
|
+
return props;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1276
1292
|
std::unordered_map<std::string, bool> isOwnedByInlineStyle;
|
|
1277
1293
|
|
|
1278
1294
|
for (const auto& unistyleData : unistyles) {
|
|
@@ -4,13 +4,13 @@ using namespace margelo::nitro::unistyles;
|
|
|
4
4
|
using namespace facebook::react;
|
|
5
5
|
using namespace facebook;
|
|
6
6
|
|
|
7
|
-
std::vector<
|
|
7
|
+
std::vector<InstanceHandle::Shared> shadow::ShadowTreeManager::updateShadowTree(jsi::Runtime& rt) {
|
|
8
8
|
auto& registry = core::UnistylesRegistry::get();
|
|
9
9
|
|
|
10
10
|
// updates pin their families, so raw pointers stay valid during the commit
|
|
11
11
|
// declared outside of the lock, so the last pin is released after unlocking
|
|
12
12
|
PinnedShadowLeafUpdates updates;
|
|
13
|
-
std::vector<
|
|
13
|
+
std::vector<InstanceHandle::Shared> committedInstanceHandles;
|
|
14
14
|
|
|
15
15
|
registry.trafficController.withLock([&](){
|
|
16
16
|
updates = registry.trafficController.takeUpdates();
|
|
@@ -21,18 +21,18 @@ std::vector<Tag> shadow::ShadowTreeManager::updateShadowTree(jsi::Runtime& rt) {
|
|
|
21
21
|
|
|
22
22
|
std::unordered_map<Tag, folly::dynamic> tagToProps;
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
committedInstanceHandles.reserve(updates.size());
|
|
25
25
|
|
|
26
26
|
for (const auto& [family, update] : updates) {
|
|
27
27
|
auto safeProps = update.props.isObject() ? update.props : folly::dynamic::object();
|
|
28
28
|
|
|
29
29
|
tagToProps.insert({family->getTag(), safeProps});
|
|
30
|
-
|
|
30
|
+
committedInstanceHandles.push_back(family->getInstanceHandle());
|
|
31
31
|
shadow::mergeNativeProps(family, safeProps);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
UIManagerBinding::getBinding(rt)->getUIManager().updateShadowTree(std::move(tagToProps));
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
return
|
|
37
|
+
return committedInstanceHandles;
|
|
38
38
|
}
|
|
@@ -120,8 +120,10 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
|
|
|
120
120
|
return cachedRuntime.screen;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
//
|
|
124
|
-
|
|
123
|
+
// when the app is launched in the background there is no foreground window yet, fall back to the screen
|
|
124
|
+
let screenSize = UIScreen.main.bounds.size
|
|
125
|
+
|
|
126
|
+
return Dimensions(width: screenSize.width, height: screenSize.height)
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
let width = windowFrame.size.width
|
|
@@ -280,8 +282,8 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
|
|
|
280
282
|
return cachedRuntime.pixelRatio;
|
|
281
283
|
}
|
|
282
284
|
|
|
283
|
-
//
|
|
284
|
-
return
|
|
285
|
+
// when the app is launched in the background there is no foreground window yet, fall back to the screen
|
|
286
|
+
return UIScreen.main.scale
|
|
285
287
|
}
|
|
286
288
|
|
|
287
289
|
return window.screen.scale
|
|
@@ -8,6 +8,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _core = require("../core");
|
|
9
9
|
var _specs = require("../specs");
|
|
10
10
|
var _ApplyScopedTheme = require("./ApplyScopedTheme");
|
|
11
|
+
var _scopeChildren = require("./scopeChildren");
|
|
12
|
+
var _ScopedThemeContext = require("./ScopedThemeContext");
|
|
11
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
14
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
15
|
const AdaptiveTheme = ({
|
|
@@ -18,9 +20,15 @@ const AdaptiveTheme = ({
|
|
|
18
20
|
rt
|
|
19
21
|
} = (0, _core.useUnistyles)();
|
|
20
22
|
const name = rt.colorScheme === 'dark' ? 'light' : 'dark';
|
|
23
|
+
const scope = (0, _react.useMemo)(() => ({
|
|
24
|
+
name
|
|
25
|
+
}), [name]);
|
|
21
26
|
const mappedChildren = [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ApplyScopedTheme.ApplyScopedTheme, {
|
|
22
27
|
name: name
|
|
23
|
-
}, name),
|
|
28
|
+
}, name), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ScopedThemeContext.ScopedThemeContext.Provider, {
|
|
29
|
+
value: scope,
|
|
30
|
+
children: (0, _scopeChildren.scopeChildren)(name, children)
|
|
31
|
+
}, "scope"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ApplyScopedTheme.ApplyScopedTheme, {
|
|
24
32
|
name: previousScopedTheme
|
|
25
33
|
}, "dispose")];
|
|
26
34
|
(0, _react.useLayoutEffect)(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_core","_specs","_ApplyScopedTheme","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","AdaptiveTheme","children","previousScopedTheme","rt","useUnistyles","name","colorScheme","mappedChildren","jsx","ApplyScopedTheme","useLayoutEffect","UnistylesShadowRegistry","flush","Fragment","exports"],"sourceRoot":"../../../src","sources":["components/AdaptiveTheme.tsx"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_core","_specs","_ApplyScopedTheme","_scopeChildren","_ScopedThemeContext","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","AdaptiveTheme","children","previousScopedTheme","rt","useUnistyles","name","colorScheme","scope","useMemo","mappedChildren","jsx","ApplyScopedTheme","ScopedThemeContext","Provider","value","scopeChildren","useLayoutEffect","UnistylesShadowRegistry","flush","Fragment","exports"],"sourceRoot":"../../../src","sources":["components/AdaptiveTheme.tsx"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AAAyD,IAAAM,WAAA,GAAAN,OAAA;AAAA,SAAAD,wBAAAQ,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAV,uBAAA,YAAAA,CAAAQ,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAMlD,MAAMkB,aAA0D,GAAGA,CAAC;EAAEC,QAAQ;EAAEC;AAAoB,CAAC,KAAK;EAC7G,MAAM;IAAEC;EAAG,CAAC,GAAG,IAAAC,kBAAY,EAAC,CAAC;EAC7B,MAAMC,IAAI,GAAIF,EAAE,CAACG,WAAW,KAAK,MAAM,GAAG,OAAO,GAAG,MAAgC;EACpF,MAAMC,KAAK,GAAG,IAAAC,cAAO,EAAC,OAAO;IAAEH;EAAK,CAAC,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAE/C,MAAMI,cAAc,GAAG,cACnB,IAAA7B,WAAA,CAAA8B,GAAA,EAACjC,iBAAA,CAAAkC,gBAAgB;IAAYN,IAAI,EAAEA;EAAK,GAAjBA,IAAmB,CAAC,eAC3C,IAAAzB,WAAA,CAAA8B,GAAA,EAAC/B,mBAAA,CAAAiC,kBAAkB,CAACC,QAAQ;IAAaC,KAAK,EAAEP,KAAM;IAAAN,QAAA,EACjD,IAAAc,4BAAa,EAACV,IAAI,EAAEJ,QAAQ;EAAC,GADD,OAEJ,CAAC,eAC9B,IAAArB,WAAA,CAAA8B,GAAA,EAACjC,iBAAA,CAAAkC,gBAAgB;IAAeN,IAAI,EAAEH;EAAyD,GAAzE,SAA2E,CAAC,CACrG;EAED,IAAAc,sBAAe,EAAC,MAAM;IAClB;IACAC,8BAAuB,CAACC,KAAK,CAAC,CAAC;EACnC,CAAC,CAAC;EAEF,oBAAO,IAAAtC,WAAA,CAAA8B,GAAA,EAACtC,MAAA,CAAAmB,OAAK,CAAC4B,QAAQ;IAAAlB,QAAA,EAAaQ;EAAc,GAArBJ,IAAsC,CAAC;AACvE,CAAC;AAAAe,OAAA,CAAApB,aAAA,GAAAA,aAAA","ignoreList":[]}
|
|
@@ -7,6 +7,8 @@ exports.NamedTheme = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _specs = require("../specs");
|
|
9
9
|
var _ApplyScopedTheme = require("./ApplyScopedTheme");
|
|
10
|
+
var _scopeChildren = require("./scopeChildren");
|
|
11
|
+
var _ScopedThemeContext = require("./ScopedThemeContext");
|
|
10
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
13
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
14
|
const NamedTheme = ({
|
|
@@ -14,9 +16,15 @@ const NamedTheme = ({
|
|
|
14
16
|
children,
|
|
15
17
|
previousScopedTheme
|
|
16
18
|
}) => {
|
|
19
|
+
const scope = (0, _react.useMemo)(() => ({
|
|
20
|
+
name
|
|
21
|
+
}), [name]);
|
|
17
22
|
const mappedChildren = [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ApplyScopedTheme.ApplyScopedTheme, {
|
|
18
23
|
name: name
|
|
19
|
-
}, "apply"),
|
|
24
|
+
}, "apply"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ScopedThemeContext.ScopedThemeContext.Provider, {
|
|
25
|
+
value: scope,
|
|
26
|
+
children: (0, _scopeChildren.scopeChildren)(name, children)
|
|
27
|
+
}, "scope"), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ApplyScopedTheme.ApplyScopedTheme, {
|
|
20
28
|
name: previousScopedTheme
|
|
21
29
|
}, "dispose")];
|
|
22
30
|
(0, _react.useLayoutEffect)(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_specs","_ApplyScopedTheme","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","NamedTheme","name","children","previousScopedTheme","mappedChildren","jsx","ApplyScopedTheme","useLayoutEffect","UnistylesShadowRegistry","flush","Fragment","exports"],"sourceRoot":"../../../src","sources":["components/NamedTheme.tsx"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_specs","_ApplyScopedTheme","_scopeChildren","_ScopedThemeContext","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","NamedTheme","name","children","previousScopedTheme","scope","useMemo","mappedChildren","jsx","ApplyScopedTheme","ScopedThemeContext","Provider","value","scopeChildren","useLayoutEffect","UnistylesShadowRegistry","flush","Fragment","exports"],"sourceRoot":"../../../src","sources":["components/NamedTheme.tsx"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AAAyD,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAD,wBAAAO,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAO,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAOlD,MAAMkB,UAAoD,GAAGA,CAAC;EAAEC,IAAI;EAAEC,QAAQ;EAAEC;AAAoB,CAAC,KAAK;EAC7G,MAAMC,KAAK,GAAG,IAAAC,cAAO,EAAC,OAAO;IAAEJ;EAAK,CAAC,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAE/C,MAAMK,cAAc,GAAG,cACnB,IAAA1B,WAAA,CAAA2B,GAAA,EAAC9B,iBAAA,CAAA+B,gBAAgB;IAAaP,IAAI,EAAEA;EAAK,GAAnB,OAAqB,CAAC,eAC5C,IAAArB,WAAA,CAAA2B,GAAA,EAAC5B,mBAAA,CAAA8B,kBAAkB,CAACC,QAAQ;IAAaC,KAAK,EAAEP,KAAM;IAAAF,QAAA,EACjD,IAAAU,4BAAa,EAACX,IAAI,EAAEC,QAAQ;EAAC,GADD,OAEJ,CAAC,eAC9B,IAAAtB,WAAA,CAAA2B,GAAA,EAAC9B,iBAAA,CAAA+B,gBAAgB;IAAeP,IAAI,EAAEE;EAAyD,GAAzE,SAA2E,CAAC,CACrG;EAED,IAAAU,sBAAe,EAAC,MAAM;IAClB;IACAC,8BAAuB,CAACC,KAAK,CAAC,CAAC;EACnC,CAAC,CAAC;EAEF,oBAAO,IAAAnC,WAAA,CAAA2B,GAAA,EAAClC,MAAA,CAAAkB,OAAK,CAACyB,QAAQ;IAAAd,QAAA,EAAEI;EAAc,CAAiB,CAAC;AAC5D,CAAC;AAAAW,OAAA,CAAAjB,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScopedThemeContext = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
const ScopedThemeContext = exports.ScopedThemeContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
9
|
+
//# sourceMappingURL=ScopedThemeContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","ScopedThemeContext","exports","createContext"],"sourceRoot":"../../../src","sources":["components/ScopedThemeContext.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAQO,MAAMC,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,gBAAG,IAAAE,oBAAa,EAAe,IAAI,CAAC","ignoreList":[]}
|
|
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
var _core = require("../../core");
|
|
10
10
|
var _specs = require("../../specs");
|
|
11
|
+
var _ScopedThemeContext = require("../ScopedThemeContext");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
14
|
// instance type of View for both legacy and Strict TypeScript API (RN 0.87+)
|
|
@@ -29,7 +30,7 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
29
30
|
...props
|
|
30
31
|
}, forwardedRef) => {
|
|
31
32
|
const storedRef = (0, _react.useRef)(null);
|
|
32
|
-
const
|
|
33
|
+
const scope = (0, _react.useContext)(_ScopedThemeContext.ScopedThemeContext);
|
|
33
34
|
(0, _react.useLayoutEffect)(() => {
|
|
34
35
|
return () => {
|
|
35
36
|
if (storedRef.current) {
|
|
@@ -50,7 +51,7 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
50
51
|
}
|
|
51
52
|
return (0, _core.passForwardedRef)(ref, forwardedRef, () => {
|
|
52
53
|
// @ts-expect-error - this is hidden from TS
|
|
53
|
-
_specs.UnistylesShadowRegistry.add(ref, unistyles);
|
|
54
|
+
_specs.UnistylesShadowRegistry.add(ref, unistyles, scope);
|
|
54
55
|
}, () => {
|
|
55
56
|
// @ts-expect-error - this is hidden from TS
|
|
56
57
|
_specs.UnistylesShadowRegistry.remove(ref);
|
|
@@ -59,8 +60,9 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
59
60
|
style: state => {
|
|
60
61
|
const isPropStyleAFunction = typeof style === 'function';
|
|
61
62
|
const previousScopedTheme = _specs.UnistylesShadowRegistry.getScopedTheme();
|
|
62
|
-
_specs.UnistylesShadowRegistry.setScopedTheme(
|
|
63
|
+
_specs.UnistylesShadowRegistry.setScopedTheme(scope?.name);
|
|
63
64
|
const unistyles = isPropStyleAFunction ? style.call(style, state) : getStyles(style);
|
|
65
|
+
_specs.UnistylesShadowRegistry.setScopedTheme(previousScopedTheme);
|
|
64
66
|
if (!storedRef.current) {
|
|
65
67
|
return unistyles;
|
|
66
68
|
}
|
|
@@ -69,8 +71,7 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
69
71
|
_specs.UnistylesShadowRegistry.remove(storedRef.current);
|
|
70
72
|
|
|
71
73
|
// @ts-expect-error - this is hidden from TS
|
|
72
|
-
_specs.UnistylesShadowRegistry.add(storedRef.current, unistyles);
|
|
73
|
-
_specs.UnistylesShadowRegistry.setScopedTheme(previousScopedTheme);
|
|
74
|
+
_specs.UnistylesShadowRegistry.add(storedRef.current, unistyles, scope);
|
|
74
75
|
return unistyles;
|
|
75
76
|
}
|
|
76
77
|
});
|