mirror of
https://github.com/bitwarden/mobile
synced 2025-12-27 05:33:23 +00:00
attach and detach event handlers onappearing and ondisappearing to free up views for GC
This commit is contained in:
@@ -4,7 +4,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class DismissModalToolBarItem : ToolbarItem
|
||||
public class DismissModalToolBarItem : ToolbarItem, IDisposable
|
||||
{
|
||||
private readonly ContentPage _page;
|
||||
private readonly Action _cancelClickedAction;
|
||||
@@ -13,8 +13,9 @@ namespace Bit.App.Controls
|
||||
{
|
||||
_cancelClickedAction = cancelClickedAction;
|
||||
_page = page;
|
||||
// TODO: init and dispose events from pages
|
||||
InitEvents();
|
||||
Text = text ?? AppResources.Close;
|
||||
Clicked += ClickedItem;
|
||||
Priority = -1;
|
||||
}
|
||||
|
||||
@@ -23,5 +24,15 @@ namespace Bit.App.Controls
|
||||
_cancelClickedAction?.Invoke();
|
||||
await _page.Navigation.PopModalAsync();
|
||||
}
|
||||
|
||||
public void InitEvents()
|
||||
{
|
||||
Clicked += ClickedItem;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Clicked -= ClickedItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class FormEditorCell : ExtendedViewCell
|
||||
public class FormEditorCell : ExtendedViewCell, IDisposable
|
||||
{
|
||||
public FormEditorCell(Keyboard entryKeyboard = null, double? height = null)
|
||||
{
|
||||
@@ -26,7 +26,6 @@ namespace Bit.App.Controls
|
||||
|
||||
stackLayout.Children.Add(Editor);
|
||||
|
||||
Tapped += FormEditorCell_Tapped;
|
||||
Editor.AdjustMarginsForDevice();
|
||||
stackLayout.AdjustPaddingForDevice();
|
||||
|
||||
@@ -39,5 +38,15 @@ namespace Bit.App.Controls
|
||||
{
|
||||
Editor.Focus();
|
||||
}
|
||||
|
||||
public void InitEvents()
|
||||
{
|
||||
Tapped += FormEditorCell_Tapped;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Tapped -= FormEditorCell_Tapped;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Bit.App.Resources;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
@@ -42,8 +41,6 @@ namespace Bit.App.Controls
|
||||
Picker.AdjustMarginsForDevice();
|
||||
stackLayout.AdjustPaddingForDevice();
|
||||
|
||||
Tapped += FormPickerCell_Tapped;
|
||||
|
||||
View = stackLayout;
|
||||
}
|
||||
|
||||
@@ -54,5 +51,15 @@ namespace Bit.App.Controls
|
||||
{
|
||||
Picker.Focus();
|
||||
}
|
||||
|
||||
public void InitEvents()
|
||||
{
|
||||
Tapped += FormPickerCell_Tapped;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Tapped -= FormPickerCell_Tapped;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace Bit.App.Controls
|
||||
MaxLength = 4,
|
||||
Margin = new Thickness(0, int.MaxValue, 0, 0)
|
||||
};
|
||||
Entry.TextChanged += Entry_TextChanged;
|
||||
|
||||
if(Device.OS == TargetPlatform.Android)
|
||||
{
|
||||
@@ -30,6 +29,9 @@ namespace Bit.App.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public Label Label { get; set; }
|
||||
public ExtendedEntry Entry { get; set; }
|
||||
|
||||
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if(e.NewTextValue.Length >= 4)
|
||||
@@ -38,7 +40,14 @@ namespace Bit.App.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public Label Label { get; set; }
|
||||
public ExtendedEntry Entry { get; set; }
|
||||
public void InitEvents()
|
||||
{
|
||||
Entry.TextChanged += Entry_TextChanged;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Entry.TextChanged -= Entry_TextChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,6 @@ namespace Bit.App.Controls
|
||||
Value = value
|
||||
};
|
||||
|
||||
Stepper.ValueChanged += Stepper_ValueChanged;
|
||||
|
||||
var stackLayout = new StackLayout
|
||||
{
|
||||
Orientation = StackOrientation.Horizontal,
|
||||
@@ -56,13 +54,23 @@ namespace Bit.App.Controls
|
||||
View = stackLayout;
|
||||
}
|
||||
|
||||
public Label Label { get; private set; }
|
||||
public Label StepperValueLabel { get; private set; }
|
||||
public Stepper Stepper { get; private set; }
|
||||
|
||||
private void Stepper_ValueChanged(object sender, ValueChangedEventArgs e)
|
||||
{
|
||||
StepperValueLabel.Text = e.NewValue.ToString();
|
||||
}
|
||||
|
||||
public Label Label { get; private set; }
|
||||
public Label StepperValueLabel { get; private set; }
|
||||
public Stepper Stepper { get; private set; }
|
||||
public void InitEvents()
|
||||
{
|
||||
Stepper.ValueChanged += Stepper_ValueChanged;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Stepper.ValueChanged -= Stepper_ValueChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user