summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2017-02-03 01:18:22 -0600
committerStephane Delcroix <stephane@delcroix.org>2017-02-03 08:18:22 +0100
commit0dff517c22195b145fdb1b2d1ce6e07190d19445 (patch)
tree7bf9cfe63eae0c99f69349c9a3eaa49e1d518b83 /Xamarin.Forms.Platform.iOS
parent3c7b2918b3065a81ecb4040fde09d93aae09f62d (diff)
downloadxamarin-forms-0dff517c22195b145fdb1b2d1ce6e07190d19445.tar.gz
xamarin-forms-0dff517c22195b145fdb1b2d1ce6e07190d19445.tar.bz2
xamarin-forms-0dff517c22195b145fdb1b2d1ce6e07190d19445.zip
[iOS] Dispose Entry and Editor properly and automate GC checks (#628)
* fix entry leak * change code style * reduce indentation * fix editorrenderer * add uitest * revert editorrenderer changes * Fix Editor
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs39
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs33
-rw-r--r--Xamarin.Forms.Platform.iOS/ViewRenderer.cs1
3 files changed, 44 insertions, 29 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs
index 448ebada..b11c3270 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs
@@ -7,17 +7,24 @@ namespace Xamarin.Forms.Platform.iOS
{
public class EditorRenderer : ViewRenderer<Editor, UITextView>
{
- UIToolbar _accessoryView;
-
+ bool _disposed;
IElementController ElementController => Element as IElementController;
protected override void Dispose(bool disposing)
{
+ if (_disposed)
+ return;
+
+ _disposed = true;
+
if (disposing)
{
- Control.Changed -= HandleChanged;
- Control.Started -= OnStarted;
- Control.Ended -= OnEnded;
+ if (Control != null)
+ {
+ Control.Changed -= HandleChanged;
+ Control.Started -= OnStarted;
+ Control.Ended -= OnEnded;
+ }
}
base.Dispose(disposing);
@@ -27,6 +34,9 @@ namespace Xamarin.Forms.Platform.iOS
{
base.OnElementChanged(e);
+ if (e.NewElement == null)
+ return;
+
if (Control == null)
{
SetNativeControl(new UITextView(RectangleF.Empty));
@@ -35,7 +45,7 @@ namespace Xamarin.Forms.Platform.iOS
{
// iPhone does not have a dismiss keyboard button
var keyboardWidth = UIScreen.MainScreen.Bounds.Width;
- _accessoryView = new UIToolbar(new RectangleF(0, 0, keyboardWidth, 44)) { BarStyle = UIBarStyle.Default, Translucent = true };
+ var accessoryView = new UIToolbar(new RectangleF(0, 0, keyboardWidth, 44)) { BarStyle = UIBarStyle.Default, Translucent = true };
var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) =>
@@ -43,8 +53,8 @@ namespace Xamarin.Forms.Platform.iOS
Control.ResignFirstResponder();
Element.SendCompleted();
});
- _accessoryView.SetItems(new[] { spacer, doneButton }, false);
- Control.InputAccessoryView = _accessoryView;
+ accessoryView.SetItems(new[] { spacer, doneButton }, false);
+ Control.InputAccessoryView = accessoryView;
}
Control.Changed += HandleChanged;
@@ -52,14 +62,11 @@ namespace Xamarin.Forms.Platform.iOS
Control.Ended += OnEnded;
}
- if (e.NewElement != null)
- {
- UpdateText();
- UpdateFont();
- UpdateTextColor();
- UpdateKeyboard();
- UpdateEditable();
- }
+ UpdateText();
+ UpdateFont();
+ UpdateTextColor();
+ UpdateKeyboard();
+ UpdateEditable();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs
index 7fc9b04a..dd8be853 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs
@@ -10,6 +10,7 @@ namespace Xamarin.Forms.Platform.iOS
public class EntryRenderer : ViewRenderer<Entry, UITextField>
{
UIColor _defaultTextColor;
+ bool _disposed;
public EntryRenderer()
{
@@ -20,8 +21,15 @@ namespace Xamarin.Forms.Platform.iOS
protected override void Dispose(bool disposing)
{
+ if (_disposed)
+ return;
+
+ _disposed = true;
+
if (disposing)
{
+ _defaultTextColor = null;
+
if (Control != null)
{
Control.EditingDidBegin -= OnEditingBegan;
@@ -37,11 +45,13 @@ namespace Xamarin.Forms.Platform.iOS
{
base.OnElementChanged(e);
- var textField = Control;
+ if (e.NewElement == null)
+ return;
if (Control == null)
{
- SetNativeControl(textField = new UITextField(RectangleF.Empty));
+ var textField = new UITextField(RectangleF.Empty);
+ SetNativeControl(textField);
_defaultTextColor = textField.TextColor;
textField.BorderStyle = UITextBorderStyle.RoundedRect;
@@ -55,17 +65,14 @@ namespace Xamarin.Forms.Platform.iOS
textField.EditingDidEnd += OnEditingEnded;
}
- if (e.NewElement != null)
- {
- UpdatePlaceholder();
- UpdatePassword();
- UpdateText();
- UpdateColor();
- UpdateFont();
- UpdateKeyboard();
- UpdateAlignment();
- UpdateAdjustsFontSizeToFitWidth();
- }
+ UpdatePlaceholder();
+ UpdatePassword();
+ UpdateText();
+ UpdateColor();
+ UpdateFont();
+ UpdateKeyboard();
+ UpdateAlignment();
+ UpdateAdjustsFontSizeToFitWidth();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
diff --git a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
index 2cf9f754..8a433c91 100644
--- a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
@@ -74,6 +74,7 @@ namespace Xamarin.Forms.Platform.MacOS
if (disposing && Control != null && ManageNativeControlLifetime)
{
+ Control.RemoveFromSuperview();
Control.Dispose();
Control = null;
}