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

feat: Allow disabling the icon background #310

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions doc/uno-resizetizer-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ Properties that can be used across all items

## UnoIcon

| Property Name | Description |
|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `Include` | Used to insert the path of the Background image. |
| `ForegroundFile` | Used to insert the path of the Foreground image |
| `ForegroundScale` | Used to rescale the Foreground image, in order to fit on the app icon, it's a percentage value so `0.33` will be translated as 33%. |
| `AndroidForegroundScale` | The same as ForegroundScale, but the value will be applied just for Android. |
| `WasmForegroundScale` | The same as ForegroundScale, but the value will be applied just for Wasm |
| `WindowsForegroundScale` | The same as ForegroundScale, but the value will be applied just for Windows |
| `IOSForegroundScale` | The same as ForegroundScale, but the value will be applied just for iOS |
| `SkiaForegroundScale` | The same as ForegroundScale, but the value will be applied just for Skia targets |
| Property Name | Description |
|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| `Include` | Used to insert the path of the Background image. |
| `ForegroundFile` | Used to insert the path of the Foreground image |
| `ForegroundScale` | Used to rescale the Foreground image, in order to fit on the app icon, it's a percentage value so `0.33` will be translated as 33%. |
| `UseBackgroundFile` | If set to `false`, only the foreground image will be used with a transparent background. Defaults to `true` on desktop, `false` elsewhere. |
| `AndroidForegroundScale` | The same as ForegroundScale, but the value will be applied just for Android. |
| `WasmForegroundScale` | The same as ForegroundScale, but the value will be applied just for Wasm |
| `WindowsForegroundScale` | The same as ForegroundScale, but the value will be applied just for Windows |
| `IOSForegroundScale` | The same as ForegroundScale, but the value will be applied just for iOS |
| `SkiaForegroundScale` | The same as ForegroundScale, but the value will be applied just for Skia targets |

> [!NOTE]
> The `<PLATFORM>ForegroundScale` (`AndroidForegroundScale`, `WasmForegroundScale`, etc) will override the global `ForegroundScale` value.
Expand Down
4 changes: 3 additions & 1 deletion doc/using-uno-resizetizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ The Uno Platform SDK exposes several properties that simplify the customization
* `UnoIconForegroundFile`: Sets the foreground image file for the icon.
* `UnoIconForegroundScale`: Adjusts the scaling of the icon's foreground.
* `UnoIconBackgroundColor`: Sets the background color of the icon.
* `UnoUseIconBackgroundFile`: Controls whether the background file is used (useful for platforms where icons can have transparent background, e.g. desktop).

For basic adjustments, such as changing the icon's foreground color or applying a common modification across platforms, you can use SDK properties:

Expand Down Expand Up @@ -362,6 +363,7 @@ Next, some adjustments are needed on `Android`, `Windows`, and `iOS`.
-----

## Platform-Specific Customization

The Uno Resizetizer SDK allows for detailed control over how assets are rendered on different platforms. This can be particularly useful for properties such as icon and splash screen backgrounds, which may need to vary between platforms due to design or visibility concerns.

### Customizing Background Colors Per Platform
Expand All @@ -382,7 +384,7 @@ For properties like BackgroundColor, which might need different values per platf
```
This setup demonstrates setting a default background color that is overridden on specific platforms. Adjust the conditions to match your project's target frameworks as defined in your project files or SDK documentation.

#### Applying Platform-Specific Scale
### Applying Platform-Specific Scale
Similarly, if you want to apply different scaling factors for the icon foreground across platforms, use the platform-specific properties:

```xml
Expand Down
13 changes: 13 additions & 0 deletions src/Resizetizer/src/ResizeImageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal class ResizeImageInfo

public bool IsAppIcon { get; set; }

public bool UseBackgroundFile { get; set; } = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test with a validation for this part?


public bool IsSplashScreen { get; set; }

public string? ForegroundFilename { get; set; }
Expand Down Expand Up @@ -138,6 +140,11 @@ public static List<ResizeImageInfo> Parse(IEnumerable<ITaskItem>? images)
info.ForegroundScale = fsc;
}

if (bool.TryParse(image.GetMetadata(nameof(UseBackgroundFile)), out var uib))
{
info.UseBackgroundFile = uib;
}

if (info.IsSplashScreen)
{
SetPlatformForegroundScale(image, "Scale", info);
Expand All @@ -154,6 +161,12 @@ public static List<ResizeImageInfo> Parse(IEnumerable<ITaskItem>? images)
}

info.ForegroundFilename = fgFileInfo.FullName;

// If we don't want to apply icon background, we set it to null.
if (!info.UseBackgroundFile)
{
info.Filename = null;
}
}

if (info.IsAppIcon)
Expand Down
Loading