@vxrn/color-scheme 1.2.46 → 1.2.47
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/dist/cjs/systemScheme.native.js +16 -7
- package/dist/cjs/systemScheme.native.js.map +1 -1
- package/dist/esm/systemScheme.native.js +17 -8
- package/dist/esm/systemScheme.native.js.map +1 -1
- package/package.json +2 -2
- package/src/systemScheme.native.ts +19 -3
- package/types/systemScheme.native.d.ts.map +1 -1
|
@@ -34,14 +34,23 @@ function getSystemScheme() {
|
|
|
34
34
|
function useSystemScheme() {
|
|
35
35
|
var [scheme, setScheme] = (0, import_react.useState)(getSystemScheme);
|
|
36
36
|
return (0, import_react.useEffect)(function () {
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
var appearanceSubscription = import_react_native.Appearance.addChangeListener(function (param) {
|
|
38
|
+
var {
|
|
39
|
+
colorScheme
|
|
40
|
+
} = param;
|
|
41
|
+
setScheme(colorScheme || "light");
|
|
42
|
+
}),
|
|
43
|
+
handleAppStateChange = function (nextAppState) {
|
|
44
|
+
if (nextAppState === "active") {
|
|
45
|
+
var currentScheme = getSystemScheme();
|
|
46
|
+
setScheme(function (prev) {
|
|
47
|
+
return prev !== currentScheme ? currentScheme : prev;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
appStateSubscription = import_react_native.AppState.addEventListener("change", handleAppStateChange);
|
|
43
52
|
return function () {
|
|
44
|
-
|
|
53
|
+
appearanceSubscription.remove(), appStateSubscription.remove();
|
|
45
54
|
};
|
|
46
55
|
}, []), scheme;
|
|
47
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["systemScheme_native_exports","__export","getSystemScheme","useSystemScheme","module","exports","__toCommonJS","import_react","require","import_react_native","Appearance","getColorScheme","scheme","setScheme","useState","useEffect","
|
|
1
|
+
{"version":3,"names":["systemScheme_native_exports","__export","getSystemScheme","useSystemScheme","module","exports","__toCommonJS","import_react","require","import_react_native","Appearance","getColorScheme","scheme","setScheme","useState","useEffect","appearanceSubscription","addChangeListener","param","colorScheme","handleAppStateChange","nextAppState","currentScheme","prev","appStateSubscription","AppState","addEventListener","remove"],"sources":["../../src/systemScheme.native.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,2BAAA;AAAAC,QAAA,CAAAD,2BAAA;EAAAE,eAAA,EAAAA,CAAA,KAAAA,eAAA;EAAAC,eAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAC,YAAA,CAAAN,2BAAA;AAAA,IAAAO,YAAA,GAAoCC,OAAA;EACpCC,mBAAA,GAAqCD,OAAA;AAC9B,SAASN,gBAAA,EAAkB;EAC9B,OAAOO,mBAAA,CAAAC,UAAA,CAAWC,cAAA,CAAe,KAAK;AAC1C;AACO,SAASR,gBAAA,EAAkB;EAC9B,IAAI,CAACS,MAAA,EAAQC,SAAS,QAAIN,YAAA,CAAAO,QAAA,EAASZ,eAAe;EAClD,WAAAK,YAAA,CAAAQ,SAAA,EAAU,YAAW;IAEjB,IAAIC,sBAAA,GAAyBP,mBAAA,CAAAC,UAAA,CAAWO,iBAAA,CAAkB,UAASC,KAAA,EAAO;QACtE,IAAI;UAAEC;QAAY,IAAID,KAAA;QACtBL,SAAA,CAAUM,WAAA,IAAe,OAAO;MACpC,CAAC;MAGGC,oBAAA,GAAuB,SAAAA,CAASC,YAAA,EAAc;QAC9C,IAAIA,YAAA,KAAiB,UAAU;UAC3B,IAAIC,aAAA,GAAgBpB,eAAA,CAAgB;UACpCW,SAAA,CAAU,UAASU,IAAA,EAAM;YACrB,OAAOA,IAAA,KAASD,aAAA,GAAgBA,aAAA,GAAgBC,IAAA;UACpD,CAAC;QACL;MACJ;MACIC,oBAAA,GAAuBf,mBAAA,CAAAgB,QAAA,CAASC,gBAAA,CAAiB,UAAUN,oBAAoB;IACnF,OAAO,YAAW;MACdJ,sBAAA,CAAuBW,MAAA,CAAO,GAC9BH,oBAAA,CAAqBG,MAAA,CAAO;IAChC;EACJ,GAAG,EAAE,GACEf,MAAA;AACX","ignoreList":[]}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
|
-
import { Appearance } from "react-native";
|
|
2
|
+
import { Appearance, AppState } from "react-native";
|
|
3
3
|
function getSystemScheme() {
|
|
4
4
|
return Appearance.getColorScheme() || "light";
|
|
5
5
|
}
|
|
6
6
|
function useSystemScheme() {
|
|
7
7
|
var [scheme, setScheme] = useState(getSystemScheme);
|
|
8
8
|
return useEffect(function () {
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
var appearanceSubscription = Appearance.addChangeListener(function (param) {
|
|
10
|
+
var {
|
|
11
|
+
colorScheme
|
|
12
|
+
} = param;
|
|
13
|
+
setScheme(colorScheme || "light");
|
|
14
|
+
}),
|
|
15
|
+
handleAppStateChange = function (nextAppState) {
|
|
16
|
+
if (nextAppState === "active") {
|
|
17
|
+
var currentScheme = getSystemScheme();
|
|
18
|
+
setScheme(function (prev) {
|
|
19
|
+
return prev !== currentScheme ? currentScheme : prev;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
appStateSubscription = AppState.addEventListener("change", handleAppStateChange);
|
|
15
24
|
return function () {
|
|
16
|
-
|
|
25
|
+
appearanceSubscription.remove(), appStateSubscription.remove();
|
|
17
26
|
};
|
|
18
27
|
}, []), scheme;
|
|
19
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useEffect","Appearance","getSystemScheme","getColorScheme","useSystemScheme","scheme","setScheme","
|
|
1
|
+
{"version":3,"names":["useState","useEffect","Appearance","AppState","getSystemScheme","getColorScheme","useSystemScheme","scheme","setScheme","appearanceSubscription","addChangeListener","param","colorScheme","handleAppStateChange","nextAppState","currentScheme","prev","appStateSubscription","addEventListener","remove"],"sources":["../../src/systemScheme.native.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,QAAA,EAAUC,SAAA,QAAiB;AACpC,SAASC,UAAA,EAAYC,QAAA,QAAgB;AAC9B,SAASC,gBAAA,EAAkB;EAC9B,OAAOF,UAAA,CAAWG,cAAA,CAAe,KAAK;AAC1C;AACO,SAASC,gBAAA,EAAkB;EAC9B,IAAI,CAACC,MAAA,EAAQC,SAAS,IAAIR,QAAA,CAASI,eAAe;EAClD,OAAAH,SAAA,CAAU,YAAW;IAEjB,IAAIQ,sBAAA,GAAyBP,UAAA,CAAWQ,iBAAA,CAAkB,UAASC,KAAA,EAAO;QACtE,IAAI;UAAEC;QAAY,IAAID,KAAA;QACtBH,SAAA,CAAUI,WAAA,IAAe,OAAO;MACpC,CAAC;MAGGC,oBAAA,GAAuB,SAAAA,CAASC,YAAA,EAAc;QAC9C,IAAIA,YAAA,KAAiB,UAAU;UAC3B,IAAIC,aAAA,GAAgBX,eAAA,CAAgB;UACpCI,SAAA,CAAU,UAASQ,IAAA,EAAM;YACrB,OAAOA,IAAA,KAASD,aAAA,GAAgBA,aAAA,GAAgBC,IAAA;UACpD,CAAC;QACL;MACJ;MACIC,oBAAA,GAAuBd,QAAA,CAASe,gBAAA,CAAiB,UAAUL,oBAAoB;IACnF,OAAO,YAAW;MACdJ,sBAAA,CAAuBU,MAAA,CAAO,GAC9BF,oBAAA,CAAqBE,MAAA,CAAO;IAChC;EACJ,GAAG,EAAE,GACEZ,MAAA;AACX","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vxrn/color-scheme",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.47",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package.json": "./package.json",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"watch": "tamagui-build --watch"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@vxrn/use-isomorphic-layout-effect": "1.2.
|
|
35
|
+
"@vxrn/use-isomorphic-layout-effect": "1.2.47"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@tamagui/build": "^1.142.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react'
|
|
2
|
-
import { Appearance } from 'react-native'
|
|
2
|
+
import { Appearance, AppState, type AppStateStatus } from 'react-native'
|
|
3
3
|
|
|
4
4
|
export type Scheme = 'light' | 'dark'
|
|
5
5
|
|
|
@@ -11,10 +11,26 @@ export function useSystemScheme(): Scheme {
|
|
|
11
11
|
const [scheme, setScheme] = useState<Scheme>(getSystemScheme)
|
|
12
12
|
|
|
13
13
|
useEffect(() => {
|
|
14
|
-
|
|
14
|
+
// Listen for appearance changes while app is active
|
|
15
|
+
const appearanceSubscription = Appearance.addChangeListener(({ colorScheme }) => {
|
|
15
16
|
setScheme(colorScheme || 'light')
|
|
16
17
|
})
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
// Also check when app comes back to foreground, as appearance change
|
|
20
|
+
// events may not fire if the theme changed while app was in background
|
|
21
|
+
const handleAppStateChange = (nextAppState: AppStateStatus) => {
|
|
22
|
+
if (nextAppState === 'active') {
|
|
23
|
+
const currentScheme = getSystemScheme()
|
|
24
|
+
setScheme((prev) => (prev !== currentScheme ? currentScheme : prev))
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const appStateSubscription = AppState.addEventListener('change', handleAppStateChange)
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
appearanceSubscription.remove()
|
|
32
|
+
appStateSubscription.remove()
|
|
33
|
+
}
|
|
18
34
|
}, [])
|
|
19
35
|
|
|
20
36
|
return scheme
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemScheme.native.d.ts","sourceRoot":"","sources":["../src/systemScheme.native.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAErC,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,eAAe,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"systemScheme.native.d.ts","sourceRoot":"","sources":["../src/systemScheme.native.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAErC,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,eAAe,IAAI,MAAM,CA2BxC"}
|