Просмотр исходного кода

Close keyboard even when there's no focused view in activity

Guy Carmeli 8 лет назад
Родитель
Сommit
f2077e3d7f

+ 3
- 9
android/app/src/main/java/com/reactnativenavigation/utils/KeyboardVisibilityDetector.java Просмотреть файл

@@ -1,6 +1,5 @@
1 1
 package com.reactnativenavigation.utils;
2 2
 
3
-import android.app.Activity;
4 3
 import android.content.Context;
5 4
 import android.graphics.Rect;
6 5
 import android.view.View;
@@ -28,14 +27,9 @@ public class KeyboardVisibilityDetector {
28 27
     }
29 28
 
30 29
     public void closeKeyboard(Runnable keyboardClosedListener) {
31
-        Activity context = (Activity) screen.getContext();
32
-        View view = context.getCurrentFocus();
33
-        if (view != null) {
34
-            this.keyboardCloseListener = keyboardClosedListener;
35
-
36
-            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
37
-            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
38
-        }
30
+        this.keyboardCloseListener = keyboardClosedListener;
31
+        InputMethodManager imm = (InputMethodManager) screen.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
32
+        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
39 33
     }
40 34
 
41 35
     private static class KeyboardVisibilityLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {