@@ -19,15 +19,13 @@ protected override MauiPicker CreatePlatformView() =>
1919
2020 protected override void ConnectHandler ( MauiPicker platformView )
2121 {
22- platformView . FocusChange += OnFocusChange ;
2322 platformView . Click += OnClick ;
2423
2524 base . ConnectHandler ( platformView ) ;
2625 }
2726
2827 protected override void DisconnectHandler ( MauiPicker platformView )
2928 {
30- platformView . FocusChange -= OnFocusChange ;
3129 platformView . Click -= OnClick ;
3230
3331 base . DisconnectHandler ( platformView ) ;
@@ -86,25 +84,29 @@ public static void MapVerticalTextAlignment(IPickerHandler handler, IPicker pick
8684 handler . PlatformView ? . UpdateVerticalAlignment ( picker . VerticalTextAlignment ) ;
8785 }
8886
89- void OnFocusChange ( object ? sender , global :: Android . Views . View . FocusChangeEventArgs e )
87+ internal static void MapFocus ( IPickerHandler handler , IPicker picker , object ? args )
9088 {
91- if ( PlatformView == null )
92- return ;
93-
94- if ( e . HasFocus )
89+ if ( handler . IsConnected ( ) )
9590 {
96- if ( PlatformView . Clickable )
97- PlatformView . CallOnClick ( ) ;
98- else
99- OnClick ( PlatformView , EventArgs . Empty ) ;
91+ ViewHandler . MapFocus ( handler , picker , args ) ;
92+ handler . PlatformView . CallOnClick ( ) ;
10093 }
101- else if ( _dialog != null )
94+ }
95+
96+ internal static void MapUnfocus ( IPickerHandler handler , IPicker picker , object ? args )
97+ {
98+ if ( handler . IsConnected ( ) && handler is PickerHandler pickerHandler )
10299 {
103- _dialog . Hide ( ) ;
104- _dialog = null ;
100+ pickerHandler . DismissDialog ( ) ;
101+ ViewHandler . MapUnfocus ( handler , picker , args ) ;
105102 }
106103 }
107104
105+ void DismissDialog ( )
106+ {
107+ _dialog ? . Dismiss ( ) ;
108+ }
109+
108110 void OnClick ( object ? sender , EventArgs e )
109111 {
110112 if ( _dialog == null && VirtualView != null )
@@ -152,15 +154,37 @@ void OnClick(object? sender, EventArgs e)
152154
153155 _dialog . SetCanceledOnTouchOutside ( true ) ;
154156
155- _dialog . DismissEvent += ( sender , args ) =>
156- {
157- _dialog = null ;
158- } ;
157+ _dialog . ShowEvent += OnDialogShown ;
158+
159+ _dialog . DismissEvent += OnDialogDismiss ;
159160
160161 _dialog . Show ( ) ;
161162 }
162163 }
163164
165+ void OnDialogDismiss ( object ? sender , EventArgs e )
166+ {
167+ if ( _dialog is null )
168+ {
169+ return ;
170+ }
171+
172+ _dialog . DismissEvent -= OnDialogDismiss ;
173+ VirtualView . IsFocused = false ;
174+ _dialog = null ;
175+ }
176+
177+ void OnDialogShown ( object ? sender , EventArgs e )
178+ {
179+ if ( _dialog is null )
180+ {
181+ return ;
182+ }
183+
184+ _dialog . ShowEvent -= OnDialogShown ;
185+ VirtualView . IsFocused = true ;
186+ }
187+
164188 static void Reload ( IPickerHandler handler )
165189 {
166190 handler . PlatformView . UpdatePicker ( handler . VirtualView ) ;
0 commit comments