Is it possible to overwrite the value of UIUserInterfaceStyle at any given point?

307 views Asked by At

I'm working on a react-native app on which I want to detect how many people have dark mode and how many people have light mode but I want to keep light mode as UIUserInterfaceStyle.

So since I'm just detecting I tried a couple of solutions but the above problem statement is not being satisfied.

The project was created using CLI and not expo.

I tried using useColorScheme

import { StyleSheet, Text, Appearance } from 'react-native';
// ... other code and imports

<Text>Mode is: {Appearance.getColorScheme()}</Text>
//... other code

The above works as it'll give me light or dark as expected. But if I set UIUserInterfaceStyle to Light in Info.plist it always gives light and I'm unable to detect if user's phone is in dark mode or light.

I found that there is [overrideUserInterfaceStyle][1] which is provided for iOS by Apple so it's swift based.

Basically, I know the ways around which means to create two themes, detect which mode is on, and launch the light theme always. I'm looking for a different solution, is it's possible to override the value of UIUserInterfaceStyle from react-native ios? OR Is there a way I can change the Appearance of a specific screen? For example, if the user has a dark mode, I detect that in react-native and override the appearance from dark to light for that specific screen.

[1] https://developer.apple.com/documentation/uikit/uiviewcontroller/3238087-overrideuserinterfacestyle

0

There are 0 answers