-
Notifications
You must be signed in to change notification settings - Fork 742
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
Implement Theme Asset Qualifier #2197
Comments
Thanks for the report! |
@jeromelaban You're welcome, could you assign it to me?, since I am planning om picking this up as soon as possible, since I'm working on dark mode support for my app. |
I'm having trouble on finding out where to start on this. I found https://github.com/unoplatform/uno/blob/f3d6bb85913bbf9ecf573861e04029531d9623fb/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs but I cannot get the logs to show up. @ghuntley could you help me get started on this?
|
@pdecostervgls The linked source code is just a build task, which makes sure the platform-specific assets get copied to the respective platforms during build. To achieve the First you need to find out how (and if even) the The second part of the task will be to implement correct asset resolution on the target platforms. This might be quite easy on Android, as it could be handled automatically for you by the OS, but on iOS and WASM it might require additional work. |
@MartinZikmund I have verified that assets with the theme qualifier do already get copied to the build output folder, so I guess only the asset resolution part is left. I could look at how the scale assets get resolved and work from there? |
That sounds good! Let me know when you encounter something :-) |
I cannot find it. I'm starting to suspect that the asset resolving is actually implemented in Xamarin instead. |
Assets resolving for iOS and Android is done by the platform, given the proper naming convention. The assets retargeting is done on Android by the AndroidResourcesConverter , called from the RetargetAssets task: uno/src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs Lines 51 to 62 in 1ec834b
Adding dark theme support would probably be similar to the support for multiple DPIs. |
@jeromelaban I though that on iOS you had to create an assets catalog with the corresponding contents.json file to declare the DPIs. Other than retargeting the assets I cannot find anything creating a contents.json manifest for iOS. |
@pdecostervgls that's used for assets catalogs, not for bundle resources. But that may work differently for dark theme, there probably documentation on that. |
@jeromelaban As far is I can find in the documentation, you cannot signify bundle resources for dark/light mode without wrapping them in a asset catalog. So I think we have to generate Image Sets for each asset. We could still use the Retargeting entrypoint for this, just some extra work. |
For iOS, that would make sense. Have you looked it up for Android as well ? |
According to https://medium.com/androiddevelopers/appcompat-v23-2-daynight-d10f90c83e94 it supports the (renamed) asset qualifer, I can use the retargetassets for that too.
|
Come to think of it, I dont know for sure that the Image resolver will actually reference the xcassets entries that I plan on generating. Since the actual files do get retargetted as expected, wouldn't it be wiser to just override the Image Source resolver to try to match the image with the most fitting qualifiers at runtime? @jeromelaban @MartinZikmund |
@pdecostervgls for iOS, it's possible to generate the proper files and add them as ItemGroups so that the iOS tooling picks those up. For the other platforms, and Wasm specifically, we'll have to handle that at runtime in all cases. |
@MartinZikmund I unassigned myself because I lack the experience with VS ResourceGeneration to complete this. Would you like to pick it up? I got some work done (UI tests and set-up) at this branch |
Is this closed because it is implemented? If so, i'd like to see the code, for education purposes :) |
It's not, it was closed incorrectly. Sorry about that :) |
Ah, I just hit this with WASM trying to use an asset like <Image Width="150"
Height="150"
Source="ms-appx:///Assets/Square150x150Logo.png" /> Saw there's a workaround that Labs did using ThemeDictionaries, see here: https://github.com/CommunityToolkit/Labs-Windows/blob/3669d4c52eafb2bcb9b1d782d85c1a49111e175f/common/CommunityToolkit.Labs.Shared/Pages/GettingStartedPage.xaml
|
That's correct. At this time, Wasm only supports assets scaling, and a theme resources workaround is the best way. |
@jeromelaban @francoistanguay from a compatibility point of view, it would be good to get this onto the backlog. Having theme qualifiers would save the need for workarounds to handle theme based images. |
What would you like to be added:
The theme qualifier for assets.
Why is this needed:
So images can be different depending on the theme.
For which Platform:
Anything else we need to know?
As outlined in: https://docs.microsoft.com/en-us/windows/uwp/app-resources/images-tailored-for-scale-theme-contrast
The text was updated successfully, but these errors were encountered: