I get from UIApplication
and overriding SendEvent
to capture custom branches. Everything works fine, except when closing type modals IMvxModalIosView
.
Here's the method:
public override void SendEvent(UIEvent uievent)
{
NSSet touches = uievent.AllTouches;
if (touches != null)
{
UITouch touch = (UITouch)touches.AnyObject;
switch (touch.Phase)
{
case UITouchPhase.Ended:
StartDoingStuffAgain();
break;
default:
StopDoingStuff();
break;
}
}
base.SendEvent(uievent);
}
Debugging this when closing IMvxModalIosView
, if I set a breakpoint at the beginning of the method, and also StartDoingStuffAgain()
, the last one hits. If, however, I set a breakpoint at StartDoingStuffAgain()
, it never hits. StopDoingStuff()
falls independently.
Why is this?
Edit 1: As requested by nmilcoff to get additional code:
[Register("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
{
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
_app = application as MyUIApplication;
}
}
[Register("MyUIApplication")]
public class MyUIApplication : UIApplication
{
}
public class MyIPadViewPresenter : MvxBaseIosViewPresenter
{
private UINavigationController _navController;
private UINavigationController _modalNavController;
private IMvxMessenger _messenger;
protected readonly SemaphoreSlim _autoLock = new SemaphoreSlim(1, 1);
public override async void Show(MvxViewModelRequest request)
{
await _autoLock.WaitAsync();
if(_messenger == null)
{
_messenger = Mvx.Resolve<IMvxMessenger>();
}
var presentation = MvxIOSPresentationHelpers.CreateView(request, TargetIdiom.Tablet);
switch(presentation.Type)
{
case ViewType.ModalWithNav:
showNavModalView(presentation.ViewController);
break;
}
messenger.Publish(new ViewModelShowMessage(request.ViewModelType, presentation.ViewController, this));
_autoLock.Release();
}
private void showNavModalView(UIViewController viewController)
{
if(_modalNavController == null)
{
_modalNavController = new ModalNavController(viewController);
_modalNavController.ModalPresentationStyle = viewController.ModalPresentationStyle;
_navController.PresentViewController(_modalNavController, false, delegate { });
}
else
{
_modalNavController.PushViewController(viewController, true);
}
}
public override async void ChangePresentation(MvxPresentationHint hint)
{
var close_hint = hint as MvxClosePresentationHint;
if (close_hint != null)
{
await _autoLock.WaitAsync();
close(close_hint.ViewModelToClose);
_autoLock.Release();
}
else
{
}
}
protected void close(IMvxViewModel toClose)
{
_messenger.Publish(new MvxMessage(this));
if (_modalNavController != null)
{
if(_modalNavController.ChildViewControllers.Length <= 1)
{
_modalNavController.DismissViewController(true, delegate{ });
_modalNavController = null;
}
else
{
}
return;
}
}
}
public class MyProblematicModalVM : MvxViewModel
{
public ICommand CloseCommand
{
get { return new MvxCommand(() => Close(this)); }
}
}
source
share