libres icon indicating copy to clipboard operation
libres copied to clipboard

Night/Dark mode support for Android and iOS

Open brudaswen opened this issue 2 years ago • 5 comments

Night/Dark Mode Images

Night/Dark Mode images are supported for Android and iOS by adding the (night) modifier. The filename and type of the image must match the corresponding day/light version without the (night) modifier.

  • For Android this creates night images in drawable-night-nodpi.
  • For iOS this creates a "appearances" : [ { "appearance" : "luminosity", "value" : "dark" } ] entry in the imageset.

Closes #24

Output Example

Android

image

iOS

image
{
  "images" : [
    {
      "filename" : "icon_check.svg",
      "idiom" : "universal"
    },
    {
      "filename" : "icon_check_night.svg",
      "idiom" : "universal",
      "appearances" : [
        {
          "value" : "dark",
          "appearance" : "luminosity"
        }
      ]
    }
  ],
  "info" : {
    "author" : "xcode",
    "version" : 1
  },
  "properties" : {
    "preserves-vector-representation" : true,
    "template-rendering-intent" : "template"
  }
}

brudaswen avatar Jul 15 '23 08:07 brudaswen

Hello. When I thought about implementing such feature I had a slightly different idea in mind.

When using Compose, app's theme is usually not set to dark. Just use CompositionLocal with required palette. So when using standard android tools, same picture will be taken for any color scheme.

I think it would be more practical to solve such a moment at level of generated code: put all images in drawable-nodpi (or another suitable directory) with different names, for example my_image_light.xml and my_image_night.xml, and in generated code make function with argument, like:

Res.image.my_image(isDark = true)

Skeptick avatar Aug 10 '23 22:08 Skeptick

I would like to think that adding the images into the resource directories as originally proposed by @brudaswen is the simpler option here, since it would make use of Androids in built darkmode support and would also work for XML based layouts?

When doing that it would be trivial to add your solution too and reference a different image in a theme. Only like proposed by @brudaswen both solutions would work without any additional overhead too.

Also the proposed solution would work seamlessly for iOS, which seems like a nice solution tbh.

kihaki avatar Nov 30 '23 09:11 kihaki

Any news about this MR? 😄 We also interested in supporting of dark/light theme for shared images

VictorKochetkov avatar Jan 29 '24 10:01 VictorKochetkov

Any news about this MR? 😄 We also interested in supporting of dark/light theme for shared images

We switched to our own version https://github.com/brudaswen/libres/releases/tag/1.2.2-night until there is another solution. The version is available via jitpack https://jitpack.io/#brudaswen/libres/1.2.2-night

brudaswen avatar Jan 29 '24 19:01 brudaswen

Any news about this MR? 😄 We also interested in supporting of dark/light theme for shared images

We switched to our own version https://github.com/brudaswen/libres/releases/tag/1.2.2-night until there is another solution. The version is available via jitpack https://jitpack.io/#brudaswen/libres/1.2.2-night

Thank you for publishing your fork as a library. Our team is also in need of this functionality. I wonder why is this PR not approved by library maintainers yet...

gleb-skobinsky avatar Feb 14 '24 19:02 gleb-skobinsky