1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-28 22:23:35 +00:00

tearing down event handlers on page disappears

This commit is contained in:
Kyle Spearrin
2017-02-17 00:16:09 -05:00
parent fb564fa817
commit 22f3bd1073
9 changed files with 154 additions and 90 deletions

View File

@@ -4,14 +4,13 @@ using Xamarin.Forms;
namespace Bit.App.Controls
{
public class DismissModalToolBarItem : ToolbarItem, IDisposable
public class DismissModalToolBarItem : ExtendedToolbarItem, IDisposable
{
private readonly ContentPage _page;
private readonly Action _cancelClickedAction;
public DismissModalToolBarItem(ContentPage page, string text = null, Action cancelClickedAction = null)
: base(cancelClickedAction)
{
_cancelClickedAction = cancelClickedAction;
_page = page;
// TODO: init and dispose events from pages
InitEvents();
@@ -19,20 +18,10 @@ namespace Bit.App.Controls
Priority = -1;
}
private async void ClickedItem(object sender, EventArgs e)
protected async override void ClickedItem(object sender, EventArgs e)
{
_cancelClickedAction?.Invoke();
base.ClickedItem(sender, e);
await _page.Navigation.PopModalAsync();
}
public void InitEvents()
{
Clicked += ClickedItem;
}
public void Dispose()
{
Clicked -= ClickedItem;
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class ExtendedToolbarItem : ToolbarItem, IDisposable
{
public ExtendedToolbarItem(Action clickAction = null)
{
ClickAction = clickAction;
}
public Action ClickAction { get; set; }
protected virtual void ClickedItem(object sender, EventArgs e)
{
ClickAction?.Invoke();
}
public void InitEvents()
{
Clicked += ClickedItem;
}
public void Dispose()
{
Clicked -= ClickedItem;
}
}
}

View File

@@ -6,21 +6,17 @@ namespace Bit.App.Controls
{
public class VaultListViewCell : LabeledDetailCell
{
private Action<VaultListPageModel.Login> _moreClickedAction;
public static readonly BindableProperty LoginParameterProperty = BindableProperty.Create(nameof(LoginParameter),
typeof(VaultListPageModel.Login), typeof(VaultListViewCell), null);
public VaultListViewCell(Action<VaultListPageModel.Login> moreClickedAction)
{
_moreClickedAction = moreClickedAction;
SetBinding(LoginParameterProperty, new Binding("."));
Label.SetBinding<VaultListPageModel.Login>(Label.TextProperty, s => s.Name);
Detail.SetBinding<VaultListPageModel.Login>(Label.TextProperty, s => s.Username);
Button.Image = "more";
Button.Command = new Command(() => ShowMore());
Button.Command = new Command(() => moreClickedAction?.Invoke(LoginParameter));
Button.BackgroundColor = Color.Transparent;
BackgroundColor = Color.White;
@@ -31,10 +27,5 @@ namespace Bit.App.Controls
get { return GetValue(LoginParameterProperty) as VaultListPageModel.Login; }
set { SetValue(LoginParameterProperty, value); }
}
private void ShowMore()
{
_moreClickedAction?.Invoke(LoginParameter);
}
}
}