Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Revert "Fix hangs and NREs with Entry Observer (#14859)"
Browse files Browse the repository at this point in the history
This reverts commit 5188c4f.
  • Loading branch information
jfversluis committed Nov 16, 2021
1 parent a28c1f7 commit eb2f38c
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public abstract class EntryRendererBase<TControl> : ViewRenderer<Entry, TControl
bool _useLegacyColorManagement;

bool _disposed;
bool _observedSublayers;
IDisposable _selectedTextRangeObserver;
IDisposable _clearButtonSublayerObserver;
bool _nativeSelectionIsUpdating;

bool _cursorPositionChangePending;
Expand Down Expand Up @@ -93,12 +93,7 @@ protected override void Dispose(bool disposing)
Control.EditingDidEnd -= OnEditingEnded;
Control.ShouldChangeCharacters -= ShouldChangeCharacters;
_selectedTextRangeObserver?.Dispose();

if (_observedSublayers)
{
ClearButton?.Layer?.RemoveObserver(this, new NSString("sublayers"));
_observedSublayers = false;
}
_clearButtonSublayerObserver?.Dispose();
}
}

Expand Down Expand Up @@ -133,8 +128,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
textField.ShouldChangeCharacters += ShouldChangeCharacters;
_selectedTextRangeObserver = textField.AddObserver("selectedTextRange", NSKeyValueObservingOptions.New, UpdateCursorFromControl);

ClearButton?.Layer.AddObserver(this, new NSString("sublayers"), NSKeyValueObservingOptions.New, IntPtr.Zero);
_observedSublayers = true;
_clearButtonSublayerObserver = ClearButton?.Layer.AddObserver(new NSString("sublayers"), NSKeyValueObservingOptions.New, UpdateClearButtonSublayer);
}

// When we set the control text, it triggers the UpdateCursorFromControl event, which updates CursorPosition and SelectionLength;
Expand Down Expand Up @@ -166,12 +160,6 @@ protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
UpdateClearButtonVisibility();
}

public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
if (keyPath == new NSString("sublayers") && _defaultClearImage == null)
UpdateClearButtonVisibility();
}

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Entry.PlaceholderProperty.PropertyName || e.PropertyName == Entry.PlaceholderColorProperty.PropertyName)
Expand Down Expand Up @@ -446,6 +434,15 @@ void UpdateCursorFromControl(NSObservedChange obj)
}
}

void UpdateClearButtonSublayer(NSObservedChange obj)
{
if (Control == null || Element == null)
return;

if (_defaultClearImage == null)
UpdateClearButtonVisibility();
}

void UpdateCursorSelection()
{
if (_nativeSelectionIsUpdating || Control == null || Element == null)
Expand Down

0 comments on commit eb2f38c

Please sign in to comment.