@@ -17,7 +17,7 @@ interface EditTextListeners extends android.text.TextWatcher, android.view.View.
1717
1818interface EditTextListenersClass {
1919 prototype : EditTextListeners ;
20- new ( owner : EditableTextBase ) : EditTextListeners ;
20+ new ( owner : EditableTextBase ) : EditTextListeners ;
2121}
2222
2323let EditTextListeners : EditTextListenersClass ;
@@ -71,38 +71,29 @@ function initializeEditTextListeners(): void {
7171 }
7272
7373 if ( hasFocus ) {
74- if ( dismissKeyboardTimeoutId ) {
75- // https://github.com/NativeScript/NativeScript/issues/2942
76- // Don't hide the keyboard since another (or the same) EditText has gained focus.
77- clearTimeout ( dismissKeyboardTimeoutId ) ;
78- dismissKeyboardTimeoutId = undefined ;
79- }
8074 owner . notify ( { eventName : EditableTextBase . focusEvent , object : owner } ) ;
75+ owner . focus ( ) ;
8176 }
8277 else {
8378 if ( owner . _dirtyTextAccumulator || owner . _dirtyTextAccumulator === "" ) {
8479 textProperty . nativeValueChange ( owner , owner . _dirtyTextAccumulator ) ;
8580 owner . _dirtyTextAccumulator = undefined ;
8681 }
8782
88- dismissKeyboardTimeoutId = setTimeout ( ( ) => {
89- // https://github.com/NativeScript/NativeScript/issues/2942
90- // Dismiss the keyboard if focus goes to something different from EditText.
91- owner . dismissSoftInput ( ) ;
92- dismissKeyboardTimeoutId = null ;
93- } , 1 ) ;
94-
9583 owner . notify ( { eventName : EditableTextBase . blurEvent , object : owner } ) ;
84+ owner . dismissSoftInput ( ) ;
9685 }
9786 }
9887
9988 public onEditorAction ( textView : android . widget . TextView , actionId : number , event : android . view . KeyEvent ) : boolean {
10089 const owner = this . owner ;
10190 if ( ! owner ) {
102- return ;
91+ return false ;
10392 }
10493
105- if ( actionId === android . view . inputmethod . EditorInfo . IME_ACTION_DONE ||
94+ if ( actionId === android . view . inputmethod . EditorInfo . IME_NULL ||
95+ actionId === android . view . inputmethod . EditorInfo . IME_ACTION_UNSPECIFIED ||
96+ actionId === android . view . inputmethod . EditorInfo . IME_ACTION_DONE ||
10697 actionId === android . view . inputmethod . EditorInfo . IME_ACTION_GO ||
10798 actionId === android . view . inputmethod . EditorInfo . IME_ACTION_SEARCH ||
10899 actionId === android . view . inputmethod . EditorInfo . IME_ACTION_SEND ||
@@ -112,8 +103,8 @@ function initializeEditTextListeners(): void {
112103 if ( textView . getMaxLines ( ) === 1 ) {
113104 owner . dismissSoftInput ( ) ;
114105 }
106+
115107 owner . _onReturnPress ( ) ;
116- return true ;
117108 }
118109
119110 // If action is ACTION_NEXT then do not close keyboard
@@ -178,7 +169,20 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
178169 }
179170
180171 public dismissSoftInput ( ) {
181- ad . dismissSoftInput ( this . nativeViewProtected ) ;
172+ const nativeView = this . nativeViewProtected ;
173+ if ( ! nativeView ) {
174+ return ;
175+ }
176+
177+ const activity = this . _context as android . app . Activity ;
178+ setTimeout ( ( ) => {
179+ const focused = activity . getCurrentFocus ( ) ;
180+ if ( ! focused
181+ || focused === nativeView
182+ || ! ( focused instanceof android . widget . EditText ) ) {
183+ ad . dismissSoftInput ( nativeView ) ;
184+ }
185+ } , 100 ) ;
182186 }
183187
184188 public focus ( ) : boolean {
0 commit comments