react-native-unistyles 3.0.23 → 3.0.24
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 +6 -0
- package/android/src/main/java/com/unistyles/Equatable.kt +1 -2
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +18 -5
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +15 -2
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +16 -3
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +20 -5
package/README.md
CHANGED
|
@@ -71,6 +71,12 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
|
|
|
71
71
|
<a href="https://github.com/andkindness">
|
|
72
72
|
<img src="https://avatars.githubusercontent.com/u/143941782?v=4" height="70px" width="70px" alt="andkindness" />
|
|
73
73
|
</a>
|
|
74
|
+
<a href="https://github.com/AdiRishi">
|
|
75
|
+
<img src="https://avatars.githubusercontent.com/u/8351234?v=4" height="70px" width="70px" alt="AdiRishi" />
|
|
76
|
+
</a>
|
|
77
|
+
<a href="https://github.com/cybercarrot">
|
|
78
|
+
<img src="https://avatars.githubusercontent.com/u/6837094?v=4" height="70px" width="70px" alt="cybercarrot" />
|
|
79
|
+
</a>
|
|
74
80
|
|
|
75
81
|
|
|
76
82
|
## Past sponsors
|
|
@@ -11,8 +11,7 @@ fun Dimensions.isEqualTo(other: Dimensions): Boolean {
|
|
|
11
11
|
|
|
12
12
|
fun Insets.isEqualTo(other: Insets): Boolean {
|
|
13
13
|
return this.top == other.top && this.bottom == other.bottom &&
|
|
14
|
-
this.left == other.left && this.right == other.right
|
|
15
|
-
this.ime == other.ime
|
|
14
|
+
this.left == other.left && this.right == other.right
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
fun NativePlatformAndroid.diffMiniRuntimes(lhs: UnistylesNativeMiniRuntime, rhs: UnistylesNativeMiniRuntime): Array<UnistyleDependency> {
|
|
@@ -67,6 +67,8 @@ class NativePlatformInsets(
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
fun setInsets(insetsCompat: WindowInsetsCompat, window: Window, animatedBottomInsets: Double?, skipUpdate: Boolean = false) {
|
|
70
|
+
val previousInsets = this._insets
|
|
71
|
+
|
|
70
72
|
// below Android 11, we need to use window flags to detect status bar visibility
|
|
71
73
|
val isStatusBarVisible = when(Build.VERSION.SDK_INT) {
|
|
72
74
|
in 30..Int.MAX_VALUE -> {
|
|
@@ -117,8 +119,6 @@ class NativePlatformInsets(
|
|
|
117
119
|
else -> 0.0
|
|
118
120
|
}
|
|
119
121
|
|
|
120
|
-
val shouldEmitImeEvent = Build.VERSION.SDK_INT < 30 && imeInsets != this._insets.ime || animatedBottomInsets != null && Build.VERSION.SDK_INT >= 30
|
|
121
|
-
|
|
122
122
|
this._insets = Insets(
|
|
123
123
|
statusBarTopInset.toDouble(),
|
|
124
124
|
bottomInset.toDouble(),
|
|
@@ -126,15 +126,26 @@ class NativePlatformInsets(
|
|
|
126
126
|
insets.right.toDouble(),
|
|
127
127
|
imeInsets
|
|
128
128
|
)
|
|
129
|
+
val didInsetsChange = !previousInsets.isEqualTo(this._insets)
|
|
130
|
+
val didImeChange = previousInsets.ime != this._insets.ime
|
|
131
|
+
val shouldEmitImeEvent =
|
|
132
|
+
didImeChange && (
|
|
133
|
+
Build.VERSION.SDK_INT < 30 ||
|
|
134
|
+
animatedBottomInsets != null && Build.VERSION.SDK_INT >= 30
|
|
135
|
+
)
|
|
129
136
|
|
|
130
137
|
if (skipUpdate) {
|
|
131
138
|
return
|
|
132
139
|
}
|
|
133
140
|
|
|
134
|
-
|
|
141
|
+
if (didInsetsChange) {
|
|
142
|
+
this@NativePlatformInsets.onConfigChange()
|
|
143
|
+
}
|
|
135
144
|
|
|
136
145
|
if (shouldEmitImeEvent) {
|
|
137
|
-
this@NativePlatformInsets.emitImeEvent(
|
|
146
|
+
this@NativePlatformInsets.emitImeEvent(
|
|
147
|
+
this.getMiniRuntime().copy(insets = this.getInsets())
|
|
148
|
+
)
|
|
138
149
|
}
|
|
139
150
|
}
|
|
140
151
|
|
|
@@ -162,7 +173,9 @@ class NativePlatformInsets(
|
|
|
162
173
|
return insets
|
|
163
174
|
}
|
|
164
175
|
|
|
165
|
-
runningAnimations.firstOrNull
|
|
176
|
+
runningAnimations.firstOrNull { animation ->
|
|
177
|
+
animation.typeMask and WindowInsetsCompat.Type.ime() != 0
|
|
178
|
+
}?.let {
|
|
166
179
|
val bottomInset = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom.toDouble() - this@NativePlatformInsets._insets.bottom
|
|
167
180
|
val nextBottomInset = if (bottomInset < 0) {
|
|
168
181
|
0.0
|
|
@@ -36,6 +36,8 @@ const useProxifiedUnistyles = forcedTheme => {
|
|
|
36
36
|
const [theme, setTheme] = (0, _react.useState)(_specs.UnistylesRuntime.getTheme(scopedTheme));
|
|
37
37
|
const [_, runtimeChanged] = (0, _react.useReducer)(() => ({}), {});
|
|
38
38
|
const disposeRef = (0, _react.useRef)(undefined);
|
|
39
|
+
const syncedDependenciesSizeRef = (0, _react.useRef)(-1);
|
|
40
|
+
const syncedScopedThemeRef = (0, _react.useRef)(undefined);
|
|
39
41
|
const reinitListener = () => {
|
|
40
42
|
disposeRef.current?.();
|
|
41
43
|
disposeRef.current = (0, _listener.listener)({
|
|
@@ -55,9 +57,8 @@ const useProxifiedUnistyles = forcedTheme => {
|
|
|
55
57
|
});
|
|
56
58
|
};
|
|
57
59
|
(0, _react.useEffect)(() => {
|
|
58
|
-
reinitListener();
|
|
59
60
|
return () => disposeRef.current?.();
|
|
60
|
-
}, [
|
|
61
|
+
}, [disposeRef]);
|
|
61
62
|
const maybeNewScopedTheme = _specs.UnistylesShadowRegistry.getScopedTheme();
|
|
62
63
|
if (scopedTheme && maybeNewScopedTheme && scopedTheme !== maybeNewScopedTheme) {
|
|
63
64
|
setScopedTheme(maybeNewScopedTheme);
|
|
@@ -91,6 +92,16 @@ const useProxifiedUnistyles = forcedTheme => {
|
|
|
91
92
|
return target[prop];
|
|
92
93
|
}
|
|
93
94
|
});
|
|
95
|
+
(0, _react.useLayoutEffect)(() => {
|
|
96
|
+
const sameDeps = syncedDependenciesSizeRef.current === dependencies.size;
|
|
97
|
+
const sameScopedTheme = syncedScopedThemeRef.current === scopedTheme;
|
|
98
|
+
if (sameDeps && sameScopedTheme) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
syncedDependenciesSizeRef.current = dependencies.size;
|
|
102
|
+
syncedScopedThemeRef.current = scopedTheme;
|
|
103
|
+
reinitListener();
|
|
104
|
+
}, [proxifiedTheme, proxifiedRuntime, scopedTheme]);
|
|
94
105
|
return {
|
|
95
106
|
proxifiedTheme,
|
|
96
107
|
proxifiedRuntime,
|
|
@@ -102,6 +113,8 @@ const useProxifiedUnistyles = forcedTheme => {
|
|
|
102
113
|
if (dependenciesSize === dependencies.size) {
|
|
103
114
|
return;
|
|
104
115
|
}
|
|
116
|
+
syncedDependenciesSizeRef.current = dependencies.size;
|
|
117
|
+
syncedScopedThemeRef.current = scopedTheme;
|
|
105
118
|
reinitListener();
|
|
106
119
|
}
|
|
107
120
|
};
|
|
@@ -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","reinitListener","current","listener","Array","from","updateTheme","updateRuntime","hasThemeNameChange","useEffect","
|
|
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;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AAHA;;AAKA,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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,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":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { useEffect, useReducer, useRef, useState } from 'react';
|
|
3
|
+
import { useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react';
|
|
4
4
|
import { UnistylesRuntime, UnistylesShadowRegistry } from '../../specs';
|
|
5
5
|
// It's imported that way because of circular dependency
|
|
6
6
|
import { UnistyleDependency } from '../../specs/NativePlatform';
|
|
@@ -31,6 +31,8 @@ export const useProxifiedUnistyles = forcedTheme => {
|
|
|
31
31
|
const [theme, setTheme] = useState(UnistylesRuntime.getTheme(scopedTheme));
|
|
32
32
|
const [_, runtimeChanged] = useReducer(() => ({}), {});
|
|
33
33
|
const disposeRef = useRef(undefined);
|
|
34
|
+
const syncedDependenciesSizeRef = useRef(-1);
|
|
35
|
+
const syncedScopedThemeRef = useRef(undefined);
|
|
34
36
|
const reinitListener = () => {
|
|
35
37
|
disposeRef.current?.();
|
|
36
38
|
disposeRef.current = listener({
|
|
@@ -50,9 +52,8 @@ export const useProxifiedUnistyles = forcedTheme => {
|
|
|
50
52
|
});
|
|
51
53
|
};
|
|
52
54
|
useEffect(() => {
|
|
53
|
-
reinitListener();
|
|
54
55
|
return () => disposeRef.current?.();
|
|
55
|
-
}, [
|
|
56
|
+
}, [disposeRef]);
|
|
56
57
|
const maybeNewScopedTheme = UnistylesShadowRegistry.getScopedTheme();
|
|
57
58
|
if (scopedTheme && maybeNewScopedTheme && scopedTheme !== maybeNewScopedTheme) {
|
|
58
59
|
setScopedTheme(maybeNewScopedTheme);
|
|
@@ -86,6 +87,16 @@ export const useProxifiedUnistyles = forcedTheme => {
|
|
|
86
87
|
return target[prop];
|
|
87
88
|
}
|
|
88
89
|
});
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
const sameDeps = syncedDependenciesSizeRef.current === dependencies.size;
|
|
92
|
+
const sameScopedTheme = syncedScopedThemeRef.current === scopedTheme;
|
|
93
|
+
if (sameDeps && sameScopedTheme) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
syncedDependenciesSizeRef.current = dependencies.size;
|
|
97
|
+
syncedScopedThemeRef.current = scopedTheme;
|
|
98
|
+
reinitListener();
|
|
99
|
+
}, [proxifiedTheme, proxifiedRuntime, scopedTheme]);
|
|
89
100
|
return {
|
|
90
101
|
proxifiedTheme,
|
|
91
102
|
proxifiedRuntime,
|
|
@@ -97,6 +108,8 @@ export const useProxifiedUnistyles = forcedTheme => {
|
|
|
97
108
|
if (dependenciesSize === dependencies.size) {
|
|
98
109
|
return;
|
|
99
110
|
}
|
|
111
|
+
syncedDependenciesSizeRef.current = dependencies.size;
|
|
112
|
+
syncedScopedThemeRef.current = scopedTheme;
|
|
100
113
|
reinitListener();
|
|
101
114
|
}
|
|
102
115
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useReducer","useRef","useState","UnistylesRuntime","UnistylesShadowRegistry","UnistyleDependency","listener","getMiniRuntime","miniRuntime","RTDependencyMap","breakpoint","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","getScopedTheme","dependencies","Set","theme","setTheme","getTheme","_","runtimeChanged","disposeRef","undefined","reinitListener","current","Array","from","updateTheme","updateRuntime","hasThemeNameChange","
|
|
1
|
+
{"version":3,"names":["useEffect","useLayoutEffect","useReducer","useRef","useState","UnistylesRuntime","UnistylesShadowRegistry","UnistyleDependency","listener","getMiniRuntime","miniRuntime","RTDependencyMap","breakpoint","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","getScopedTheme","dependencies","Set","theme","setTheme","getTheme","_","runtimeChanged","disposeRef","undefined","syncedDependenciesSizeRef","syncedScopedThemeRef","reinitListener","current","Array","from","updateTheme","updateRuntime","hasThemeNameChange","maybeNewScopedTheme","proxifiedTheme","Proxy","get","target","prop","add","Theme","proxifiedRuntime","Ime","sameDeps","size","sameScopedTheme","addDependencies","newDependencies","dependenciesSize","forEach","dependency"],"sourceRoot":"../../../../src","sources":["core/useProxifiedUnistyles/useProxifiedUnistyles.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,eAAe,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAChF,SAAoCC,gBAAgB,EAAEC,uBAAuB,QAAQ,aAAa;AAClG;AACA,SAASC,kBAAkB,QAAQ,4BAA4B;AAE/D,SAASC,QAAQ,QAAQ,YAAY;AAErC,MAAMC,cAAc,GAAGA,CAAA,KAA4B;EAC/C;EACA,OAAOJ,gBAAgB,CAACK,WAAW;AACvC,CAAC;AAED,MAAMC,eAAe,GAAG;EACpBC,UAAU,EAAEL,kBAAkB,CAACM,WAAW;EAC1CC,WAAW,EAAEP,kBAAkB,CAACQ,WAAW;EAC3CC,mBAAmB,EAAET,kBAAkB,CAACU,mBAAmB;EAC3DC,iBA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xC;MACJ;MAEApB,yBAAyB,CAACG,OAAO,GAAGZ,YAAY,CAAC6B,IAAI;MACrDnB,oBAAoB,CAACE,OAAO,GAAGf,WAAW;MAC1Cc,cAAc,CAAC,CAAC;IACpB;EACJ,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProxifiedUnistyles.d.ts","sourceRoot":"","sources":["../../../../../src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAA6C,MAAM,aAAa,CAAA;AAElG,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAyBjD,eAAO,MAAM,qBAAqB,GAAI,cAAc,cAAc;;;
|
|
1
|
+
{"version":3,"file":"useProxifiedUnistyles.d.ts","sourceRoot":"","sources":["../../../../../src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,oBAAoB,EAA6C,MAAM,aAAa,CAAA;AAElG,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAyBjD,eAAO,MAAM,qBAAqB,GAAI,cAAc,cAAc;;;uCA8FvB,KAAK,CAAC,kBAAkB,CAAC;CAgBnE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useReducer, useRef, useState } from 'react'
|
|
1
|
+
import { useEffect, useLayoutEffect, useReducer, useRef, useState } from 'react'
|
|
2
2
|
import { type UnistylesMiniRuntime, UnistylesRuntime, UnistylesShadowRegistry } from '../../specs'
|
|
3
3
|
// It's imported that way because of circular dependency
|
|
4
4
|
import { UnistyleDependency } from '../../specs/NativePlatform'
|
|
@@ -33,6 +33,8 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
|
33
33
|
const [theme, setTheme] = useState(UnistylesRuntime.getTheme(scopedTheme))
|
|
34
34
|
const [_, runtimeChanged] = useReducer(() => ({}), {})
|
|
35
35
|
const disposeRef = useRef<VoidFunction>(undefined)
|
|
36
|
+
const syncedDependenciesSizeRef = useRef(-1)
|
|
37
|
+
const syncedScopedThemeRef = useRef<UnistylesTheme | undefined>(undefined)
|
|
36
38
|
|
|
37
39
|
const reinitListener = () => {
|
|
38
40
|
disposeRef.current?.()
|
|
@@ -56,11 +58,8 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
useEffect(() => {
|
|
59
|
-
reinitListener()
|
|
60
|
-
|
|
61
61
|
return () => disposeRef.current?.()
|
|
62
|
-
}, [
|
|
63
|
-
|
|
62
|
+
}, [disposeRef])
|
|
64
63
|
|
|
65
64
|
const maybeNewScopedTheme = UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
|
|
66
65
|
|
|
@@ -105,6 +104,20 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
|
105
104
|
}
|
|
106
105
|
})
|
|
107
106
|
|
|
107
|
+
useLayoutEffect(() => {
|
|
108
|
+
const sameDeps = syncedDependenciesSizeRef.current === dependencies.size
|
|
109
|
+
const sameScopedTheme = syncedScopedThemeRef.current === scopedTheme
|
|
110
|
+
|
|
111
|
+
if (sameDeps && sameScopedTheme) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
syncedDependenciesSizeRef.current = dependencies.size
|
|
116
|
+
syncedScopedThemeRef.current = scopedTheme
|
|
117
|
+
|
|
118
|
+
reinitListener()
|
|
119
|
+
}, [proxifiedTheme, proxifiedRuntime, scopedTheme])
|
|
120
|
+
|
|
108
121
|
return {
|
|
109
122
|
proxifiedTheme,
|
|
110
123
|
proxifiedRuntime,
|
|
@@ -119,6 +132,8 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
|
119
132
|
return
|
|
120
133
|
}
|
|
121
134
|
|
|
135
|
+
syncedDependenciesSizeRef.current = dependencies.size
|
|
136
|
+
syncedScopedThemeRef.current = scopedTheme
|
|
122
137
|
reinitListener()
|
|
123
138
|
}
|
|
124
139
|
}
|