Skip to content

Instantly share code, notes, and snippets.

@gshackles
Last active December 27, 2015 11:59
Show Gist options
  • Save gshackles/7322246 to your computer and use it in GitHub Desktop.
Save gshackles/7322246 to your computer and use it in GitHub Desktop.
public class PhonePresenter : MvxTouchViewPresenter
{
private void navigateInPlace(MvxViewModelRequest request)
{
var nextViewController = (UIViewController)ViewCreator.CreateView(request);
var menuViewController = MasterNavigationController.ViewControllers.FirstOrDefault(vc => vc.GetType() == nextViewController.GetType());
if (menuViewController != null)
{
MasterNavigationController.PopToViewController(menuViewController, true);
}
else
{
var transition = new CATransition();
transition.Duration = 0.3;
transition.Type = CAAnimation.TransitionPush;
transition.Subtype = CAAnimation.TransitionFade;
var exitingViewController = MasterNavigationController.TopViewController;
MasterNavigationController.PopViewControllerAnimated(false);
MasterNavigationController.View.Layer.AddAnimation (transition, null);
MasterNavigationController.PushViewController(nextViewController, false);
exitingViewController.SafeDispose();
}
}
}
public abstract class ViewControllerBase : MvxViewController
{
public override void DidMoveToParentViewController(UIViewController parent)
{
base.DidMoveToParentViewController(parent);
if (parent == null)
this.SafeDispose();
}
}
public static class ViewControllerExtensions
{
public static void SafeDispose(this UIViewController viewController)
{
if (viewController.ParentViewController != null)
return;
var mvxView = viewController as IMvxTouchView;
if (mvxView == null)
return;
if (mvxView.ViewModel is IDisposable)
((IDisposable)mvxView.ViewModel).Dispose();
mvxView.ViewModel = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment