Call Page.Disappearing when session end

This commit is contained in:
Frank A. Krueger 2018-04-15 16:55:04 -07:00
parent 57b8aa15d2
commit 92e9b9bee4
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
2 changed files with 34 additions and 2 deletions

View File

@ -3,7 +3,7 @@ using Xamarin.Forms;
namespace Ooui.Forms namespace Ooui.Forms
{ {
public class PlatformRenderer : Ooui.Div public class PlatformRenderer : Ooui.Div, IDisposable
{ {
readonly Platform platform; readonly Platform platform;
@ -18,6 +18,8 @@ namespace Ooui.Forms
protected override bool TriggerEventFromMessage (Message message) 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) { if (message.TargetId == "window" && message.Key == "resize" && message.Value is Newtonsoft.Json.Linq.JObject j) {
var width = (double)j["width"]; var width = (double)j["width"];
var height = (double)j["height"]; var height = (double)j["height"];
@ -29,5 +31,28 @@ namespace Ooui.Forms
return base.TriggerEventFromMessage (message); 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
}
} }

View File

@ -21,6 +21,13 @@ namespace Samples
status.Text = "Page appeared"; status.Text = "Page appeared";
} }
protected override void OnDisappearing ()
{
base.OnDisappearing ();
Console.WriteLine ("Disappear was called");
}
public async void OnButtonClicked(object sender, EventArgs args) public async void OnButtonClicked(object sender, EventArgs args)
{ {
activity.IsRunning = true; activity.IsRunning = true;