-
Notifications
You must be signed in to change notification settings - Fork 9
修复主题自动异常切换 #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
klxiaoniu
wants to merge
1
commit into
master
Choose a base branch
from
fix/css-interop-dark-mode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+189
−17
Open
修复主题自动异常切换 #394
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| diff --git a/node_modules/react-native-css-interop/dist/runtime/native/appearance-observables.js b/node_modules/react-native-css-interop/dist/runtime/native/appearance-observables.js | ||
| index ff931dc..2d93872 100644 | ||
| --- a/node_modules/react-native-css-interop/dist/runtime/native/appearance-observables.js | ||
| +++ b/node_modules/react-native-css-interop/dist/runtime/native/appearance-observables.js | ||
| @@ -33,7 +33,7 @@ exports.colorScheme = { | ||
| toggle() { | ||
| let current = colorSchemeObservable.get(); | ||
| if (current === undefined) | ||
| - current = appearance.getColorScheme() ?? "light"; | ||
| + current = resolveColorScheme(appearance.getColorScheme()); | ||
| exports.colorScheme.set(current === "light" ? "dark" : "light"); | ||
| }, | ||
| [shared_1.INTERNAL_RESET]: (appearance) => { | ||
| @@ -68,6 +68,11 @@ function cssVariableObservable(value, { name } = {}) { | ||
| }, | ||
| }; | ||
| } | ||
| +function resolveColorScheme(scheme) { | ||
| + if (scheme === "light" || scheme === "dark") | ||
| + return scheme; | ||
| + return exports.systemColorScheme.get() ?? "light"; | ||
| +} | ||
| let appearance = react_native_1.Appearance; | ||
| let appearanceListener; | ||
| let appStateListener; | ||
| @@ -77,13 +82,12 @@ function resetAppearanceListeners($appearance, appState) { | ||
| appStateListener?.remove(); | ||
| appearanceListener = appearance.addChangeListener((state) => { | ||
| if (react_native_1.AppState.currentState === "active") { | ||
| - exports.systemColorScheme.set(state.colorScheme ?? "light"); | ||
| + exports.systemColorScheme.set(resolveColorScheme(state.colorScheme)); | ||
| } | ||
| }); | ||
| appStateListener = appState.addEventListener("change", (type) => { | ||
| if (type === "active") { | ||
| - const colorScheme = appearance.getColorScheme() ?? "light"; | ||
| - exports.systemColorScheme.set(colorScheme); | ||
| + exports.systemColorScheme.set(resolveColorScheme(appearance.getColorScheme())); | ||
| } | ||
| }); | ||
| } | ||
| diff --git a/node_modules/react-native-css-interop/dist/runtime/native/appearance-observables.js.map b/node_modules/react-native-css-interop/dist/runtime/native/appearance-observables.js.map | ||
| index aad5f62..292e606 100644 | ||
| --- a/node_modules/react-native-css-interop/dist/runtime/native/appearance-observables.js.map | ||
| +++ b/node_modules/react-native-css-interop/dist/runtime/native/appearance-observables.js.map | ||
| @@ -1 +1 @@ | ||
| -{"version":3,"file":"appearance-observables.js","sourceRoot":"","sources":["../../../src/runtime/native/appearance-observables.ts"],"names":[],"mappings":";;;AA6DA,sDA2BC;AAxFD,+CAMsB;AAEtB,yCAA8C;AAE9C,8CAAsE;AAKzD,QAAA,iBAAiB,GAAG,IAAA,uBAAU,EACzC,yBAAU,CAAC,cAAc,EAAE,IAAI,OAAO,CACvC,CAAC;AACF,MAAM,qBAAqB,GAAG,IAAA,uBAAU,EACtC,SAAS,CACV,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
| \ No newline at end of file | ||
| +{"version":3,"file":"appearance-observables.js","sourceRoot":"","sources":["../../../src/runtime/native/appearance-observables.ts"],"names":[],"mappings":";;;AA8DA,sDA2BC;AAzFD,+CAMsB;AAEtB,yCAA8C;AAE9C,8CAAsE;AAKzD,QAAA,iBAAiB,GAAG,IAAA,uBAAU,EACzC,yBAAU,CAAC,cAAc,EAAE,IAAI,OAAO,CACvC,CAAC;AACF,MAAM,qBAAqB,GAAG,IAAA,uBAAU,EACtC,SAAS,CACV,CAAC;AAEW,QAAA,WAAW,GAAG;IACzB,GAAG,CAAC,KAAkC;QACpC,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvB,IAAI,CAAC,uBAAQ,CAAC,SAAS,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBAC/D,UAAU,CAAC,cAAc,CAAC,aAAoB,CAAC,CAAC;YAClD,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAGD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YACpC,qBAAqB,CAAC,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IACD,GAAG,CAAC,MAAe;QACjB,OAAO,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,yBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;IACD,SAAS,CAAC,MAAe;QACvB,OAAO,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,yBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM;QACJ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AAC,CAAC;AAKlC,QAAA,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAChD,IAAA,uBAAU,EAAU,KAAK,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC,EAC7D,EAAE,CAAC,uBAAc,CAAC,EAAE,GAAG,EAAE,CAAC,6BAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAC7D,CAAC;AAEF,gCAAiB,CAAC,qBAAqB,EAAE,EAAE,IAAI,CAAC,6BAAqB,CAAC,GAAG,CAAC,CAAC;AAC3E,gCAAiB,CAAC,gBAAgB,CAAC,qBAAqB,EAAE,CAAC,KAAK,EAAE,EAAE;IAClE,6BAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC"} | ||
| \ No newline at end of file | ||
| diff --git a/node_modules/react-native-css-interop/src/runtime/native/appearance-observables.ts b/node_modules/react-native-css-interop/src/runtime/native/appearance-observables.ts | ||
| index e0fb8a0..9f0c6fe 100644 | ||
| --- a/node_modules/react-native-css-interop/src/runtime/native/appearance-observables.ts | ||
| +++ b/node_modules/react-native-css-interop/src/runtime/native/appearance-observables.ts | ||
| @@ -45,7 +45,8 @@ export const colorScheme = { | ||
| }, | ||
| toggle() { | ||
| let current = colorSchemeObservable.get(); | ||
| - if (current === undefined) current = appearance.getColorScheme() ?? "light"; | ||
| + if (current === undefined) | ||
| + current = resolveColorScheme(appearance.getColorScheme()); | ||
| colorScheme.set(current === "light" ? "dark" : "light"); | ||
| }, | ||
| [INTERNAL_RESET]: (appearance: typeof Appearance) => { | ||
| @@ -90,7 +91,18 @@ export function cssVariableObservable( | ||
|
|
||
| /** | ||
| * Appearance | ||
| + * | ||
| + * On RN 0.82+, Appearance can emit "unspecified" during AppState transitions | ||
| + * (e.g. background→foreground). This is not a valid color scheme for consumers, | ||
| + * so we filter it out and keep the last known valid scheme. (nativewind#1722) | ||
| */ | ||
| +function resolveColorScheme( | ||
| + scheme: string | null | undefined, | ||
| +): "light" | "dark" { | ||
| + if (scheme === "light" || scheme === "dark") return scheme; | ||
| + return systemColorScheme.get() ?? "light"; | ||
| +} | ||
| + | ||
| let appearance = Appearance; | ||
| let appearanceListener: NativeEventSubscription | undefined; | ||
| let appStateListener: NativeEventSubscription | undefined; | ||
| @@ -105,14 +117,13 @@ function resetAppearanceListeners( | ||
|
|
||
| appearanceListener = appearance.addChangeListener((state) => { | ||
| if (AppState.currentState === "active") { | ||
| - systemColorScheme.set(state.colorScheme ?? "light"); | ||
| + systemColorScheme.set(resolveColorScheme(state.colorScheme)); | ||
| } | ||
| }); | ||
|
|
||
| appStateListener = appState.addEventListener("change", (type) => { | ||
| if (type === "active") { | ||
| - const colorScheme = appearance.getColorScheme() ?? "light"; | ||
| - systemColorScheme.set(colorScheme); | ||
| + systemColorScheme.set(resolveColorScheme(appearance.getColorScheme())); | ||
| } | ||
| }); | ||
| } | ||
|
klxiaoniu marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.