Copy the code from BaseController in this gist to BaseController in your project, then attach setMode to onInit() of your views, or the base view.
Last active
June 14, 2021 07:52
-
-
Save CruciformHawk7/c43374f947e0cc3a5afc577fc40a07d4 to your computer and use it in GitHub Desktop.
Change Theme automatically in OpenUI5/SAPUI5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setMode: function() { | |
const colorScheme = window.matchMedia("(prefers-color-scheme: dark)"); | |
this.determineColoringScheme(colorScheme); | |
colorScheme.addEventListener("change", scheme => this.determineColoringScheme(scheme)); | |
}, | |
determineColoringScheme: function(colorScheme) { | |
if (colorScheme.matches) | |
sap.ui.getCore().applyTheme("sap_fiori_3_dark"); | |
else | |
sap.ui.getCore().applyTheme("sap_fiori_3"); | |
} |
Copy the code from
BaseController
toBaseController
…Is it correct or there is a typo? From one controller to the same controller?
Whoops. I meant copy from BaseController in this gist to the BaseController in your module.
Thanks, I'll try it!
It works! But addListener
is deprecated.
I would replace it with addEventListener
:
colorScheme.addEventListener("scheme", (scheme) => this.determineColoringScheme(scheme));
It works! But
addListener
is deprecated.I would replace it with
addEventListener
:colorScheme.addEventListener("scheme", (scheme) => this.determineColoringScheme(scheme));
Thank you for that. I probably forgot to update it here.
Edit: I've updated the gist, thank you so much!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it correct or there is a typo? From one controller to the same controller?