1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-28 14:13:25 +00:00

attach and detach event handlers onappearing and ondisappearing to free up views for GC

This commit is contained in:
Kyle Spearrin
2017-02-15 00:28:05 -05:00
parent 56c33ee82b
commit f5e7f9249c
18 changed files with 332 additions and 106 deletions

View File

@@ -5,8 +5,11 @@ using XLabs.Ioc;
namespace Bit.App.Controls
{
public class FormEntryCell : ExtendedViewCell
public class FormEntryCell : ExtendedViewCell, IDisposable
{
private VisualElement _nextElement;
private TapGestureRecognizer _tgr;
public FormEntryCell(
string labelText,
Keyboard entryKeyboard = null,
@@ -17,6 +20,8 @@ namespace Bit.App.Controls
Thickness? containerPadding = null,
bool useButton = false)
{
_nextElement = nextElement;
if(!useLabelAsPlaceholder)
{
Label = new Label
@@ -47,7 +52,6 @@ namespace Bit.App.Controls
if(nextElement != null)
{
Entry.ReturnType = Enums.ReturnType.Next;
Entry.Completed += (object sender, EventArgs e) => { nextElement.Focus(); };
}
var imageStackLayout = new StackLayout
@@ -61,8 +65,7 @@ namespace Bit.App.Controls
if(imageSource != null)
{
var tgr = new TapGestureRecognizer();
tgr.Tapped += Tgr_Tapped;
_tgr = new TapGestureRecognizer();
var theImage = new Image
{
@@ -70,7 +73,7 @@ namespace Bit.App.Controls
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Center
};
theImage.GestureRecognizers.Add(tgr);
theImage.GestureRecognizers.Add(_tgr);
imageStackLayout.Children.Add(theImage);
}
@@ -126,8 +129,6 @@ namespace Bit.App.Controls
}
}
Tapped += FormEntryCell_Tapped;
View = imageStackLayout;
}
@@ -135,6 +136,21 @@ namespace Bit.App.Controls
public ExtendedEntry Entry { get; private set; }
public ExtendedButton Button { get; private set; }
public void InitEvents()
{
if(_nextElement != null)
{
Entry.Completed += Entry_Completed;
}
if(_tgr != null)
{
_tgr.Tapped += Tgr_Tapped;
}
Tapped += FormEntryCell_Tapped;
}
private void Tgr_Tapped(object sender, EventArgs e)
{
Entry.Focus();
@@ -144,5 +160,21 @@ namespace Bit.App.Controls
{
Entry.Focus();
}
private void Entry_Completed(object sender, EventArgs e)
{
_nextElement?.Focus();
}
public void Dispose()
{
if(_tgr != null)
{
_tgr.Tapped -= Tgr_Tapped;
}
Tapped -= FormEntryCell_Tapped;
Entry.Completed -= Entry_Completed;
}
}
}