-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Drawing of Borders lags behind other elements on iOS creating bizarre overlaps and glitches (okay in Windows/Android) #18204
Comments
Verified this on Visual Studio Enterprise 17.8.0 Preview 4.0(8.0.0-rc.2.9373). Repro on iOS 16.4, not repro on Windows 11 and Android 13.0-API33 with below Project: |
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
I suspect this is due to iOS animation that needs to be disabled on changing requested View size: https://stackoverflow.com/questions/10975449/changing-uiviews-transformation-rotation-scale-without-animation |
It took me a lot of time to find a workaround, but here it is. I hope this also helps fixing the issue. handlers.AddHandler<Border, NotAnimatedBorderHandler>(); The following workaround removes sizing animations but keeps other kind of animations which are good (i.e. background). using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using ContentView = Microsoft.Maui.Platform.ContentView;
namespace YourNamespace;
public class NotAnimatedBorderHandler : BorderHandler
{
private class BorderContentView : ContentView
{
public override void LayoutSubviews()
{
// This is the only workaround I found to avoid the animation when the border size is updated.
// https://github.com/dotnet/maui/issues/15363
// https://github.com/dotnet/maui/issues/18204
if (Layer.Sublayers?.FirstOrDefault(layer => layer is MauiCALayer) is { AnimationKeys: not null } caLayer)
{
caLayer.RemoveAnimation("bounds");
caLayer.RemoveAnimation("position");
}
base.LayoutSubviews();
}
}
protected override ContentView CreatePlatformView()
{
_ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a {nameof(ContentView)}");
_ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} cannot be null");
return new BorderContentView
{
CrossPlatformLayout = VirtualView
};
}
} Please note that setting CC @durandt |
Related #15363 (I see now it was closed during Fall, but from my latest tests on net8 the animation still existed) |
@durandt I am on .NET MAUI 8.0.3 and I can confirm what they did to prevent this issue is NOT effective, my workaround appears the only way to get around it. |
@albyrock87 Now with Maui 8.0.6/8.0.7 removing a few blocking bugs I have finally had time to upgrade and test my app. As you say, the Border animations seem even worse but your work-around seems to work well for me too! Thank you. |
Thank you very much @albyrock87!!! I finally worked up the courage to test your fix and it did work as you suggested. It was my first time adding a custom Handler. I have one question as I am very curious about how this works in terms of the custom Handler. When you add the custom Handler in MauiProgram.cs, does this automatically replace the standard Border Handler inside Maui? Or is it a second Handler now attached to Border? Ie. Would each Border with this method now have two Handlers? One standard Obviously your Thanks for any clarification. This is a nice relatively easy technique to customize Handlers if it doesn't just add a duplicate Handler which would be less ideal. (All commands may run twice if two handlers per Border now, if that is even possible?) Thanks for any clarification. For anyone who has never done this before, this is how I used it (more specific instructions for amateurs like me who have to figure it out 😊). 1) MauiProgram.csAdd to default builder string so it reads:
2) NotAnimatedBorderHandler.csCreate a file by this name and enter in its body within the namespace:
|
@jonmdev I can confirm it replaces the default handler! :) And btw, you can place iOS specific handler in |
I've found a related issue. |
I tried to use the mentioned workaround with handler, but it doesn't work (v. 8.0.20) |
When i was working with .NET Maui 6.0 this workaround fixed the issue, but now the workaround dont work anymore. We are in 8.0.21 version. |
@matheusouz have you tried the one above? |
Yes i tried too but no lucky. |
The mentioned workaround works for me (8.0.21) but corner radius is still animated when border size changes. |
Border within a CollectionView appears to have a default BackgroundColor animation. This can be observed at the bottom of the CollectionView, where views are recycled with different colors. |
Same here, corner radius is still animated when using the workaround mentioned above. I can reproduce the animation if a Border that has CornerRadius set, is hidden and then gets visible with |
I've spent a lot of time trying to fix that thing. In your case you can just put everything into Grid and highlight the BoxView behind. |
Also having the same issue. My work around for now instead of relying border.StrokeShape = new RoundRectangle {CornerRadius = cornerRadius} I am using border.Clip = new RoundRectangleGeometry(new CornerRadius(cornerRadius), new Rect(0, 0, width, height)); the downside is I need to know the height and width of the border first but this can be done by just relying on creating custom view for it then override |
Alternative Solutions:I looked into this a bit more. The best reference I can find is this one: https://stackoverflow.com/questions/5833488/how-to-disable-calayer-implicit-animations There it is explained there are three ways to stop animations in iOS:
Definitely the correct solution for our main problem of the Borders resizing wildly (like in my OP bug report) is the RemoveAllAnimations. Or more specifically removing certain animations like @albyrock87 posted above. Comprehensive Solution?Out of curiosity I tried to apply all three and this is what I get for a new NotAnimatedBorderHandler:
ProblemThis works just as fine as the original posted above by @albyrock87 for the main problem. The problem with this code in the So Or maybe running Remaining IssueThe only remaining issue I see is that Borders with corners in iOS now have what looks like a single frame lag before their corners are drawn correctly. I don't believe this is an Animation, as it happens too quickly. Even on my very slow running Debug builds to iPhone I only see the glitch for a moment, so I think this is just a drawing function order error of not refreshing corners correctly until a frame later each time something is resized or shown/hidden. What do you see? @albilaga do you agree it is just a frame lag on the correct drawing of the corner border you are seeing when you use the corner radius? @Phenek out of curiosity does this approach in general (RemoveAllAnimations & setting each Action to the new NSDictionary) fix your background issue also? |
@jonmdev I am not sure if that is just lag. Basically what we have issue setting view which contains |
Okay you are seeing something different than me. You are still getting some animations of the Border sizes from what it sounds like. I am not anymore in any real world circumstance. I just see the corner radius of the rounded Border for a fractional second is shaped wrong (too square or round for a single frame) on each resize or hide/display. Which I think is just a drawing lag that needs to be fixed separately. Could you make a demo project to try to repro it? You could set up a basic Border with rounded corners and run a timer. If you take a default Maui project, then just edit App.xaml.cs to something like this: https://github.com/jonmdev/Border-iOS-Mask-Bug/blob/main/Border%20iOS%20Mask%20Bug/App.xaml.cs And add a timer to modulate the Border to that code after the border is set up with reasonable corner radius like 20 or so:
That should resize it and hide/show it on periodic basis to repro the issue if it can be still reproduced. |
@jonmdev found some time to reproduce the issue. This is the issue that I have. Looks like this is only happen when attaching |
I copied and pasted your page code into MainPage.xaml of a new Maui project and added my newer version of the NotAnimatedBorderHandler just posted above here: #18204 (comment) I see no further animations like your video. You can download my project here to see and confirm: |
Yes. Now you are seeing the same behavior as me. What I think we are seeing is a drawing error. As you can see, they are momentarily square on the corners, then a frame later they are drawn correctly with the rounded corners. I believe this is now likely not an animation issue but that they are being drawn wrong the first frame which is likely a separate bug. |
@albilaga I have posted the new "1 frame lag on redraw" bug report here: I used your test project and another one I made combined into one to show the issue, as your test project and gif best showed the square border effect which I am also seeing my real projects but had trouble figuring out how to reproduce consistently. My project in there shows there is a redraw lag also on the background color. Likely this is all the same bug and the order of operations must be changed on Border redraw to get them to redraw immediately when needed rather than after 1 frame to fix both. If anyone has any understanding of the Border and can think of any way to fix it that would be great also. I looked at BorderHandler and Border code and I can't see how it really works to understand a fix. One problem down, one more to go. Also just for reference the simplest NotAnimatedBorderHandler.cs code I have tested and works is:
|
We agree that this is an important issue. As our roadmap indicates, for the near future, we are focused on:
I am marking this as a p/2 issue because it does not meet our focus areas right now, but we are constantly revisiting the backlog for important issues to address as time allows. Thank you for your patience and understanding! |
…initial render performance
…initial render performance
…initial render performance
…initial render performance
…initial render performance
…initial render performance
…initial render performance
…initial render performance
Description
Currently, whenever a Border is resized in iOS it lags behind other elements by a large margin creating strange visual overlaps and effects.
This is likely the same overlap phenomenon seen here, which indicates the overlap/lag phenomenon is due to Borders, not Editor: #17757
That thread is more relevant therefore for the other strange Editor bugs like the textfield scrolling itself off the screen, unless perhaps these are all related and caused by the same thing.
DEMO PROJECT
This is the same project used to demonstrate the Android Shadow bug here: #18202
It draws 3 purple borders on screen and then oscillates their height continuously.
Correct animation should look like this:
Nothing should overlap at any time. However, in iOS we get the following bizarre overlaps as the animated Borders lag behind everything else and desynchronize in how they are drawn:
Steps to Reproduce
Link to public reproduction project repository
https://github.com/jonmdev/Resize-Lag-Bug
Version with bug
8.0.0-rc.2.9373
Is this a regression from previous behavior?
No, this is something new
Affected platforms
iOS
The text was updated successfully, but these errors were encountered: