1+ using CoreAnimation ;
12using CoreGraphics ;
23using Foundation ;
34using ObjCRuntime ;
45using System . Collections ;
5- using System . Collections . Specialized ;
66using System . Drawing ;
77using UIKit ;
88
@@ -17,7 +17,7 @@ public sealed class IOSAutoCompleteEntry : UIView
1717 /// Raised after the text content of the editable control component is updated.
1818 /// </summary>
1919 public event EventHandler < AutoCompleteEntryTextChangedEventArgs > TextChanged ;
20-
20+
2121 /// <summary>
2222 /// Raised after the cursor position of the editable control component is updated.
2323 /// </summary>
@@ -39,7 +39,7 @@ public sealed class IOSAutoCompleteEntry : UIView
3939 private nfloat _keyboardHeight ;
4040 private NSLayoutConstraint _bottomConstraint ;
4141 private Func < object , string > _textFunc ;
42- private CoreAnimation . CALayer _border ;
42+ private CoreAnimation . CALayer _border = null ;
4343 private bool _showBottomBorder = true ;
4444 private readonly NSObject _keyboardShownObserverToken ;
4545 private readonly NSObject _keyboardHiddenObserverToken ;
@@ -128,12 +128,15 @@ public IOSAutoCompleteEntry() : this(RectangleF.Empty)
128128 InputTextField . SelectedTextRangeChanged += InputText_OnTextRangeChanged ;
129129 InputTextField . ShouldReturn += InputText_OnShouldReturn ;
130130
131- AddSubview ( InputTextField ) ;
131+ AddSubview ( InputTextField ) ;
132132
133- InputTextField . TopAnchor . ConstraintEqualTo ( TopAnchor ) . Active = true ;
134- InputTextField . LeftAnchor . ConstraintEqualTo ( LeftAnchor ) . Active = true ;
135- InputTextField . WidthAnchor . ConstraintEqualTo ( WidthAnchor ) . Active = true ;
136- InputTextField . HeightAnchor . ConstraintEqualTo ( HeightAnchor ) . Active = true ;
133+ NSLayoutConstraint . ActivateConstraints ( new [ ]
134+ {
135+ InputTextField . TopAnchor . ConstraintEqualTo ( TopAnchor ) ,
136+ InputTextField . LeftAnchor . ConstraintEqualTo ( LeftAnchor ) ,
137+ InputTextField . RightAnchor . ConstraintEqualTo ( RightAnchor ) ,
138+ InputTextField . BottomAnchor . ConstraintEqualTo ( BottomAnchor ) ,
139+ } ) ;
137140
138141 SelectionList = new UITableView { TranslatesAutoresizingMaskIntoConstraints = false } ;
139142
@@ -219,14 +222,14 @@ private void InputText_OnEditingChanged(object sender, EventArgs e)
219222 TextChanged ? . Invoke ( this , new AutoCompleteEntryTextChangedEventArgs ( AutoCompleteEntryTextChangeReason . UserInput ) ) ;
220223
221224 InputText_OnTextRangeChanged ( sender , e ) ;
222-
225+
223226 IsSuggestionListOpen = true ;
224227 }
225228
226229 private void InputText_OnTextRangeChanged ( object sender , EventArgs e )
227230 {
228231 var cp = InputTextField . GetOffsetFromPosition ( InputTextField . BeginningOfDocument , InputTextField . SelectedTextRange ? . Start ?? InputTextField . EndOfDocument ) . ToInt32 ( ) ;
229-
232+
230233 CursorPositionChanged ? . Invoke ( this , new AutoCompleteEntryCursorPositionChangedEventArgs ( cp ) ) ;
231234 }
232235
@@ -235,11 +238,12 @@ private bool InputText_OnShouldReturn(UITextField view)
235238 ShouldReturn ? . Invoke ( this , EventArgs . Empty ) ;
236239 return false ;
237240 }
238-
241+
239242 /// <inheritdoc />
240243 public override void LayoutSubviews ( )
241244 {
242245 base . LayoutSubviews ( ) ;
246+
243247 AddBottomBorder ( ) ;
244248 }
245249
@@ -292,17 +296,10 @@ private void UpdateSuggestionListOpenState()
292296 return ;
293297 }
294298
295- #if MACCATALYST14_2_OR_GREATER
296299 if ( viewController . PresentedViewController != null )
297300 {
298301 viewController = viewController . PresentedViewController ;
299302 }
300- #else
301- if ( viewController . ModalViewController != null )
302- {
303- viewController = viewController . ModalViewController ;
304- }
305- #endif
306303
307304 if ( SelectionList . Superview == null )
308305 {
@@ -319,7 +316,9 @@ private void UpdateSuggestionListOpenState()
319316 else
320317 {
321318 if ( SelectionList . Superview != null )
319+ {
322320 SelectionList . RemoveFromSuperview ( ) ;
321+ }
323322 }
324323 }
325324
@@ -376,7 +375,7 @@ private void SuggestionTableSource_TableRowSelected(object sender, TableRowSelec
376375 public class MyUITextField : UITextField
377376 {
378377 public event EventHandler < EventArgs > SelectedTextRangeChanged ;
379-
378+
380379 public override UITextRange SelectedTextRange
381380 {
382381 get => base . SelectedTextRange ;
@@ -385,7 +384,7 @@ public override UITextRange SelectedTextRange
385384 if ( base . SelectedTextRange == null || ! base . SelectedTextRange . Equals ( value ) )
386385 {
387386 base . SelectedTextRange = value ;
388-
387+
389388 SelectedTextRangeChanged ? . Invoke ( this , EventArgs . Empty ) ;
390389 }
391390 }
0 commit comments