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.setColorScheme support (revisited) #36122

Closed
wants to merge 12 commits into from

Conversation

birkir
Copy link
Contributor

@birkir birkir commented Feb 10, 2023

Summary

Both Android and iOS allow you to set application specific user interface style, which is useful for applications that support both light and dark mode.

With the newly added Appearance.setColorScheme, you can natively manage the application's user interface style rather than keeping that preference in JavaScript. The benefit is that native dialogs like alert, keyboard, action sheets and more will also be affected by this change.

Implemented using Android X AppCompatDelegate.setDefaultNightMode and iOS 13+ overrideUserInterfaceStyle

// Lets assume a given device is set to **dark** mode.

Appearance.getColorScheme(); // `dark`

// Set the app's user interface to `light`
Appearance.setColorScheme('light');

Appearance.getColorScheme(); // `light`

// Set the app's user interface to `unspecified`
Appearance.setColorScheme(null);

Appearance.getColorScheme() // `dark`

Changelog

[GENERAL] [ADDED] - Added setColorScheme to Appearance module

Test Plan

Added a RNTester for the feature in the Appearance section.

Three buttons for toggling all set of modes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 10, 2023
@analysis-bot
Copy link

analysis-bot commented Feb 10, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 8,486,696 +668
android hermes armeabi-v7a 7,807,536 +547
android hermes x86 8,964,127 +697
android hermes x86_64 8,820,973 +762
android jsc arm64-v8a 6,700,260 +454
android jsc armeabi-v7a 7,491,657 +329
android jsc x86 9,225,152 +482
android jsc x86_64 6,925,502 +545

Base commit: 70fb2dc
Branch: main

@birkir
Copy link
Contributor Author

birkir commented Feb 14, 2023

Please provide guidance on further improvements for this PR, if any.

@NickGerleman @jacdebug @cortinico

@cortinico
Copy link
Contributor

/rebase

@cortinico
Copy link
Contributor

@NickGerleman should be taking care of this one. Don't you mind rebasing on top of main as the CI should be green now 👍

@facebook-github-bot
Copy link
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@NickGerleman
Copy link
Contributor

@birkir would you be willing to add the new API to this page as well? https://github.com/facebook/react-native-website/blob/main/docs/appearance.md

@birkir
Copy link
Contributor Author

birkir commented Feb 21, 2023

CI still broken I guess

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Feb 28, 2023
@facebook-github-bot
Copy link
Contributor

@NickGerleman merged this pull request in c18566f.

facebook-github-bot pushed a commit that referenced this pull request Mar 14, 2023
Summary:
After #36122 we have two of these. This change consolidates the two category methods to be part of the base RCTConvert class instead.

Changelog:
[iOS][Fixed] - Fix duplicate [RCTConvert UIUserInterfaceStyle:]

Reviewed By: cipolleschi

Differential Revision: D44050929

fbshipit-source-id: dd216545e6194446c593cd693072f3959d653d7f
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
Both Android and iOS allow you to set application specific user interface style, which is useful for applications that support both light and dark mode.

With the newly added `Appearance.setColorScheme`, you can natively manage the application's user interface style rather than keeping that preference in JavaScript. The benefit is that native dialogs like alert, keyboard, action sheets and more will also be affected by this change.

Implemented using Android X [AppCompatDelegate.setDefaultNightMode](https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate#setDefaultNightMode(int)) and iOS 13+ [overrideUserInterfaceStyle](https://developer.apple.com/documentation/uikit/uiview/3238086-overrideuserinterfacestyle?language=objc)

```tsx
// Lets assume a given device is set to **dark** mode.

Appearance.getColorScheme(); // `dark`

// Set the app's user interface to `light`
Appearance.setColorScheme('light');

Appearance.getColorScheme(); // `light`

// Set the app's user interface to `unspecified`
Appearance.setColorScheme(null);

Appearance.getColorScheme() // `dark`
 ```

## Changelog

[GENERAL] [ADDED] - Added `setColorScheme` to `Appearance` module

Pull Request resolved: facebook#36122

Test Plan:
Added a RNTester for the feature in the Appearance section.

Three buttons for toggling all set of modes.

Reviewed By: lunaleaps

Differential Revision: D43331405

Pulled By: NickGerleman

fbshipit-source-id: 3b15f1ed0626d1ad7a8266ec026e903cd3ec46aa
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
After facebook#36122 we have two of these. This change consolidates the two category methods to be part of the base RCTConvert class instead.

Changelog:
[iOS][Fixed] - Fix duplicate [RCTConvert UIUserInterfaceStyle:]

Reviewed By: cipolleschi

Differential Revision: D44050929

fbshipit-source-id: dd216545e6194446c593cd693072f3959d653d7f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants