Browse Source

Merge branch 'dismissKeyBoardExperimental'

Guy Carmeli 8 years ago
parent
commit
262b7f818e

+ 27
- 9
android/app/src/main/java/com/reactnativenavigation/views/RctView.java View File

@@ -9,6 +9,7 @@ import com.facebook.react.ReactRootView;
9 9
 import com.reactnativenavigation.activities.BaseReactActivity;
10 10
 import com.reactnativenavigation.core.objects.Screen;
11 11
 import com.reactnativenavigation.utils.BridgeUtils;
12
+import com.reactnativenavigation.utils.ReflectionUtils;
12 13
 
13 14
 /**
14 15
  * Created by guyc on 10/03/16.
@@ -24,15 +25,7 @@ public class RctView extends FrameLayout {
24 25
         /**
25 26
          * This method will be invoked when the {@link ReactRootView} is visible.
26 27
          */
27
-        public void onDisplayed();
28
-    }
29
-
30
-    public ReactRootView getReactRootView() {
31
-        return mReactRootView;
32
-    }
33
-
34
-    public RctView(BaseReactActivity ctx, ReactInstanceManager rctInstanceManager, Screen screen) {
35
-        this(ctx, rctInstanceManager, screen, null);
28
+        void onDisplayed();
36 29
     }
37 30
 
38 31
     @SuppressWarnings("unchecked")
@@ -67,5 +60,30 @@ public class RctView extends FrameLayout {
67 60
 
68 61
         addView(mReactRootView);
69 62
     }
63
+
64
+    /**
65
+     * Must be called before view is removed from screen, but will be added again later. Setting mAttachScheduled
66
+     * to true will prevent the component from getting unmounted once view is detached from screen.
67
+     */
68
+    public void onTemporallyRemovedFromScreen() {
69
+        // Hack in order to prevent the react view from getting unmounted
70
+        ReflectionUtils.setBooleanField(mReactRootView, "mAttachScheduled", true);
71
+    }
72
+
73
+    /**
74
+     * Must be called before view is removed from screen inorder to ensure onDetachedFromScreen is properly
75
+     * executed and componentWillUnmount is called
76
+     */
77
+    public void onRemoveFromScreen() {
78
+        ReflectionUtils.setBooleanField(mReactRootView, "mAttachScheduled", false);
79
+    }
80
+
81
+    /**
82
+     * Must be called when view is added again to screen inorder to ensure onDetachedFromScreen is properly
83
+     * executed and componentWillUnmount is called
84
+     */
85
+    public void onReAddToScreen() {
86
+        ReflectionUtils.setBooleanField(mReactRootView, "mAttachScheduled", false);
87
+    }
70 88
 }
71 89
 

+ 13
- 14
android/app/src/main/java/com/reactnativenavigation/views/ScreenStack.java View File

@@ -7,11 +7,9 @@ import android.view.ViewGroup;
7 7
 import android.widget.FrameLayout;
8 8
 
9 9
 import com.facebook.react.ReactInstanceManager;
10
-import com.facebook.react.ReactRootView;
11 10
 import com.reactnativenavigation.activities.BaseReactActivity;
12 11
 import com.reactnativenavigation.core.RctManager;
13 12
 import com.reactnativenavigation.core.objects.Screen;
14
-import com.reactnativenavigation.utils.ReflectionUtils;
15 13
 
16 14
 import java.util.Stack;
17 15
 
@@ -60,7 +58,7 @@ public class ScreenStack extends FrameLayout {
60 58
         if (oldView != null) {
61 59
             addView(view, MATCH_PARENT, MATCH_PARENT);
62 60
 
63
-            ReflectionUtils.setBooleanField(oldView.getReactRootView(), "mAttachScheduled", true);
61
+            oldView.onTemporallyRemovedFromScreen();
64 62
             getLayoutTransition().setStartDelay(LayoutTransition.DISAPPEARING, DISAPPEAR_ANIMATION_DELAY);
65 63
             removeView(oldView);
66 64
             getLayoutTransition().setStartDelay(LayoutTransition.DISAPPEARING, 0);
@@ -76,9 +74,12 @@ public class ScreenStack extends FrameLayout {
76 74
         }
77 75
 
78 76
         ScreenView popped = mStack.pop();
79
-        addView(mStack.peek().view, 0);
80 77
 
81
-        ReflectionUtils.setBooleanField(popped.view.getReactRootView(), "mAttachScheduled", false);
78
+        RctView newView = mStack.peek().view;
79
+        addView(newView);
80
+        newView.onReAddToScreen();
81
+
82
+        popped.view.onRemoveFromScreen();
82 83
         removeView(popped.view);
83 84
         return popped.screen;
84 85
     }
@@ -91,7 +92,7 @@ public class ScreenStack extends FrameLayout {
91 92
         ScreenView oldScreenView = null;
92 93
         while (getStackSize() > 1) {
93 94
             ScreenView popped = mStack.pop();
94
-            ReflectionUtils.setBooleanField(popped.view.getReactRootView(), "mAttachScheduled", false);
95
+            popped.view.onRemoveFromScreen();
95 96
             removeView(popped.view);
96 97
             if (oldScreenView == null) {
97 98
                 oldScreenView = popped;
@@ -116,11 +117,11 @@ public class ScreenStack extends FrameLayout {
116 117
         ScreenView oldScreenView = null;
117 118
         if (!mStack.isEmpty()) {
118 119
             while (getStackSize() > 0) {
119
-                ScreenView screenView = mStack.pop();
120
-                ReflectionUtils.setBooleanField(screenView.view.getReactRootView(), "mAttachScheduled", false);
121
-                removeView(screenView.view);
120
+                ScreenView popped = mStack.pop();
121
+                popped.view.onRemoveFromScreen();
122
+                removeView(popped.view);
122 123
                 if (oldScreenView == null) {
123
-                    oldScreenView = screenView;
124
+                    oldScreenView = popped;
124 125
                 }
125 126
             }
126 127
         }
@@ -151,8 +152,7 @@ public class ScreenStack extends FrameLayout {
151 152
      * Remove the ScreenStack from {@code parent} while preventing all child react views from getting unmounted
152 153
      */
153 154
     public void removeFromScreen(ViewGroup parent) {
154
-        ReactRootView view = mStack.peek().view.getReactRootView();
155
-        ReflectionUtils.setBooleanField(view, "mAttachScheduled", true);
155
+        mStack.peek().view.onTemporallyRemovedFromScreen();
156 156
 
157 157
         parent.removeView(this);
158 158
     }
@@ -161,8 +161,7 @@ public class ScreenStack extends FrameLayout {
161 161
      * Add ScreenStack to {@code parent}
162 162
      */
163 163
     public void addToScreen(ViewGroup parent) {
164
-        ReactRootView view = mStack.peek().view.getReactRootView();
165
-        ReflectionUtils.setBooleanField(view, "mAttachScheduled", false);
164
+        mStack.peek().view.onReAddToScreen();
166 165
 
167 166
         parent.addView(this, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
168 167
     }