Skip to content

Commit

Permalink
Fix for closing and re-opening non-fullscreen modals on iOS fast not …
Browse files Browse the repository at this point in the history
…working correctly (#4554)

* Update MvxModalPresentationControllerDelegate.cs

* Fixed iOS modals not opening and closing correctly by swipe gesture

* Remove ClosedModalViewController since it's redundant

* Update MvxIosViewPresenter.cs

* Update MvxModalPresentationControllerDelegate.cs

* Update MvxIosViewPresenter.cs

* Remove forgotten leftover when DidDismiss was used in MvxModalPresentationControllerDelegate instead of WillDismiss
  • Loading branch information
Digifais committed Jan 20, 2023
1 parent 183ebbc commit e573653
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
3 changes: 0 additions & 3 deletions MvvmCross/Platforms/Ios/Presenters/IMvxIosViewPresenter.cs
Expand Up @@ -14,9 +14,6 @@ namespace MvvmCross.Platforms.Ios.Presenters
public interface IMvxIosViewPresenter : IMvxViewPresenter, IMvxCanCreateIosView
{
public void ClosedPopoverViewController();

public ConfiguredTaskAwaitable<bool> ClosedModalViewController(UIViewController viewController,
MvxModalPresentationAttribute attribute);
}
#nullable restore
}
29 changes: 6 additions & 23 deletions MvvmCross/Platforms/Ios/Presenters/MvxIosViewPresenter.cs
Expand Up @@ -410,12 +410,6 @@ private Task<bool> ShowPopoverViewControllerChild(UIViewController viewControlle
{
ValidateArguments(viewController, attribute);

// Content size should be set to a target view controller, not the navigation one
if (attribute.PreferredContentSize != default)
{
viewController.PreferredContentSize = attribute.PreferredContentSize;
}

// setup modal based on attribute
if (attribute.WrapInNavigationController)
{
Expand All @@ -424,6 +418,9 @@ private Task<bool> ShowPopoverViewControllerChild(UIViewController viewControlle

viewController.ModalPresentationStyle = attribute.ModalPresentationStyle;
viewController.ModalTransitionStyle = attribute.ModalTransitionStyle;
if (attribute.PreferredContentSize != default(CGSize))
viewController.PreferredContentSize = attribute.PreferredContentSize;

if (_iosVersion13Checker.IsVersionOrHigher && viewController.PresentationController != null)
{
viewController.PresentationController.Delegate =
Expand All @@ -432,19 +429,12 @@ private Task<bool> ShowPopoverViewControllerChild(UIViewController viewControlle

// Check if there is a modal already presented first. Otherwise use the window root
var modalHost = ModalViewControllers.LastOrDefault() ?? Window.RootViewController;
if (modalHost != null)
{
modalHost.PresentViewController(
viewController,
attribute.Animated,
null);

ModalViewControllers.Add(viewController);
modalHost.PresentViewController(viewController, attribute.Animated, null);

return Task.FromResult(true);
}
ModalViewControllers.Add(viewController);

return Task.FromResult(false);
return Task.FromResult(true);
}

protected virtual async Task<bool> ShowPopoverViewController(
Expand Down Expand Up @@ -845,13 +835,6 @@ public virtual void ClosedPopoverViewController()
PopoverViewController = null;
}

// Called if the modal was dismissed by user (perhaps tapped background or form sheet swiped down)
public virtual ConfiguredTaskAwaitable<bool> ClosedModalViewController(UIViewController viewController,
MvxModalPresentationAttribute attribute)
{
return CloseModalViewController(viewController, attribute).ConfigureAwait(false);
}

private static void ValidateArguments(Type viewModelType, Type viewType)
{
if (viewModelType == null)
Expand Down
Expand Up @@ -9,20 +9,20 @@ namespace MvvmCross.Platforms.Ios.Presenters
{
public class MvxModalPresentationControllerDelegate : UIAdaptivePresentationControllerDelegate
{
private readonly IMvxIosViewPresenter _presenter;
private readonly MvxIosViewPresenter _presenter;
private readonly UIViewController _viewController;
private readonly MvxModalPresentationAttribute _attribute;

public MvxModalPresentationControllerDelegate(IMvxIosViewPresenter presenter, UIViewController viewController, MvxModalPresentationAttribute attribute)
public MvxModalPresentationControllerDelegate(MvxIosViewPresenter presenter, UIViewController viewController, MvxModalPresentationAttribute attribute)
{
_presenter = presenter;
_viewController = viewController;
_attribute = attribute;
}

public override void DidDismiss(UIPresentationController presentationController)
public override void WillDismiss(UIPresentationController presentationController)
{
_presenter.ClosedModalViewController(_viewController, _attribute);
_presenter.CloseModalViewController(_viewController, _attribute);
}
}
}

0 comments on commit e573653

Please sign in to comment.