Skip to content

fix(android): update the tab bar after Appearance.setColorScheme() - #628

Open
oleksandrzavarzin-callstack wants to merge 1 commit into
callstack:mainfrom
oleksandrzavarzin-callstack:fix/android-set-color-scheme
Open

oleksandrzavarzin-callstack wants to merge 1 commit into
callstack:mainfrom
oleksandrzavarzin-callstack:fix/android-set-color-scheme

Conversation

@oleksandrzavarzin-callstack

Copy link
Copy Markdown
Contributor

Closes #397.

PR Description

On Android, the tab bar kept its old colors after Appearance.setColorScheme(). Only a system dark mode change or a new mount of the tab bar changed the colors.

React Native implements setColorScheme with AppCompatDelegate.setDefaultNightMode. AppCompat updates the Activity configuration, but Android does not call onConfigurationChanged on the views. The code from #305 that creates the bar again runs only in that view callback, so it never ran.

This PR adds a second trigger for the same code. While the view is attached, it listens to the Activity with addOnConfigurationChangedListener from androidx. A change can also happen while the view is detached. For that case, the view compares the configuration each time it attaches.

A tab bar with tabBarStyle.backgroundColor or barTintColor keeps the current behavior: the library does not create it again.

How to test?

  1. Render the tabs without a custom bar color.
  2. Call Appearance.setColorScheme('dark'), for example from a button.
  3. Make sure that the tab bar turns dark.
  4. Call Appearance.setColorScheme('light').
  5. Make sure that the tab bar turns light, and that a tab press still works.

Tested on Android 8.1 (API 27), Android 13 (API 33), and the Android 17 beta (API 37). The system dark mode path still works on all 3.

Videos

Light to dark Dark to light
Before
397-android-37-before-light-to-dark.mp4
397-android-37-before-dark-to-light.mp4
After
397-android-37-after-light-to-dark.mp4
397-android-37-after-dark-to-light.mp4

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Tab bar does not react to color change if useColorScheme omitted

1 participant