@pushwoosh/websdk-common 6.22.3 → 6.22.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushwoosh/websdk-common",
|
|
3
|
-
"version": "6.22.
|
|
3
|
+
"version": "6.22.4",
|
|
4
4
|
"description": "Code shared by the Pushwoosh WebSDK and the Control Panel, one entry point per module (web-popups: web popup model and renderer; subscription-widget: push subscription widget model and renderer; inbox: web inbox widget and inbox cell previews)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -7,13 +7,20 @@ function prefersDark() {
|
|
|
7
7
|
// be on screen when the theme flips, and a stale palette is the visible half.
|
|
8
8
|
export function useColorScheme(pref, watch) {
|
|
9
9
|
const [dark, setDark] = useState(() => pref === 'auto' && watch && prefersDark());
|
|
10
|
+
const watchDeps = [pref, watch];
|
|
11
|
+
const [prevWatchDeps, setPrevWatchDeps] = useState(null);
|
|
12
|
+
if (prevWatchDeps === null || watchDeps.some((dep, index) => dep !== prevWatchDeps[index])) {
|
|
13
|
+
setPrevWatchDeps(watchDeps);
|
|
14
|
+
if (pref === 'auto' && watch) {
|
|
15
|
+
setDark(prefersDark());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
10
18
|
useEffect(() => {
|
|
11
19
|
if (pref !== 'auto' || !watch || typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
|
|
12
20
|
return undefined;
|
|
13
21
|
}
|
|
14
22
|
const media = window.matchMedia(DARK_MEDIA_QUERY);
|
|
15
23
|
const onChange = event => setDark(event.matches);
|
|
16
|
-
setDark(media.matches);
|
|
17
24
|
media.addEventListener('change', onChange);
|
|
18
25
|
return () => media.removeEventListener('change', onChange);
|
|
19
26
|
}, [pref, watch]);
|