Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Night/Dark mode support for Android and iOS #25

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

brudaswen
Copy link

@brudaswen brudaswen commented Jul 15, 2023

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 brudaswen force-pushed the feature/night-support branch 3 times, most recently from 07f8012 to 23aa788 Compare July 15, 2023 11:09
@Skeptick
Copy link
Owner

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
Copy link

kihaki commented Nov 30, 2023

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.

Sven Obser added 2 commits December 12, 2023 17:44
# Conflicts:
#	gradle-plugin/src/main/java/io/github/skeptick/libres/plugin/LibresImagesGenerationTask.kt
@VictorKochetkov
Copy link

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

@brudaswen
Copy link
Author

brudaswen commented Jan 29, 2024

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Night/Dark mode support for Android and iOS
5 participants