Last active
December 27, 2015 11:59
-
-
Save gshackles/7322246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class ViewControllerBase : MvxViewController | |
{ | |
public override void DidMoveToParentViewController(UIViewController parent) | |
{ | |
base.DidMoveToParentViewController(parent); | |
if (parent == null) | |
this.SafeDispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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