소스 검색

Merge branch 'dismissKeyBoardExperimental'

Guy Carmeli 9 년 전
부모
커밋
262b7f818e

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

9
 import com.reactnativenavigation.activities.BaseReactActivity;
9
 import com.reactnativenavigation.activities.BaseReactActivity;
10
 import com.reactnativenavigation.core.objects.Screen;
10
 import com.reactnativenavigation.core.objects.Screen;
11
 import com.reactnativenavigation.utils.BridgeUtils;
11
 import com.reactnativenavigation.utils.BridgeUtils;
12
+import com.reactnativenavigation.utils.ReflectionUtils;
12
 
13
 
13
 /**
14
 /**
14
  * Created by guyc on 10/03/16.
15
  * Created by guyc on 10/03/16.
24
         /**
25
         /**
25
          * This method will be invoked when the {@link ReactRootView} is visible.
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
     @SuppressWarnings("unchecked")
31
     @SuppressWarnings("unchecked")
67
 
60
 
68
         addView(mReactRootView);
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 파일 보기

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