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

Allow setting a padding on android icons #417

Closed

Conversation

muuvmuuv
Copy link
Contributor

@muuvmuuv muuvmuuv commented Nov 9, 2022

Adds an option --android-resize, that allows scaling the source image for modern icons (API>24).

Closes #118

@muuvmuuv
Copy link
Contributor Author

muuvmuuv commented Nov 9, 2022

Played a little bit around and this seems not really possible with the current options. The closest I came was to avoid applying the scale to the legacy items (which require a padding by default).

@muuvmuuv
Copy link
Contributor Author

muuvmuuv commented Nov 9, 2022

Images of scaling 30 and 80:

Bildschirm­foto 2022-11-09 um 14 52 28

Bildschirm­foto 2022-11-09 um 14 52 17

The two on the right are the legacy ones which are generated from "icon-only" or "android/icon". These cannot be scaled atm because them would require to have foreground and background separated which is currently not implemented that way because all assets are looped and therefore the "icon-only" overrides the previous comb of fore- and background.

@mlynch
Copy link
Contributor

mlynch commented Nov 9, 2022

I think the only one that really needs any padding possibly is the round and legacy launcher icons. Let me know when you want me to take another look. We can figure out what option we want to call this later but I agree with the functionality

@muuvmuuv
Copy link
Contributor Author

muuvmuuv commented Nov 9, 2022

Yes. From what I saw in Android Studio and Google is that by default it creates a padding around the legacy icons (when you right-click and generate an image asset resource). So, I wouldn't make this an option but apply it by default (as before).

Having a resize method to scale the foreground would make sense in case of Android. From two of my projects, I had to scale to 65% of what looked perfectly on iOS. IDK why Android does that zooming, and it is just relevant for API above 29.

@muuvmuuv
Copy link
Contributor Author

Another test with the latest main Branch merged into this.

Source assets: assets.zip

Command: capacitor-assets generate --android-resize=64

Result:

Android With res Without
till 7 Android 7 Android 7
8 - 13 Android 11 Bildschirm­foto 2022-11-10 um 13 43 07

I think --android-resize fit's pretty well, even if it is just used in _generateAdaptiveIconForeground, and it looks exactly what #118 wants. But I think I forgot something. Lets see if someone from the issue can test this by itself.

@noahbrenner
Copy link
Contributor

This might be addressed by #424, if folks think that's a good approach to the Android scaling issue.

@mlynch
Copy link
Contributor

mlynch commented Nov 11, 2022

Just gave it a test and it appears to be working for me

image

Any idea whether this padding needs to be adjusted to account for the inset for adaptive icons done in #424?

Also I think --androidIconScale would be a better name since this is a percentage scale not specific pixel value

@noahbrenner
Copy link
Contributor

From the two links below, I'm wondering if the <background> should actually not have the inset I added in #424, so that it allows for the intended bleed for the various ways the icon can be displayed. At the same time, the info at these links make me more confident that the inset is the correct approach for the foreground.

https://developer.android.com/develop/ui/views/launch/icon_design_adaptive
https://developer.android.com/studio/write/image-asset-studio

@co-dax
Copy link

co-dax commented Dec 4, 2022

When will this change will be released?

@co-dax
Copy link

co-dax commented Dec 4, 2022

@mlynch, @muuvmuuv I have tested this and it works fine.
I would say this option pretty much urgent as otherwise as a workaround we would need to manual (or via some code) scale down foreground icon (assets/icon-foreground.png) by around 67% and it would work fine even without this change.
@muuvmuuv As for why Android is "zooming" the icon...it is not actually zooming the icon it is just taking advantage of the non safe area that is allowed to be trimmed/shaped by OEMs (if I am not missing something). Here it is the related link https://developer.android.com/develop/ui/views/launch/icon_design_adaptive

@noahbrenner
Copy link
Contributor

@co-dax Does the most recent version work for you, after #424 was merged (v2.0.1 or later)?

@co-dax
Copy link

co-dax commented Dec 5, 2022

@muuvmuuv, @mlynch version 2.0.4 (latest) does not work for me while the change on your branch does work.

I can see that this branch has been merged but only one file seems to be merged https://github.com/ionic-team/capacitor-assets/pull/424/files. Also when we navigate to your branch there is an additional usage description:

--android-resize - resize the non-legacy android icons based on a percentage.

...but when we navigate to the latest verion branch there is so such usage description which seems to confirm that the branch has only been partially merged.

@muuvmuuv
Copy link
Contributor Author

muuvmuuv commented Dec 5, 2022

@co-dax because my branch is not the master in here and still a draft we are discussing. #424 was a good workaround without additional needs of options. But I agree that this workaround also scales the background and my solution just adds a "padding" to the foreground.

@co-dax
Copy link

co-dax commented Dec 5, 2022

@muuvmuuv thanks, I actually have confused the two branches :-).
Your branch seems to be working fine. I will try using it in production and will keep you informed.

Thanks everyone.

@muuvmuuv muuvmuuv closed this May 14, 2024
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.

Scaling option for Android launcher icons
4 participants