Ver código fonte

ReactViewHacks + RctView terminated

Guy Carmeli 8 anos atrás
pai
commit
3c29a11968

+ 18
- 0
android/app/src/main/java/com/reactnativenavigation/react/ReactViewHacks.java Ver arquivo

@@ -0,0 +1,18 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import com.facebook.react.ReactRootView;
4
+import com.reactnativenavigation.utils.ReflectionUtils;
5
+
6
+public class ReactViewHacks {
7
+
8
+    public static void preventUnmountOnDetachedFromWindow(ReactRootView view) {
9
+        ReflectionUtils.setField(view, "mAttachScheduled", true);
10
+    }
11
+
12
+    public static void ensureUnmountOnDetachedFromWindow(ReactRootView view) {
13
+        // Must be called before view is removed from screen inorder to ensure onDetachedFromScreen is properly
14
+        // executed and componentWillUnmount is called
15
+        ReflectionUtils.setField(view, "mAttachScheduled", false);
16
+    }
17
+
18
+}

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java Ver arquivo

@@ -2,9 +2,11 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.os.Bundle;
5
+import android.view.ViewGroup;
5 6
 
6 7
 import com.facebook.react.ReactInstanceManager;
7 8
 import com.facebook.react.ReactRootView;
9
+import com.reactnativenavigation.react.ReactViewHacks;
8 10
 
9 11
 public class ContentView extends ReactRootView implements ScrollDirectionListener.OnChanged {
10 12
 
@@ -20,4 +22,16 @@ public class ContentView extends ReactRootView implements ScrollDirectionListene
20 22
     public void onScrollChanged(ScrollDirectionListener.Direction direction) {
21 23
 
22 24
     }
25
+
26
+    public void removeFromParentWithoutUnmount() {
27
+        // Hack in order to prevent the react view from getting unmounted
28
+        ReactViewHacks.preventUnmountOnDetachedFromWindow(this);
29
+        ((ViewGroup) getParent()).removeView(this);
30
+    }
31
+
32
+    public void removeFromParentAndUnmount() {
33
+        ReactViewHacks.ensureUnmountOnDetachedFromWindow(this);
34
+        ((ViewGroup) getParent()).removeView(this);
35
+    }
36
+
23 37
 }

+ 21
- 51
android/app/src/main/java/com/reactnativenavigation/views/RctView.java Ver arquivo

@@ -121,56 +121,26 @@ public class RctView extends FrameLayout {
121 121
         return passProps;
122 122
     }
123 123
 
124
-    private void setupScrollViewWithBottomTabs() {
125
-        scrollView = getScrollView((ViewGroup) getParent());
126
-        if (scrollView != null) {
127
-            context = (BottomTabActivity) getContext();
128
-            attachStateChangeListener(scrollView);
129
-            addScrollListener();
130
-        }
131
-    }
132
-
133
-
134
-    private void attachStateChangeListener(ScrollView scrollView) {
135
-        scrollView.addOnAttachStateChangeListener(stateChangeListener);
136
-    }
137
-
138
-    private void addScrollListener() {
139
-        scrollView.getViewTreeObserver().addOnScrollChangedListener(scrollChangedListener);
140
-    }
141
-
142
-    private void removeScrollListener() {
143
-        scrollView.getViewTreeObserver().removeOnScrollChangedListener(scrollChangedListener);
144
-    }
145
-
146
-    /**
147
-     * Must be called before view is removed from screen, but will be added again later. Setting mAttachScheduled
148
-     * to true will prevent the component from getting unmounted once view is detached from screen.
149
-     */
150
-    public void onTemporallyRemovedFromScreen() {
151
-        // Hack in order to prevent the react view from getting unmounted
152
-
153
-        ReflectionUtils.setField(reactRootView, "mAttachScheduled", true);
154
-    }
155
-
156
-    /**
157
-     * Must be called before view is removed from screen inorder to ensure onDetachedFromScreen is properly
158
-     * executed and componentWillUnmount is called
159
-     */
160
-    public void onRemoveFromScreen() {
161
-        ReflectionUtils.setField(reactRootView, "mAttachScheduled", false);
162
-    }
163
-
164
-    /**
165
-     * Must be called when view is added again to screen inorder to ensure onDetachedFromScreen is properly
166
-     * executed and componentWillUnmount is called
167
-     */
168
-    public void onReAddToScreen() {
169
-        ReflectionUtils.setField(reactRootView, "mAttachScheduled", false);
170
-    }
171
-
172
-    public void detachFromScreen() {
173
-        ReflectionUtils.invoke(reactRootView, "onDetachedFromWindow");
174
-    }
124
+//    private void setupScrollViewWithBottomTabs() {
125
+//        scrollView = getScrollView((ViewGroup) getParent());
126
+//        if (scrollView != null) {
127
+//            context = (BottomTabActivity) getContext();
128
+//            attachStateChangeListener(scrollView);
129
+//            addScrollListener();
130
+//        }
131
+//    }
132
+
133
+
134
+//    private void attachStateChangeListener(ScrollView scrollView) {
135
+//        scrollView.addOnAttachStateChangeListener(stateChangeListener);
136
+//    }
137
+//
138
+//    private void addScrollListener() {
139
+//        scrollView.getViewTreeObserver().addOnScrollChangedListener(scrollChangedListener);
140
+//    }
141
+//
142
+//    private void removeScrollListener() {
143
+//        scrollView.getViewTreeObserver().removeOnScrollChangedListener(scrollChangedListener);
144
+//    }
175 145
 }
176 146