Add MonochromeFile support for Android adaptive icons#34569
Add MonochromeFile support for Android adaptive icons#34569jfversluis wants to merge 2 commits intonet11.0from
Conversation
Android 13+ supports themed icons with a separate monochrome layer.
Previously, MAUI always hardcoded the monochrome layer to reference
the foreground drawable, which causes incorrect rendering when the
foreground contains multiple colors.
Add MonochromeFile metadata to MauiIcon so developers can provide a
dedicated monochrome image for themed icons:
<MauiIcon Include="icon_bg.svg"
ForegroundFile="icon_fg.svg"
MonochromeFile="icon_mono.svg" />
When MonochromeFile is provided:
- A separate _monochrome.png is generated at each density
- The adaptive-icon XML references @mipmap/{name}_monochrome
When MonochromeFile is omitted:
- Backwards compatible: foreground is used as monochrome (existing behavior)
Also removed the early-return cache in ProcessAdaptiveIcon that
prevented the XML from being regenerated when MonochromeFile changed.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 34569Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 34569" |
There was a problem hiding this comment.
Pull request overview
Adds opt-in support for Android adaptive icon monochrome layers in the Resizetizer pipeline, allowing MAUI apps to provide a dedicated monochrome source image for Android 13+ themed icons while preserving existing behavior when not provided.
Changes:
- Parse new
MonochromeFilemetadata intoResizeImageInfoand expose vector detection for it. - Generate
{name}_monochrome.pngat all app icon part densities whenMonochromeFileis provided, and emit adaptive icon XML referencing that layer. - Add unit tests validating monochrome generation, backward-compatible fallback behavior, and expected output sizing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/SingleProject/Resizetizer/src/ResizeImageInfo.cs | Adds MonochromeFilename/MonochromeIsVector and parses MonochromeFile item metadata. |
| src/SingleProject/Resizetizer/src/AndroidAdaptiveIconGenerator.cs | Generates monochrome app icon part PNGs and updates adaptive icon XML to reference either monochrome or foreground. |
| src/SingleProject/Resizetizer/test/UnitTests/ResizetizeImagesTests.cs | Adds tests for monochrome layer generation, fallback behavior, and size correctness. |
You can also share your feedback on Copilot code review. Take the survey.
src/SingleProject/Resizetizer/src/AndroidAdaptiveIconGenerator.cs
Outdated
Show resolved
Hide resolved
|
🚨 API change(s) detected @davidortinau FYI |
Avoid unnecessary timestamp updates on incremental builds by comparing file content before writing. This preserves proper incremental build behavior while still picking up MonochromeFile changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jfversluis
left a comment
There was a problem hiding this comment.
Good catch — replaced the unconditional File.WriteAllText with a WriteFileIfChanged helper that reads existing content first and only writes when it differs. This preserves incremental build timestamps while still picking up changes when MonochromeFile is added/removed. See c0fe91e.
Description
Fixes #22543
Android 13+ supports themed icons with three layers: background, foreground, and monochrome. MAUI currently hardcodes the monochrome layer to always reference the foreground drawable. This causes incorrect rendering when the foreground contains multiple colors — themed icons display the full-color foreground instead of a proper monochrome silhouette.
This PR adds a new
MonochromeFilemetadata property forMauiIcon, allowing developers to provide a dedicated monochrome image:Behavior
MonochromeFilespecified?@mipmap/{name}_monochrome@mipmap/{name}_foregroundChanges
ResizeImageInfo.cs— AddedMonochromeFilenameandMonochromeIsVectorproperties; parseMonochromeFilemetadata fromITaskItemAndroidAdaptiveIconGenerator.cs— AddedProcessMonochrome()method that generates monochrome PNGs at each density; two XML templates (with/without monochrome); removed stale XML caching that prevented incremental updatesResizetizeImagesTests.cs— 3 new tests:AppIconWithMonochromeFileGeneratesMonochromeLayer— verifies monochrome PNGs and XML referenceAppIconWithoutMonochromeFileFallsBackToForeground— verifies backwards compatibilityAppIconMonochromeLayerHasCorrectSize— verifies density-correct sizingTesting
SkiaSharpAppIconToolsTestsare unrelated