Page MenuHomePhabricator

[Night mode] Set theme color and switch it when night/light modes are switched, like the gadget does
Open, MediumPublicFeature

Description

Feature summary (what you would like to be able to do and where):
On mobile (and certain browsers), i want the background color of the UI to theme itself to the dark/light mode

Example of forced dark skin, where the chrome areas of Safari are in

IMG_599C3C004433-1.jpeg (2×1 px, 397 KB)

Compare to the Gadget's dark mode:
IMG_668073C6B3FD-1.jpeg (2×1 px, 483 KB)

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
When i enable dark mode on my iphone, the address bar and topbar remain gray, instead of dark.

Benefits (why should this be implemented?):
This provides a more coherent visual style for the page.

  • See also **

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name/theme-color

This is already implemented in the gadget of english wikipedia
https://en.wikipedia.org/wiki/MediaWiki:Gadget-dark-mode-toggle.js#L-23
It even listens for a media change. If the OS switches from light to dark mode as you have the page open, it updates the value to match.
https://en.wikipedia.org/wiki/MediaWiki:Gadget-dark-mode-toggle.js#L-176

Event Timeline

TheDJ renamed this task from Set theme color and switch it when modes switch, like the gadget does to [Night mode] Set theme color and switch it when night/light modes are switched, like the gadget does.May 5 2024, 8:50 PM
TheDJ updated the task description. (Show Details)
Jdrewniak lowered the priority of this task from High to Medium.EditedMay 14 2024, 1:19 PM
Jdrewniak subscribed.

Sorry I mistakenly marked this as high priority. I thought this task related to switching the entire page theme from dark to light in certain situations (like if VisualEditor appears for example) but I see it's about adding the meta tag to the HTML based on the light/dark theme:

<meta name="theme-color" content="#4285f4" />

making the chrome of the mobile browser (URL bar, et.) change color.

I'm not sure how we'd accomplish this in a performant way for anonymous users considering the HTML is cached (we could do it after pageload like the gadget), but I can see it working for logged-in users and creating a more unified night-mode experience.

I'm not sure how we'd accomplish this in a performant way for anonymous users considering the HTML is cached (we could do it after pageload like the gadget), but I can see it working for logged-in users and creating a more unified night-mode experience.

You can really only do it with JS I think, because you also need to respond to the OS changing it in automatic mode while the page is already loaded.

Change #1032089 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/core@master] Support skins setting their own theme color

https://gerrit.wikimedia.org/r/1032089

Change #1032090 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/skins/MinervaNeue@master] Set Minerva color scheme

https://gerrit.wikimedia.org/r/1032090

MobileFrontend has some handling for theme that would need to be revised in preparation for this. Adding platform team in case they have any opinions about the necessary core change that will be required to unblock this: https://gerrit.wikimedia.org/r/1032089

Change #1032091 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/extensions/MobileFrontend@master] Upstream theme-color to core/skins

https://gerrit.wikimedia.org/r/1032091

Tagging Mediawiki-engineering on this ticket and related ones due to pending ownership discussion.
cc: @MNadrofsky @Bmueller

I personally think that specifying theme-color from skin.json as in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1032089 is not a good idea. It should be provided by a function of the skin, so that skins can provide it dynamically based on the page being rendered.

I can easily think of situations where page layout differs so that the color depends on the page you are rendering (a theme color per namespace for instance).

We can already see how this doesn't scale for light mode vs dark mode.. What if like the iOS/Android apps, you have 4 themes ? light/dark/sepia/black ?

I personally think that specifying theme-color from skin.json as in https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1032089 is not a good idea. It should be provided by a function of the skin, so that skins can provide it dynamically based on the page being rendered.

I can easily think of situations where page layout differs so that the color depends on the page you are rendering (a theme color per namespace for instance).

We can already see how this doesn't scale for light mode vs dark mode.. What if like the iOS/Android apps, you have 4 themes ? light/dark/sepia/black ?

I think these would be handled via JavaScript. My main thinking around the core patch I posted was that the dark theme and light theme can be done in a way which is friendly with our Varnish cache without the theme changing several seconds after the page has finished loading. How about generalizing this further: e.g. using a template or simply allowing the addition of an arbitrary amount of meta tags via skin options like so?

e.g.

[
      'meta => [
          ['theme-color', '#333' ],
          ['theme-color', '#fff', '(prefers-color-scheme: dark)' ]
      ]
]
Jdlrobson added a subscriber: ovasileva.

@ovasileva we need to talk to MediaWiki engineering before working on this one.

Change #1032090 abandoned by Jdlrobson:

[mediawiki/skins/MinervaNeue@master] Set Minerva color scheme

Reason:

Seems like this needs more discussion on the ticket / core patch before we can work on this.

https://gerrit.wikimedia.org/r/1032090

Change #1032091 abandoned by Jdlrobson:

[mediawiki/extensions/MobileFrontend@master] Upstream theme-color to core/skins

Reason:

Blocked on https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1032089 - will wait for that to play out before restoring.

https://gerrit.wikimedia.org/r/1032091