Is this a good way to implement Dark Mode?

I have tried to use conditional formatting for implementing a dark mode.

I found a few downsides:

  • We cannot use Styles in conditions. We need to specify the dark mode colors for every single element.
  • The user sees the default light color for a second or so, before it changes to dark - every time a page is accessed or refreshed. This creates an annoying flickering effect.

Hence I’m thinking of doing the following instead. But because it’s quite an extensive change, I need opinions on whether this is a good idea or not, before I proceed. e.g. every element now needs to access User data type before it can render - any potential issues with that? Any feedback or comments are appreciated!

  • I create a new option set Color Mode with 2 options - Light and Dark.
  • Each option has attributes that contain the hex color codes for background, text, etc.
    e.g. Page background is set to “#FFFFFF” for Light Mode and “#000000” for Dark Mode.
  • Each User has a field called Preferred Color Mode that they can set - either Light or Dark.
  • Finally I’ll set each element’s color according to the attribute in the User’s Preferred Color Mode, e.g. Current User’s Preferred Color Mode’s Page background

image

This might help

2 Likes

The way how I implemented Dark mode is via database field with yes/no field on current user.

You can access style condidtions inside the Style tab:

image

And as you can see you can access Current User there which allows you to define inside the style itself how the style should look for either Dark or Light mode.

I find this quite optimal because you don’t have to fiddle with conditions on the page elements which could be insane on bigger apps.

Hope this helps!

Cheers!

4 Likes

@Guru oh this is pretty smart - didn’t know we could do this. Thanks so much!! Glad I asked before i went ahead :slight_smile:

1 Like

Yeah that’s good, hadn’t thought of doing it this way. There are a lot of limits on what you can define on the conditional within styles but for a simple yes/no for dark/light mode this works.

Thanks for sharing.

2 Likes

No problem, hopefully I’ve spared you some unnecessary development hours :smiley:

1 Like

Well the only scenario I’ve investigated was for the dark/light mode, but I’m quite sure you can squeeze even more stuff out of Current User :wink:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.