Skip to content

Commit

Permalink
Merge pull request #88 from eichbaum/master
Browse files Browse the repository at this point in the history
only animate with system animations enabled
  • Loading branch information
LuckyDucko authored Nov 30, 2023
2 parents 6e92e62 + 6ecf5c1 commit 6ab0275
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
16 changes: 16 additions & 0 deletions Mopups/Mopups.Maui/Animations/AnimationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
namespace Mopups.Animations;

public static class AnimationHelper
{
public static bool SystemAnimationsEnabled
{
get
{
#if __ANDROID__
return Android.Animation.ValueAnimator.AreAnimatorsEnabled();
#endif
return true;
}
}
}
2 changes: 1 addition & 1 deletion Mopups/Mopups.Maui/Pages/PopupPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class PopupPage : ContentPage

public bool IsAnimationEnabled
{
get => (bool)GetValue(IsAnimationEnabledProperty);
get => (bool)GetValue(IsAnimationEnabledProperty) && AnimationHelper.SystemAnimationsEnabled;
set => SetValue(IsAnimationEnabledProperty, value);
}

Expand Down
14 changes: 11 additions & 3 deletions Mopups/Mopups.Maui/Services/PopupNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ private void OnInitialized(object? sender, EventArgs e)

public Task PushAsync(PopupPage page, bool animate = true)
{
animate = animate && Animations.AnimationHelper.SystemAnimationsEnabled;

Pushing?.Invoke(this, new PopupNavigationEventArgs(page, animate));
_popupStack.Add(page);

Expand All @@ -84,22 +86,28 @@ async Task PushPage()

public async Task PopAllAsync(bool animate = true)
{
while (MopupService.Instance.PopupStack.Count > 0)
animate = animate && Animations.AnimationHelper.SystemAnimationsEnabled;

while (MopupService.Instance.PopupStack.Count > 0)
{
await PopAsync(animate);
}
}

public Task PopAsync(bool animate = true)
{
return _popupStack.Count <= 0
animate = animate && Animations.AnimationHelper.SystemAnimationsEnabled;

return _popupStack.Count <= 0
? throw new InvalidOperationException("PopupStack is empty")
: RemovePageAsync(PopupStack[PopupStack.Count - 1], animate);
}

public Task RemovePageAsync(PopupPage page, bool animate = true)
{
if (page == null)
animate = animate && Animations.AnimationHelper.SystemAnimationsEnabled;

if (page == null)
throw new InvalidOperationException("Page can not be null");

if (!_popupStack.Contains(page))
Expand Down

0 comments on commit 6ab0275

Please sign in to comment.