Browse Source

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 years ago
parent
commit
1f88d75519

+ 7
- 17
android/app/src/main/java/com/reactnativenavigation/views/RctView.java View File

2
 
2
 
3
 import android.os.Bundle;
3
 import android.os.Bundle;
4
 import android.view.ViewTreeObserver;
4
 import android.view.ViewTreeObserver;
5
-import android.view.inputmethod.InputMethodManager;
6
 import android.widget.FrameLayout;
5
 import android.widget.FrameLayout;
7
 
6
 
8
 import com.facebook.react.ReactInstanceManager;
7
 import com.facebook.react.ReactInstanceManager;
12
 import com.reactnativenavigation.utils.BridgeUtils;
11
 import com.reactnativenavigation.utils.BridgeUtils;
13
 import com.reactnativenavigation.utils.ReflectionUtils;
12
 import com.reactnativenavigation.utils.ReflectionUtils;
14
 
13
 
15
-import static android.content.Context.INPUT_METHOD_SERVICE;
16
-
17
 /**
14
 /**
18
  * Created by guyc on 10/03/16.
15
  * Created by guyc on 10/03/16.
19
  */
16
  */
28
         /**
25
         /**
29
          * This method will be invoked when the {@link ReactRootView} is visible.
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
     @SuppressWarnings("unchecked")
31
     @SuppressWarnings("unchecked")
70
      */
67
      */
71
     public void onTemporallyRemovedFromScreen() {
68
     public void onTemporallyRemovedFromScreen() {
72
         // Hack in order to prevent the react view from getting unmounted
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
      * Must be called before view is removed from screen inorder to ensure onDetachedFromScreen is properly
74
      * Must be called before view is removed from screen inorder to ensure onDetachedFromScreen is properly
79
      * executed and componentWillUnmount is called
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
      * executed and componentWillUnmount is called
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 View File

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