瀏覽代碼

Merge pull request #288 from wix/remove_react_hacks

Remove react hacks
DanielZlotin 8 年之前
父節點
當前提交
2fd52b27f3

+ 0
- 26
android/app/src/main/java/com/reactnativenavigation/react/ReactViewHacks.java 查看文件

@@ -1,26 +0,0 @@
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
-    /**
13
-     * Side effect: prevents JS components constructor from being called
14
-     */
15
-    public static void ensureUnmountOnDetachedFromWindow(ReactRootView view) {
16
-        ReflectionUtils.setField(view, "mAttachScheduled", false);
17
-    }
18
-
19
-    /**
20
-     * Side effect: ensures unmount will be called
21
-     */
22
-    public static void preventMountAfterReattachedToWindow(ReactRootView view) {
23
-        ReflectionUtils.setField(view, "mAttachScheduled", false);
24
-    }
25
-
26
-}

+ 1
- 11
android/app/src/main/java/com/reactnativenavigation/screens/FragmentScreen.java 查看文件

@@ -109,17 +109,7 @@ public class FragmentScreen extends Screen {
109 109
     }
110 110
 
111 111
     @Override
112
-    public void ensureUnmountOnDetachedFromWindow() {
113
-        // nothing
114
-    }
115
-
116
-    @Override
117
-    public void preventUnmountOnDetachedFromWindow() {
118
-        // nothing
119
-    }
120
-
121
-    @Override
122
-    public void preventMountAfterReattachedToWindow() {
112
+    public void unmountOnDetachedFromWindow() {
123 113
         // nothing
124 114
     }
125 115
 

+ 1
- 5
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java 查看文件

@@ -122,11 +122,7 @@ public abstract class Screen extends RelativeLayout {
122 122
         }
123 123
     }
124 124
 
125
-    public abstract void ensureUnmountOnDetachedFromWindow();
126
-
127
-    public abstract void preventUnmountOnDetachedFromWindow();
128
-
129
-    public abstract void preventMountAfterReattachedToWindow();
125
+    public abstract void unmountOnDetachedFromWindow();
130 126
 
131 127
     public String getScreenInstanceId() {
132 128
         return screenParams.getScreenInstanceId();

+ 4
- 10
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java 查看文件

@@ -87,7 +87,7 @@ public class ScreenStack {
87 87
                 nextScreen.show(nextScreen.screenParams.animateScreenTransitions, new Runnable() {
88 88
                     @Override
89 89
                     public void run() {
90
-                        removePreviousWithoutUnmount(previousScreen);
90
+                        parent.removeView(previousScreen);
91 91
                     }
92 92
                 });
93 93
             }
@@ -97,7 +97,7 @@ public class ScreenStack {
97 97
     private void pushScreenToInvisibleStack(LayoutParams layoutParams, Screen nextScreen, Screen previousScreen) {
98 98
         nextScreen.setVisibility(View.INVISIBLE);
99 99
         addScreen(nextScreen, layoutParams);
100
-        removePreviousWithoutUnmount(previousScreen);
100
+        parent.removeView(previousScreen);
101 101
     }
102 102
 
103 103
     private void addScreen(Screen screen, LayoutParams layoutParams) {
@@ -109,11 +109,6 @@ public class ScreenStack {
109 109
         parent.addView(screen, parent.getChildCount() - 1, layoutParams);
110 110
     }
111 111
 
112
-    private void removePreviousWithoutUnmount(Screen previous) {
113
-        previous.preventUnmountOnDetachedFromWindow();
114
-        parent.removeView(previous);
115
-    }
116
-
117 112
     public void pop(boolean animated) {
118 113
         pop(animated, null);
119 114
     }
@@ -146,7 +141,7 @@ public class ScreenStack {
146 141
         toRemove.hide(animated, new Runnable() {
147 142
             @Override
148 143
             public void run() {
149
-                toRemove.ensureUnmountOnDetachedFromWindow();
144
+                toRemove.unmountOnDetachedFromWindow();
150 145
                 parent.removeView(toRemove);
151 146
             }
152 147
         });
@@ -163,7 +158,6 @@ public class ScreenStack {
163 158
     private void readdPrevious(Screen previous) {
164 159
         previous.setVisibility(View.VISIBLE);
165 160
         parent.addView(previous, 0);
166
-        previous.preventMountAfterReattachedToWindow();
167 161
     }
168 162
 
169 163
     public void popToRoot(boolean animated) {
@@ -174,7 +168,7 @@ public class ScreenStack {
174 168
 
175 169
     public void destroy() {
176 170
         for (Screen screen : stack) {
177
-            screen.ensureUnmountOnDetachedFromWindow();
171
+            screen.unmountOnDetachedFromWindow();
178 172
             parent.removeView(screen);
179 173
         }
180 174
         stack.clear();

+ 2
- 12
android/app/src/main/java/com/reactnativenavigation/screens/SingleScreen.java 查看文件

@@ -28,18 +28,8 @@ public class SingleScreen extends Screen {
28 28
     }
29 29
 
30 30
     @Override
31
-    public void ensureUnmountOnDetachedFromWindow() {
32
-        contentView.ensureUnmountOnDetachedFromWindow();
33
-    }
34
-
35
-    @Override
36
-    public void preventUnmountOnDetachedFromWindow() {
37
-        contentView.preventUnmountOnDetachedFromWindow();
38
-    }
39
-
40
-    @Override
41
-    public void preventMountAfterReattachedToWindow() {
42
-        contentView.preventMountAfterReattachedToWindow();
31
+    public void unmountOnDetachedFromWindow() {
32
+        contentView.unmountOnDetachedFromWindow();
43 33
     }
44 34
 
45 35
     @Override

+ 2
- 16
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java 查看文件

@@ -64,23 +64,9 @@ public class ViewPagerScreen extends Screen {
64 64
     }
65 65
 
66 66
     @Override
67
-    public void ensureUnmountOnDetachedFromWindow() {
67
+    public void unmountOnDetachedFromWindow() {
68 68
         for (ContentView contentView : contentViews) {
69
-            contentView.ensureUnmountOnDetachedFromWindow();
70
-        }
71
-    }
72
-
73
-    @Override
74
-    public void preventUnmountOnDetachedFromWindow() {
75
-        for (ContentView contentView : contentViews) {
76
-            contentView.preventUnmountOnDetachedFromWindow();
77
-        }
78
-    }
79
-
80
-    @Override
81
-    public void preventMountAfterReattachedToWindow() {
82
-        for (ContentView contentView : contentViews) {
83
-            contentView.preventMountAfterReattachedToWindow();
69
+            contentView.unmountOnDetachedFromWindow();
84 70
         }
85 71
     }
86 72
 

+ 2
- 11
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java 查看文件

@@ -6,7 +6,6 @@ import android.view.View;
6 6
 import com.facebook.react.ReactRootView;
7 7
 import com.reactnativenavigation.NavigationApplication;
8 8
 import com.reactnativenavigation.params.NavigationParams;
9
-import com.reactnativenavigation.react.ReactViewHacks;
10 9
 import com.reactnativenavigation.screens.SingleScreen;
11 10
 import com.reactnativenavigation.utils.ViewUtils;
12 11
 
@@ -29,16 +28,8 @@ public class ContentView extends ReactRootView {
29 28
         return navigationParams.navigatorEventId;
30 29
     }
31 30
 
32
-    public void preventUnmountOnDetachedFromWindow() {
33
-        ReactViewHacks.preventUnmountOnDetachedFromWindow(this);
34
-    }
35
-
36
-    public void ensureUnmountOnDetachedFromWindow() {
37
-        ReactViewHacks.ensureUnmountOnDetachedFromWindow(this);
38
-    }
39
-
40
-    public void preventMountAfterReattachedToWindow() {
41
-        ReactViewHacks.preventMountAfterReattachedToWindow(this);
31
+    public void unmountOnDetachedFromWindow() {
32
+        unmountReactApplication();
42 33
     }
43 34
 
44 35
     @Override

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/views/SideMenu.java 查看文件

@@ -19,7 +19,7 @@ public class SideMenu extends DrawerLayout {
19 19
     }
20 20
 
21 21
     public void destroy() {
22
-        sideMenuView.ensureUnmountOnDetachedFromWindow();
22
+        sideMenuView.unmountOnDetachedFromWindow();
23 23
         removeView(sideMenuView);
24 24
     }
25 25