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

Appearance.getColorScheme() return wrong color schema for when call first time only in ios #36713

Closed
thtRajasthaniGuy opened this issue Mar 30, 2023 · 6 comments

Comments

@thtRajasthaniGuy
Copy link

Description

Appearance.getColorScheme() rerturn wrong color schema when app come from background to foreground mode everytime.

apperance.issue.mp4

React Native Version

0.70.6

Output of npx react-native info

System:
OS: macOS 13.1
CPU: (8) x64 Intel(R) Core(TM) i5-1030NG7 CPU @ 1.10GHz
Memory: 98.94 MB / 8.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.16.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 8.11.0 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.10.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.2, iOS 16.2, macOS 13.1, tvOS 16.1, watchOS 9.1
Android SDK: Not Found
IDEs:
Android Studio: 2021.3 AI-213.7172.25.2113.9123335
Xcode: 14.2/14C18 - /usr/bin/xcodebuild
Languages:
Java: 11.0.16.1 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.6 => 0.70.6
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

minimize the app from background to foreground.

Snack, code example, screenshot, or link to a repository

             import {Appearance, useColorScheme} from 'react-native';
            console.log(' Appearance.getColorScheme()', Appearance.getColorScheme());
@github-actions
Copy link

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot react-native-bot added the Platform: iOS iOS applications. label Mar 30, 2023
@effektsvk
Copy link

I can confirm that this is happening on RN 0.71.7 and according to changelog it's not fixed in 0.71.8 either.

@YaoHuiJi
Copy link

It happens on RN 0.72.0 too

ShevO27 pushed a commit to ShevO27/react-native that referenced this issue Sep 26, 2023
Summary:
Closes facebook#35972
Closes facebook#36713

This PR addresses a couple of issues with `useColorScheme` and the `Appearance` API.

- facebook#38214 introduced a regression. Using to `RCTExecuteOnMainQueue` was a mistake as we need this to happen synchronously to return the result. Doing it async causes the `traitCollection` to remain uninitialized.
- The `useColorScheme` hook is updating when the app is in the background on iOS and the OS is taking the snapshots for the app switcher. This causes a flash when returning to the app as the correct color is set again. Here, we can check for the app state in `traitCollectionDidChange` and not send these events when in the background.
- Removed a line that was left over after some OS version checks were removed when support for iOS 12 was dropped.

## Changelog:

[IOS] [FIXED] - Don't send the `RCTUserInterfaceStyleDidChangeNotification` when the app is in the background.

Pull Request resolved: facebook#39439

Test Plan: Tested on `rn-tester`, logged the changes whenever `useColorScheme` updates. It no longer happens when the app is in the background. The returned interface style on the initial render is always correct now.

Reviewed By: NickGerleman

Differential Revision: D49454281

Pulled By: javache

fbshipit-source-id: 87e24158a49c50608c79e73fb484442f5aad36a6
@Robert27
Copy link

Robert27 commented May 1, 2024

Happens to me after upgrading to RN version 0.74

@DanielKuhn
Copy link

Happening for me as well: only on first start (after fresh install of the app) useColorScheme returns light. Works fine later (manual or auto-switching theme is handled correctly)

@BrianAutomatize
Copy link

Updating react-native from 71.6 to 74.0, now 74.0 causes useColorScheme() and Appearance.getColorScheme() to always be 'light' when app first loads.
Happening only on ios first load of app, will recognize changes but everytime open ios app it is 'light' irregardless of settings.

Output of npx react-native info
System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Max
Memory: 1.74 GB / 64.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.16.0
path: ~/.nvm/versions/node/v18.16.0/bin/node
Yarn:
version: 3.6.0
path: ~/.nvm/versions/node/v18.16.0/bin/yarn
npm:
version: 9.5.1
path: ~/.nvm/versions/node/v18.16.0/bin/npm
Watchman:
version: 2024.08.05.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.5
- iOS 17.5
- macOS 14.5
- tvOS 17.5
- visionOS 1.2
- watchOS 10.5
Android SDK: Not Found
IDEs:
Android Studio: 2024.1 AI-241.18034.62.2411.12071903
Xcode:
version: 15.4/15F31d
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.11
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.74.0
wanted: 0.74.0
react-native-macos: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants