Unable to use only Light or Dark theme on Nativescript

959 views Asked by At

I'm developing a Nativescript (version 6.3.3) app with Angular 8.2 and @nativescript/theme 2.2.1 with scss themes. I'm trying to use only Dark (or only Light) theme regardless of system mode (Dark/Light) but nothing seems to work. I followed this guide https://github.com/NativeScript/theme and I used custom color variables setting the dark ones equal to the light ones but it doesnt' work. Can someone support me?

3

There are 3 answers

0
Tyler Blake On

If you want to force Light or Dark mode only on iOS you can add the following to your Info.plist file.

For light mode:

    <key>UIUserInterfaceStyle</key>    
    <string>Light</string>    

For dark mode:

    <key>UIUserInterfaceStyle</key>    
    <string>Dark</string>    

Hope this helps!

0
Bundyo On

Also {N} Theme 2.3.x have some important fixes to force the mode. Try with 2.3.2.

1
Justin Nadar On

For Android, First add this code in main.ts or main.js

import Theme from "@nativescript/theme";
Theme.setMode(Theme.Light);

Then change this value in styles.xml file located in folder values-v29 from true to false

<item name="android:forceDarkAllowed">false</item>