diff --git a/SlideOverKit.Droid/MenuContainerPageDroidRenderer.cs b/SlideOverKit.Droid/MenuContainerPageDroidRenderer.cs index 928c901..cc02b4f 100644 --- a/SlideOverKit.Droid/MenuContainerPageDroidRenderer.cs +++ b/SlideOverKit.Droid/MenuContainerPageDroidRenderer.cs @@ -14,7 +14,9 @@ public class MenuContainerPageDroidRenderer : PageRenderer, ISlideOverKitPageRe public Action OnLayoutEvent { get; set; } - public Action OnSizeChangedEvent { get; set; } + public Action OnSizeChangedEvent { get; set; } + + public bool IsDisposed { get; private set; } public MenuContainerPageDroidRenderer () { @@ -41,6 +43,12 @@ protected override void OnSizeChanged (int w, int h, int oldw, int oldh) if (OnSizeChangedEvent != null) OnSizeChangedEvent (w, h, oldw, oldh); } + + protected override void Dispose(bool disposing) + { + IsDisposed = true; + base.Dispose(disposing); + } } } diff --git a/SlideOverKit.Droid/SlideOverKitDroidHandler.cs b/SlideOverKit.Droid/SlideOverKitDroidHandler.cs index 7818188..90a1b03 100644 --- a/SlideOverKit.Droid/SlideOverKitDroidHandler.cs +++ b/SlideOverKit.Droid/SlideOverKitDroidHandler.cs @@ -202,8 +202,10 @@ Rect LayoutPopup () void HideBackgroundOverlay () { - if (_backgroundOverlay != null) { - _pageRenderer.RemoveView (_backgroundOverlay); + if (_backgroundOverlay != null) { + var renderer = _pageRenderer as MenuContainerPageDroidRenderer; + if (renderer == null || !renderer.IsDisposed) + _pageRenderer.RemoveView(_backgroundOverlay); _backgroundOverlay.Dispose (); _backgroundOverlay = null; }