Skeptick / libres

Resources generation in Kotlin Multiplatform
Apache License 2.0
207 stars 11 forks source link

Night/Dark mode support for Android and iOS #25

Open brudaswen opened 1 year ago

brudaswen commented 1 year ago

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.

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"
  }
}
Skeptick commented 1 year ago

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)
kihaki commented 10 months ago

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.

VictorKochetkov commented 8 months ago

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

brudaswen commented 8 months ago

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

gleb-skobinsky commented 8 months ago

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...