Browse Source

Remove keyboard listener once it's called

Guy Carmeli 8 years ago
parent
commit
9ccdd124ed

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java View File

@@ -111,12 +111,14 @@ public class ScreenStack {
111 111
         final Screen previous = stack.peek();
112 112
 
113 113
         if (keyboardVisibilityDetector.isKeyboardVisible()) {
114
-            keyboardVisibilityDetector.closeKeyboard(new Runnable() {
114
+            keyboardVisibilityDetector.setKeyboardCloseListener(new Runnable() {
115 115
                 @Override
116 116
                 public void run() {
117
+                    keyboardVisibilityDetector.setKeyboardCloseListener(null);
117 118
                     swapScreens(animated, toRemove, previous, onScreenPop);
118 119
                 }
119 120
             });
121
+            keyboardVisibilityDetector.closeKeyboard();
120 122
         } else {
121 123
             swapScreens(animated, toRemove, previous, onScreenPop);
122 124
         }

+ 5
- 2
android/app/src/main/java/com/reactnativenavigation/utils/KeyboardVisibilityDetector.java View File

@@ -26,8 +26,11 @@ public class KeyboardVisibilityDetector {
26 26
         return keyboardVisibilityListener.isKeyboardVisible();
27 27
     }
28 28
 
29
-    public void closeKeyboard(Runnable keyboardClosedListener) {
30
-        this.keyboardCloseListener = keyboardClosedListener;
29
+    public void setKeyboardCloseListener(Runnable keyboardCloseListener) {
30
+        this.keyboardCloseListener = keyboardCloseListener;
31
+    }
32
+
33
+    public void closeKeyboard() {
31 34
         InputMethodManager imm = (InputMethodManager) screen.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
32 35
         imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
33 36
     }