From 92e9b9bee452d14676d09c43b8aeb22676d6d32b Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 15 Apr 2018 16:55:04 -0700 Subject: [PATCH] Call Page.Disappearing when session end --- Ooui.Forms/PlatformRenderer.cs | 29 +++++++++++++++++++++++++++-- Samples/DisplayAlertPage.xaml.cs | 7 +++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Ooui.Forms/PlatformRenderer.cs b/Ooui.Forms/PlatformRenderer.cs index 922d171..eb156a4 100644 --- a/Ooui.Forms/PlatformRenderer.cs +++ b/Ooui.Forms/PlatformRenderer.cs @@ -3,7 +3,7 @@ using Xamarin.Forms; namespace Ooui.Forms { - public class PlatformRenderer : Ooui.Div + public class PlatformRenderer : Ooui.Div, IDisposable { readonly Platform platform; @@ -18,6 +18,8 @@ namespace Ooui.Forms protected override bool TriggerEventFromMessage (Message message) { + if (disposedValue) + return false; if (message.TargetId == "window" && message.Key == "resize" && message.Value is Newtonsoft.Json.Linq.JObject j) { var width = (double)j["width"]; var height = (double)j["height"]; @@ -29,5 +31,28 @@ namespace Ooui.Forms return base.TriggerEventFromMessage (message); } } - } + + #region IDisposable Support + private bool disposedValue = false; + + protected virtual void Dispose (bool disposing) + { + if (!disposedValue) { + if (disposing) { + // Disconnect any events we started + // Inform the page it's leaving + if (Platform.Page is IPageController pc) { + pc.SendDisappearing (); + } + } + disposedValue = true; + } + } + + public void Dispose () + { + Dispose (true); + } + #endregion + } } diff --git a/Samples/DisplayAlertPage.xaml.cs b/Samples/DisplayAlertPage.xaml.cs index 16acfcd..fa94532 100644 --- a/Samples/DisplayAlertPage.xaml.cs +++ b/Samples/DisplayAlertPage.xaml.cs @@ -21,6 +21,13 @@ namespace Samples status.Text = "Page appeared"; } + protected override void OnDisappearing () + { + base.OnDisappearing (); + + Console.WriteLine ("Disappear was called"); + } + public async void OnButtonClicked(object sender, EventArgs args) { activity.IsRunning = true;