RadekVyM / SimpleToolkit

SimpleToolkit is a .NET MAUI library of helpers and simple, fully customizable controls, such as SimpleShell - custom Shell implementation that allows you to create unique navigation experiences.
MIT License
425 stars 41 forks source link

Make animation optional #51

Closed breyed closed 2 months ago

breyed commented 2 months ago

Feature request: Just as you can dismiss a popover without animation on iOS using dismiss(animated:completion:), it would be useful to hide the MAUI Popover without animation. (In my use case, I want to immediately navigate to another page.)

RadekVyM commented 2 months ago

Hi @breyed,

thanks for the feature proposal. It should be possible to implement. I will try to implement it in the future.

RadekVyM commented 2 months ago

Hi @breyed,

I have implemented optional animations in the latest release.

breyed commented 2 months ago

The update in version 5.1.0 doesn’t work. In a response to a Command from a view on the popover, my code essentially does this:

popover.IsAnimated = false;
popover.Hide();
page.Navigation.PushModalAsync(navigationPage)

The popover still animates before the modal push animation begins. Tested on iOS 17.5 and Android 14.

RadekVyM commented 2 months ago

Hi @breyed, I made a dumb mistake in the iOS handler. I published a fix.

breyed commented 2 months ago

In 5.1.1 IsAnimated = false works on iOS. However, on Android 14, it still animates.

RadekVyM commented 2 months ago

Hi,

on Android, it does not work only if you change the IsAnimated property while the popover is open. Popover is implemented using PopupWindow on Android. I do not know why, but changing AnimationStyle of PopupWindow while the window is open does not have any effect (the change is only reflected the next time it is opened). If you change the property before you open the popover, it works as expected:

https://github.com/user-attachments/assets/7ff79cf3-0ea0-413d-b5b5-64cfd225d569

breyed commented 2 months ago

Perhaps you need to call [update](https://developer.android.com/reference/android/widget/PopupWindow#update()) for the new animation style to take effect.

RadekVyM commented 2 months ago

Hi @breyed,

thank you for the tip about the update() method. I implemented it and published a new version. However, I could not make it working in a situation when the Hide() method is called right after IsAnimated is changed. You have to wait a bit for the new animation style to take effect, for example using Task.Delay(), although this is far from a perfect solution:

popover.IsAnimated = false;
await Task.Delay(10);
popover.Hide();
breyed commented 2 months ago

~Does Dispatcher.Dispatch work around the issue? If so, it’s cleaner than using Delay.~ I tried Dispatcher.Dispatch, but it had no effect.