Skip to content
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

Apperance.getColorScheme() returns incorrect value if app opened in background (e.g. using Healthkit.HKObserverQuery) #46015

Closed
walterholohan opened this issue Aug 14, 2024 · 7 comments
Labels
Resolution: Fixed A PR that fixes this issue has been merged.

Comments

@walterholohan
Copy link

walterholohan commented Aug 14, 2024

Description

When using a background process like Healthkit.HKObserverQuery it will wake up the app in the background to process new activities in HealthKit. When this happens Apperance.getColorScheme() will return 'light' even if the system color scheme is 'dark'

Steps to reproduce

  1. Use https://github.com/kingstinct/react-native-healthkit to enable enableBackgroundDelivery i.e. HealthKit.enableBackgroundDelivery(HKWorkoutTypeIdentifier, HKUpdateFrequency.immediate)
  2. app has been force closed
  3. record a workout an Apple Workouts app on Apple Watch
  4. save the workout
  5. the app will open in the background and process the new workout
  6. open the app after a couple of minutes, then the app will open in Light mode i.e. Appearance.getColorScheme() will be 'light'

React Native Version

0.74.3

Affected Platforms

Runtime - iOS

Output of npx react-native info

System:
  OS: macOS 14.5
  CPU: (10) arm64 Apple M1 Pro
  Memory: 137.53 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.19.1
    path: ~/.nvm/versions/node/v18.19.1/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.4
    path: ~/.nvm/versions/node/v18.19.1/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/walterholohan/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.12
    path: /usr/local/opt/openjdk@11/bin/javac
  Ruby:
    version: 3.0.4
    path: /Users/walterholohan/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.3
    wanted: 0.74.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

Appearance.getColorScheme() will return 'light' when the app opens

Reproducer

I created a new native module in iOS to test if it was a iOS or RN bug. The below code will return the correct value so hence its a bug with RN

import UIKit

@objc(RbAppearance)
class RbAppearance: NSObject {

  @objc(getColorScheme:withRejecter:)
  func getColorScheme(resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
    let colorScheme = UITraitCollection.current.userInterfaceStyle
      
      switch colorScheme {
          case .dark:
              resolve("dark")
          case .light:
              resolve("light")
          @unknown default:
              resolve("unknown")
          }
  }
}

Screenshots and Videos

No response

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Aug 14, 2024
@react-native-bot
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@react-native-bot
Copy link
Collaborator

⚠️ Add or Reformat Version Info
ℹ️ We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2

@react-native-bot
Copy link
Collaborator

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:

@react-native-bot
Copy link
Collaborator

⚠️ Add or Reformat Version Info
ℹ️ We could not find or parse the version number of React Native in your issue report. Please use the template, and report your version including major, minor, and patch numbers - e.g. 0.70.2

@RodolfoGS
Copy link
Contributor

I have the same issue but with expo-background-fetch, looks like that is the same bug.
@walterholohan, did you tested the @zhongwuzw's PR?

@zhongwuzw
Copy link
Contributor

@RodolfoGS Yeah, you can try that fix.

@walterholohan
Copy link
Author

Thanks all, yep will try that and use as a patch.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Aug 15, 2024
@cortinico cortinico added Resolution: Fixed A PR that fixes this issue has been merged. and removed Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Attention Issues where the author has responded to feedback. labels Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Fixed A PR that fixes this issue has been merged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants