react / react/react-native

[0.83.1] useColorScheme returns unspecified when state updates

未关闭
#54,959 4 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Needs: Triage :mag:
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

I’m using useColorScheme to manage theming in my app.

The app has three theme options: System, Dark, and Light.

  • When System is selected, I call Appearance.setColorScheme('unspecified').
  • When Dark is selected, I call Appearance.setColorScheme('dark').
  • When Light is selected, I call Appearance.setColorScheme('light').

If the system theme is dark and I call Appearance.setColorScheme('unspecified'), useColorScheme correctly returns dark.

However, if I update a state during the same button click, useColorScheme starts returning unspecified instead.

Steps to reproduce
  1. Change color schemes by clicking buttons
  2. It should work
  3. Enable state change by clicking enable state change button
  4. Change color schemes by clicking buttons
  5. It returns unspecified when you change from system color (dark or light) to system
React Native Version

0.83.1

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.2
  CPU: (8) arm64 Apple M1 Pro
  Memory: 108.17 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.19.0
    path: /Users/aykutsaki/.nvm/versions/node/v22.19.0/bin/node
  Yarn:
    version: 1.22.15
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.9.3
    path: /Users/aykutsaki/.nvm/versions/node/v22.19.0/bin/npm
  Watchman:
    version: 2025.05.26.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.2
      - iOS 26.2
      - macOS 26.2
      - tvOS 26.2
      - visionOS 26.2
      - watchOS 26.2
  Android SDK:
    API Levels:
      - "31"
      - "35"
      - "36"
    Build Tools:
      - 35.0.0
      - 36.0.0
    System Images:
      - android-35 | Google Play ARM 64 v8a
      - android-36 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.25557.131.2521.14344949
  Xcode:
    version: 26.2/17C52
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /Users/aykutsaki/.jenv/shims/javac
  Ruby:
    version: 3.2.2
    path: /Users/aykutsaki/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.2.0
    wanted: 19.2.0
  react-native:
    installed: 0.83.1
    wanted: 0.83.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
No crash
MANDATORY Reproducer

https://github.com/AuroPick/color-scheme-unspecified

Screenshots and Videos

https://github.com/user-attachments/assets/78519563-4a32-44c0-8bf3-2a997bff4f57

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先在 iOS 上运行 https://github.com/AuroPick/color-scheme-unspecified 中的必需复现程序,并观察 useColorScheme 与 Appearance.setColorScheme 的行为。跟踪状态更新路径,并验证再次选择 System 时报告的是解析后的系统主题,而不是 unspecified,包括在同一次按钮点击中另一个状态也发生变化的情况。

由索引模型根据 Issue 内容生成。

评估

技术栈
react-native
领域
mobile
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。