1- using Foundation ;
1+ using System . Drawing ;
2+ using Foundation ;
23using Microsoft . Maui . Handlers ;
34using Microsoft . Maui . Platform ;
45using UIKit ;
56
67namespace AuroraControls ;
78
8- public partial class NumericEntryHandler : EntryHandler
9+ public partial class NumericEntryHandler : EntryHandler , IDisposable
910{
11+ private UIBarButtonItem _doneButton ;
12+
1013 protected override void ConnectHandler ( MauiTextField platformView )
1114 {
1215 base . ConnectHandler ( platformView ) ;
1316
17+ var toolbar = new UIToolbar ( new RectangleF ( 0 , 0 , ( float ) UIScreen . MainScreen . Bounds . Width , 44 ) ) { BarStyle = UIBarStyle . Default , Translucent = true } ;
18+ _doneButton = new UIBarButtonItem ( UIBarButtonSystemItem . Done ) ;
19+ _doneButton . Clicked += DoneButtonOnClicked ;
20+
21+ toolbar . Items = [ new UIBarButtonItem ( UIBarButtonSystemItem . FlexibleSpace ) , _doneButton , ] ;
22+ platformView . InputAccessoryView = toolbar ;
23+
1424 platformView . ShouldChangeCharacters += OnShouldChangeCharacters ;
1525 }
1626
1727 protected override void DisconnectHandler ( MauiTextField platformView )
1828 {
1929 platformView . ShouldChangeCharacters -= OnShouldChangeCharacters ;
30+ _doneButton . Clicked -= DoneButtonOnClicked ;
31+
32+ PlatformView . InputAccessoryView ? . Dispose ( ) ;
33+ PlatformView . InputAccessoryView = null ;
2034
2135 base . DisconnectHandler ( platformView ) ;
2236 }
2337
38+ private void DoneButtonOnClicked ( object ? sender , EventArgs e )
39+ {
40+ this . PlatformView . ResignFirstResponder ( ) ;
41+ }
42+
2443 private bool OnShouldChangeCharacters ( UITextField textField , NSRange range , string replacementString )
2544 {
2645 string originalSource = replacementString ;
@@ -36,4 +55,18 @@ private bool OnShouldChangeCharacters(UITextField textField, NSRange range, stri
3655
3756 return IsValid ( final , NumericEntryVirtualView . CultureInfo , NumericEntryVirtualView . ValueType ) ;
3857 }
58+
59+ protected virtual void Dispose ( bool disposing )
60+ {
61+ if ( disposing )
62+ {
63+ _doneButton . Dispose ( ) ;
64+ }
65+ }
66+
67+ public void Dispose ( )
68+ {
69+ Dispose ( true ) ;
70+ GC . SuppressFinalize ( this ) ;
71+ }
3972}
0 commit comments