[macOS] PushModalAsync a 2nd time causes a crash (#7250) fixes #6866
authorAndrei <andrei.misiukevich@gmail.com>
Tue, 17 Sep 2019 21:40:21 +0000 (00:40 +0300)
committerRui Marinho <me@ruimarinho.net>
Tue, 17 Sep 2019 21:40:21 +0000 (22:40 +0100)
* fixes https://github.com/xamarin/Xamarin.Forms/issues/6866

* fixed index boundaries to include 0 index

Xamarin.Forms.Platform.MacOS/ModalPageTracker.cs

index 07e2902..5c96665 100644 (file)
@@ -122,10 +122,15 @@ namespace Xamarin.Forms.Platform.MacOS
                        NSViewControllerTransitionOptions option = animated
                                                        ? NSViewControllerTransitionOptions.SlideDown
                                                        : NSViewControllerTransitionOptions.None;
-
                        var task = _renderer.HandleAsyncAnimation(controller, toViewController, option,
-                               () => modal.DisposeModalAndChildRenderers() , modal);
+                               () =>
+                               {
+                                       modal.DisposeModalAndChildRenderers();
+                                       var removingIndex = Array.IndexOf(_renderer.ChildViewControllers, controller);
+                                       if(removingIndex >= 0)
+                                               _renderer.RemoveChildViewController(removingIndex);
+                               }, modal);
                        return task;
                }
        }
-}
\ No newline at end of file
+}