When toggling Dark Mode in iOS, we can see the app previews in the app switcher immediately change their appearances even though suspended in the background.
This post aims to find out if it's possible to achieve this in React Native (regardless of using bare React Native or Expo), and if not, is there anyway we can help make it possible?
Observe the animation:
Or click here if it's not displaying.
- The native Settings app, even though suspended in background, changes it's appearance when Dark Mode is toggled
- The Expo client app, also suspended in the background (the app switcher was opened from Home, not while Expo is in use) does not change its appearance when Dark Mode is toggled. It will only do so when I tap to go back into the app
- I'm not sure if Expo client is built with React Native because the behavior described in "2." does not always happen. But I've tried creating my own RN app with
react-native-appearance
and the colors do not change when suspended (as portrayed in the animation)
At the moment, there is a hacky way to partially achieve this, but I don't think anybody could stand to ship their app with it.
<View style={{
backgroundColor: isDarkModeOn ? 'black' : 'white', // remove this
}} />
Don't specify backgroundColor
at all and it will behave like a native app even when suspended and viewed from the app switcher, probably because it's using a native value by default… but:
- that only applies to
backgroundColor
- and only if it's a
<View/>
(or something equivalent) - and is limited to black and white
We still need to rely on JavaScript as long as one of the conditions above are not met.
I would like to believe that there's a solution out there that I'm not aware of. But so far none of the dark mode tutorials I find mention about this concern.