-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[ShapeableImageView] contentPadding not working when set via Kotlin #2063
Comments
Likely related to #1871 |
Ouch, yep I can reproduce this. ShapeableImageView's For now you can work around it by only calling val imageView = findViewById<ShapeableImageView>(R.id.kotlin)
imageView.post { imageView.setContentPadding(px, px, px, px) } |
Thank you for that solution; it works in simple cases but doesn't work in cases where I need to set both |
I'm also facing same issue when i use content padding via code (kotlin/java), it adds padding around the background as well. Any update on this? I need to use content padding along with padding for stroke which actually cuts the edges of view. |
@rs-shivani-gupta Does the workaround posted above not work for you? I think I can fix this actually, gonna take me a bit to write all the test cases though. |
@drewhamilton that worked for me, hoping that this would not break something else. |
I think I'm running into this. I see your PR is still on hold @drewhamilton, any idea why? |
@J-Swift Sorry, I took a long hiatus and changed jobs. My PR needs tests and to address any other review comments which I don't remember the details of. Life is busy right now so I don't know when I'll get to it – if you want to take a stab at it I wouldn't mind. |
@drewhamilton no worries, I have no expectations on it. I dont have the bandwidth for it either honestly, I can mostly work around it for now. Appreciate you taking the time to put in the PR and document things here. |
Context: a270ebd Context: 1bbe79d Context: material-components/material-components-android#2063 Reviewing a GC dump of the device tests, I noticed a `System.Action` keeping the `ImageButton` alive: Microsoft.Maui.Controls.ImageButton System.Action Java.Lang.Thread.RunnableImplementor So next, I looked for `System.Action` and found the path on the `ReferencedTypes` tab: System.Action Microsoft.Maui.Platform.ImageButtonExtensions.[]c__DisplayClass4_0 Google.Android.Material.ImageView.ShapeableImageView Microsoft.Maui.Controls.ImageButton Which led me to the code: public static async void UpdatePadding(this ShapeableImageView platformButton, IImageButton imageButton) { platformButton.SetContentPadding(imageButton); platformButton.Post(() => { platformButton.SetContentPadding(imageButton); }); platformButton.SetContentPadding(imageButton); } ?!? Why is this code calling `SetContentPadding` three times? Reviewing the commit history: * a270ebd * 1bbe79d * material-components/material-components-android#2063 I could comment out the code and the leak is solved, but I found I could also change the code to use `await Task.Yield()` for the same result.
* [ios] fix memory leak in `ImageButton` Context: #18365 Adding a parameter to the test: [Theory("Handler Does Not Leak")] [InlineData(typeof(ImageButton))] public async Task HandlerDoesNotLeak(Type type) Shows a memory leak in `ImageButton`, caused by the cycle * `ImageButtonHandler` -> * `UIButton` events like `TouchUpInside` -> * `ImageButtonHandler` I could solve this problem by creating a `ImageButtonProxy` class -- the same pattern I've used in other PRs to avoid cycles. This makes an intermediate type to handle the events and breaks the cycle. Still thinking if the analyzer could have caught this, issue filed at: jonathanpeppers/memory-analyzers#12 * [android] fix memory leak in `ImageButton` Context: a270ebd Context: 1bbe79d Context: material-components/material-components-android#2063 Reviewing a GC dump of the device tests, I noticed a `System.Action` keeping the `ImageButton` alive: Microsoft.Maui.Controls.ImageButton System.Action Java.Lang.Thread.RunnableImplementor So next, I looked for `System.Action` and found the path on the `ReferencedTypes` tab: System.Action Microsoft.Maui.Platform.ImageButtonExtensions.[]c__DisplayClass4_0 Google.Android.Material.ImageView.ShapeableImageView Microsoft.Maui.Controls.ImageButton Which led me to the code: public static async void UpdatePadding(this ShapeableImageView platformButton, IImageButton imageButton) { platformButton.SetContentPadding(imageButton); platformButton.Post(() => { platformButton.SetContentPadding(imageButton); }); platformButton.SetContentPadding(imageButton); } ?!? Why is this code calling `SetContentPadding` three times? Reviewing the commit history: * a270ebd * 1bbe79d * material-components/material-components-android#2063 I could comment out the code and the leak is solved, but I found I could also change the code to use `await Task.Yield()` for the same result.
Description:
When setting
contentPadding
on aShapeableImageView
in code (Kotlin or Java), it does not work as expected. Settingapp:contentPadding
viaXML
works fine.Expected behavior:
Both elements should match and be like the top element.
Source code:
MainActivity.kt
activity_main.xml
styles.xml
Android API version: 30
Material Library version: 1.3.0
Device: Pixel 3 and others
The text was updated successfully, but these errors were encountered: