Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New Modal View Presenter and a fix or 2. #9

Closed
wants to merge 2 commits into from

2 participants

deapsquatter Stuart Lodge
deapsquatter

Maybe you don't want the view presenter in the framework but the 2nd commit has 2 fixes.

kevinknoop added some commits
kevinknoop Added support for modal views inside a UINavigationController. 49a7a13
kevinknoop MvxTrace fix to overloaded method TaggedTrace.
Removed criteria for constructor to be Public in the ioc object builder.
9bbe9fd
Stuart Lodge
Owner

Thanks Kevin

I'll have to come track you down at some point to discuss...

  • The TaggedTrace fix definitely.

  • The change to opennetic ioc maybe - although in vNext, I've replaced openNetCF - so would be good to talk IoC requirements with you!

  • The presenter... somehow I need to work out a contrib repo for these - I want to cut down on linked-compile size, but I also want to let people have access to lots of presenter examples - especially when it comes to modals, tabs, split screens, etc

Thanks for the pull request - will discuss with you online somewhere :)

Stuart

Stuart Lodge
Owner

At lest the simple TaggedTrace is in.

Still not sure I understand the others... will catch you one day soon - sorry, been a bit hectic with work :)

deapsquatter
Stuart Lodge
Owner

And today... I found myself writing the same presenter logic! Totally understand now :) 100% accepted - and I'm using your code - will work out how to merge this in :)

deapsquatter
Stuart Lodge
Owner

Thanks

I'm thinking the one in this pull request will probably replace the one in the existing tree - I can't remember why I ever wanted to push without a navigation controller....

Would love to see some more ipad presenters - one of the problems I have is that working cross platform I only get so much time to play with each toy. One day I would love to write a really nice pad app!

deapsquatter
Stuart Lodge
Owner

Thanks Kevin

I think I understand what you are saying - and I think it's really good you've included such a small sample - but I think your bugzilla report could be a little longer/more wordier - especially, it's not clear to me whether:

  • are you saying that ViewDidUnload does not get called?
  • or are you saying that ViewDidUnload does get called, but that afterwards the ViewController doesn't ever get garbagecollected/deleted?

I'm definitely aware that memory leaks can happen around this area

Stuart


Also - just checking - does the problem you are seeing happen on the simulator? Does it happen if you use "simulate memory warning" within the simulator?

deapsquatter
Stuart Lodge
Owner

Might be worth adding that detail to the bugzilla log - just so it's totally clear which objects are leaking and to let the xams know you've been watching using the mono profiler as well as instruments.

Stuart Lodge
Owner

I've finally added your modalnav controller... and I still really really really can't remember why I ever wanted to push a modal without a navigation controller....

Stuart Lodge slodge closed this
deapsquatter
Stuart Lodge
Owner

Ah - I've done that before :)

Glad to hear there's no leak no long as long you just bind to events at the ViewModel lifecycle scope - phew....

Thanks for the update

Stuart


Linked to this.... but not super-urgent - at some point we've got to work out how to "tombstone" views - e.g. how to cope with the situation where memory pressures cause ViewDidUnload to get called and then "Back" or "tabbing" causes ViewDidLoad to get called again... currently the code works, but it's possible to lose instance state - because the original ViewModel gets unlinked and a new one gets hooked up in its place.


deapsquatter
Stuart Lodge
Owner

Tombstoning's even more important in WP7 and Droid - and maybe winrt too.

I've been thinking of some kind of IMvxViewModelTombstoning API - but I'm not sure at present - it kind of feels like it should be an API at the constructor level...

Please do give it some thought - always good to come from real world application examples :)

Stuart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 14, 2012
Commits on May 22, 2012
  1. MvxTrace fix to overloaded method TaggedTrace.

    kevinknoop authored
    Removed criteria for constructor to be Public in the ioc object builder.
This page is out of date. Refresh to see the latest.
3  Cirrious/Cirrious.MvvmCross/Cirrious.MvvmCross.Touch.csproj
View
@@ -10,8 +10,6 @@
<OutputType>Library</OutputType>
<RootNamespace>Cirrious.MvvmCross</RootNamespace>
<AssemblyName>CirriousMvvmCrossTouch</AssemblyName>
- <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
- <TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
@@ -452,6 +450,7 @@
<Compile Include="Views\MvxViewsContainer.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Touch\Views\Presenters\MvxModalNavSupportTouchViewPresenter.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup />
2  Cirrious/Cirrious.MvvmCross/IoC/MvxOpenNetCfObjectBuilder.cs
View
@@ -66,7 +66,7 @@ internal static object CreateObject(Type type)
(type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
.Where(
c =>
- c.IsPublic && c.GetCustomAttributes(typeof (MvxOpenNetCfInjectionAttribute), true).Count() > 0));
+ c.GetCustomAttributes(typeof (MvxOpenNetCfInjectionAttribute), true).Count() > 0));
#endif
if (!ctors.Any())
6 Cirrious/Cirrious.MvvmCross/Platform/Diagnostics/MvxTrace.cs
View
@@ -50,9 +50,9 @@ public static void Trace(MvxTraceLevel level, string message, params object[] ar
Instance.Trace(level, DefaultTag, PrependWithTime(message), args);
}
- public static void TaggedTrace(string tag, string message, params object[] args)
- {
- Trace(MvxTraceLevel.Diagnostic, tag, message, args);
+ public static void TaggedTrace (string tag, string message, params object[] args)
+ {
+ TaggedTrace(MvxTraceLevel.Diagnostic, tag, message, args);
}
public static void Trace(string message, params object[] args)
109 Cirrious/Cirrious.MvvmCross/Touch/Views/Presenters/MvxModalNavSupportTouchViewPresenter.cs
View
@@ -0,0 +1,109 @@
+#region Copyright
+// <copyright file="MvxModalSupportTouchViewPresenter.cs" company="Cirrious">
+// (c) Copyright Cirrious. http://www.cirrious.com
+// This source is subject to the Microsoft Public License (Ms-PL)
+// Please see license.txt on http://opensource.org/licenses/ms-pl.html
+// All other rights reserved.
+// </copyright>
+//
+// Project Lead - Stuart Lodge, Cirrious. http://www.cirrious.com
+#endregion
+
+using Cirrious.MvvmCross.Exceptions;
+using Cirrious.MvvmCross.ExtensionMethods;
+using Cirrious.MvvmCross.Interfaces.Platform.Diagnostics;
+using Cirrious.MvvmCross.Interfaces.ViewModels;
+using Cirrious.MvvmCross.Platform.Diagnostics;
+using Cirrious.MvvmCross.Touch.Interfaces;
+using Cirrious.MvvmCross.Views;
+using MonoTouch.UIKit;
+
+namespace Cirrious.MvvmCross.Touch.Views.Presenters
+{
+ public class MvxModalNavSupportTouchViewPresenter : MvxTouchViewPresenter
+ {
+ private UIViewController _currentModalViewController;
+
+ public MvxModalNavSupportTouchViewPresenter(UIApplicationDelegate applicationDelegate, UIWindow window)
+ : base (applicationDelegate, window)
+ {
+ }
+
+ public override void Show (IMvxTouchView view)
+ {
+ if (view is IMvxModalTouchView)
+ {
+ if (_currentModalViewController != null)
+ throw new MvxException("Only one modal view controller at a time supported");
+
+ var newNav = new UINavigationController();
+ newNav.PushViewController(view as UIViewController, false);
+
+ _currentModalViewController = view as UIViewController;
+
+ PresentModalViewController(newNav, true);
+ return;
+ }
+
+ base.Show(view);
+ }
+
+ public override void NativeModalViewControllerDisappearedOnItsOwn()
+ {
+ if (_currentModalViewController != null)
+ {
+ MvxTrace.Trace(MvxTraceLevel.Error, "How did a modal disappear when we didn't have one showing?");
+ return;
+ }
+
+ // clear our local reference to avoid back confusion
+ _currentModalViewController = null;
+ }
+
+ public override void CloseModalViewController()
+ {
+ if (_currentModalViewController != null)
+ {
+ UINavigationController nav = _currentModalViewController.ParentViewController as UINavigationController;
+ if (nav != null)
+ nav.DismissModalViewControllerAnimated(true);
+ else
+ _currentModalViewController.DismissModalViewControllerAnimated(true);
+ _currentModalViewController = null;
+ return;
+ }
+
+ base.CloseModalViewController();
+ }
+
+ public override void Close(IMvxViewModel toClose)
+ {
+ if (_currentModalViewController != null)
+ {
+ var touchView = _currentModalViewController as IMvxTouchView;
+ if (touchView == null)
+ {
+ MvxTrace.Trace(MvxTraceLevel.Error, "Unable to close view - modal is showing but not an IMvxTouchView");
+ return;
+ }
+
+ var viewModel = touchView.ReflectionGetViewModel();
+ if (viewModel != toClose)
+ {
+ MvxTrace.Trace(MvxTraceLevel.Error, "Unable to close view - modal is showing but is not the requested viewmodel");
+ return;
+ }
+
+ UINavigationController nav = _currentModalViewController.ParentViewController as UINavigationController;
+ if (nav != null)
+ nav.DismissModalViewControllerAnimated(true);
+ else
+ _currentModalViewController.DismissModalViewControllerAnimated(true);
+ _currentModalViewController = null;
+ return;
+ }
+
+ base.Close(toClose);
+ }
+ }
+}
Something went wrong with that request. Please try again.