소스 검색

Remove dismiss keyboard logic

Turns out the popping a screen while keyboard is
open has no side effects. The issue was in fact
that under some condition, when adding a screen
back after it was previously removed caused the
screens constructor to be called.

This commits prevent startReactApplication from
being called by setting mAttachScheduled flag.
Guy Carmeli 8 년 전
부모
커밋
1f88d75519

+ 7
- 17
android/app/src/main/java/com/reactnativenavigation/views/RctView.java 파일 보기

@@ -2,7 +2,6 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.os.Bundle;
4 4
 import android.view.ViewTreeObserver;
5
-import android.view.inputmethod.InputMethodManager;
6 5
 import android.widget.FrameLayout;
7 6
 
8 7
 import com.facebook.react.ReactInstanceManager;
@@ -12,8 +11,6 @@ import com.reactnativenavigation.core.objects.Screen;
12 11
 import com.reactnativenavigation.utils.BridgeUtils;
13 12
 import com.reactnativenavigation.utils.ReflectionUtils;
14 13
 
15
-import static android.content.Context.INPUT_METHOD_SERVICE;
16
-
17 14
 /**
18 15
  * Created by guyc on 10/03/16.
19 16
  */
@@ -28,7 +25,7 @@ public class RctView extends FrameLayout {
28 25
         /**
29 26
          * This method will be invoked when the {@link ReactRootView} is visible.
30 27
          */
31
-        public void onDisplayed();
28
+        void onDisplayed();
32 29
     }
33 30
 
34 31
     @SuppressWarnings("unchecked")
@@ -70,30 +67,23 @@ public class RctView extends FrameLayout {
70 67
      */
71 68
     public void onTemporallyRemovedFromScreen() {
72 69
         // Hack in order to prevent the react view from getting unmounted
73
-        ReflectionUtils.setBooleanField(this, "mAttachScheduled", true);
74
-        dismissSoftKeyBoard();
70
+        ReflectionUtils.setBooleanField(mReactRootView, "mAttachScheduled", true);
75 71
     }
76 72
 
77 73
     /**
78 74
      * Must be called before view is removed from screen inorder to ensure onDetachedFromScreen is properly
79 75
      * executed and componentWillUnmount is called
80 76
      */
81
-    public void onRemovedFromScreen() {
82
-        ReflectionUtils.setBooleanField(this, "mAttachScheduled", false);
83
-        dismissSoftKeyBoard();
84
-    }
85
-
86
-    private void dismissSoftKeyBoard() {
87
-        InputMethodManager inputManager = (InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE);
88
-        inputManager.hideSoftInputFromWindow(getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
77
+    public void onRemoveFromScreen() {
78
+        ReflectionUtils.setBooleanField(mReactRootView, "mAttachScheduled", false);
89 79
     }
90 80
 
91 81
     /**
92
-     * Must be called before view is added again to screen inorder to ensure onDetachedFromScreen is properly
82
+     * Must be called when view is added again to screen inorder to ensure onDetachedFromScreen is properly
93 83
      * executed and componentWillUnmount is called
94 84
      */
95
-    public void onReaddedToScreen() {
96
-        ReflectionUtils.setBooleanField(this, "mAttachScheduled", false);
85
+    public void onReAddToScreen() {
86
+        ReflectionUtils.setBooleanField(mReactRootView, "mAttachScheduled", false);
97 87
     }
98 88
 }
99 89
 

+ 8
- 5
android/app/src/main/java/com/reactnativenavigation/views/ScreenStack.java 파일 보기

@@ -74,9 +74,12 @@ public class ScreenStack extends FrameLayout {
74 74
         }
75 75
 
76 76
         ScreenView popped = mStack.pop();
77
-        addView(mStack.peek().view, 0);
78 77
 
79
-        popped.view.onRemovedFromScreen();
78
+        RctView newView = mStack.peek().view;
79
+        addView(newView);
80
+        newView.onReAddToScreen();
81
+
82
+        popped.view.onRemoveFromScreen();
80 83
         removeView(popped.view);
81 84
         return popped.screen;
82 85
     }
@@ -89,7 +92,7 @@ public class ScreenStack extends FrameLayout {
89 92
         ScreenView oldScreenView = null;
90 93
         while (getStackSize() > 1) {
91 94
             ScreenView popped = mStack.pop();
92
-            popped.view.onRemovedFromScreen();
95
+            popped.view.onRemoveFromScreen();
93 96
             removeView(popped.view);
94 97
             if (oldScreenView == null) {
95 98
                 oldScreenView = popped;
@@ -115,7 +118,7 @@ public class ScreenStack extends FrameLayout {
115 118
         if (!mStack.isEmpty()) {
116 119
             while (getStackSize() > 0) {
117 120
                 ScreenView popped = mStack.pop();
118
-                popped.view.onRemovedFromScreen();
121
+                popped.view.onRemoveFromScreen();
119 122
                 removeView(popped.view);
120 123
                 if (oldScreenView == null) {
121 124
                     oldScreenView = popped;
@@ -158,7 +161,7 @@ public class ScreenStack extends FrameLayout {
158 161
      * Add ScreenStack to {@code parent}
159 162
      */
160 163
     public void addToScreen(ViewGroup parent) {
161
-        mStack.peek().view.onReaddedToScreen();
164
+        mStack.peek().view.onReAddToScreen();
162 165
 
163 166
         parent.addView(this, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
164 167
     }