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

Wait for animation to complete #4

Merged
merged 2 commits into from
Jun 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,28 @@ AView GetCurrentRootView()
throw new InvalidOperationException("Current Root View cannot be null");
}

Task PushModalPlatformAsync(Page modal, bool animated)
async Task PushModalPlatformAsync(Page modal, bool animated)
{
var viewToHide = GetCurrentRootView();

RemoveFocusability(viewToHide);

_platformModalPages.Add(modal);

PresentModal(modal, animated);
await PresentModal(modal, animated);

// The state of things might have changed after the modal view was pushed
if (IsModalReady)
{
GetCurrentRootView()
.SendAccessibilityEvent(global::Android.Views.Accessibility.EventTypes.ViewFocused);
}

return Task.CompletedTask;
}

void PresentModal(Page modal, bool animated)
async Task PresentModal(Page modal, bool animated)
{
TaskCompletionSource<bool> animationCompletionSource = new();

var parentView = GetModalParentView();

var dialogFragment = new ModalFragment(WindowMauiContext, modal)
Expand All @@ -141,11 +141,27 @@ void PresentModal(Page modal, bool animated)
};

var fragmentManager = WindowMauiContext.GetFragmentManager();

modals.Add(modal, dialogFragment);
dialogFragment.Show(fragmentManager, null);

modals.Add(modal, dialogFragment);
NavAnimationInProgress = false;
if (animated)
{
NavAnimationInProgress = true;
dialogFragment!.AnimationEnded += OnAnimationEnded;

await animationCompletionSource.Task;
}
else
{
NavAnimationInProgress = false;
}

void OnAnimationEnded(object? sender, EventArgs e)
{
dialogFragment!.AnimationEnded -= OnAnimationEnded;
NavAnimationInProgress = false;
animationCompletionSource.SetResult(true);
}
}

internal static void RestoreFocusability(AView platformView)
Expand Down Expand Up @@ -178,6 +194,8 @@ internal class ModalFragment : DialogFragment
static DialogBackButoonListener _backButtonListener = default!;
NavigationRootManager? _navigationRootManager;
static readonly ColorDrawable TransparentColorDrawable = new(AColor.Transparent);

public event EventHandler? AnimationEnded;

public NavigationRootManager? NavigationRootManager
{
Expand Down Expand Up @@ -244,21 +262,18 @@ public override void OnStart()
int height = ViewGroup.LayoutParams.MatchParent;
dialog.Window.SetLayout(width, height);


if (IsAnimated)
{
var animation = AnimationUtils.LoadAnimation(_mauiWindowContext.Context, Resource.Animation.nav_modal_default_enter_anim);
View.StartAnimation(animation);
View.StartAnimation(animation);

// Remove this before merge, it's here in case the team preffer to use the animation in code
//var slideUp = new TranslateAnimation(0, 0, 1000, 0)
//{
// Duration = 500,
// FillAfter = true
//};
animation!.AnimationEnd += OnAnimationEnded;
}

//// Start the animation
//View.StartAnimation(slideUp);
void OnAnimationEnded(object? sender, AAnimation.AnimationEndEventArgs e)
{
animation!.AnimationEnd -= OnAnimationEnded;
AnimationEnded?.Invoke(this, EventArgs.Empty);
}
}

Expand Down
Loading