Browse Source

Destroy react views on reload

Guy Carmeli 8 years ago
parent
commit
31b8289e31

+ 3
- 2
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

@@ -29,6 +29,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
29 29
     private static Activity currentActivity;
30 30
     private ActivityParams activityParams;
31 31
     private ModalController modalController;
32
+    private SingleScreenLayout singleScreenLayout;
32 33
 
33 34
     @Override
34 35
     protected void onCreate(Bundle savedInstanceState) {
@@ -43,7 +44,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
43 44
     }
44 45
 
45 46
     private void createLayout() {
46
-        SingleScreenLayout singleScreenLayout = new SingleScreenLayout(this, activityParams.screenParams);
47
+        singleScreenLayout = new SingleScreenLayout(this, activityParams.screenParams);
47 48
         singleScreenLayout.createLayout();
48 49
         setContentView(singleScreenLayout);
49 50
     }
@@ -74,7 +75,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
74 75
 
75 76
     @Override
76 77
     public void onJsDevReload() {
77
-//        layout.removeAllReactViews();
78
+        singleScreenLayout.removeAllReactViews();
78 79
     }
79 80
 
80 81
     @Override

+ 16
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenLayout.java View File

@@ -17,7 +17,7 @@ import com.reactnativenavigation.views.ScrollDirectionListener;
17 17
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
18 18
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
19 19
 
20
-public class ScreenLayout extends LinearLayout implements ScrollDirectionListener.OnScrollChanged {
20
+public class ScreenLayout extends LinearLayout implements ScrollDirectionListener.OnScrollChanged, Layout {
21 21
 
22 22
     private final ScreenParams screenParams;
23 23
     private ContentView contentView;
@@ -102,4 +102,19 @@ public class ScreenLayout extends LinearLayout implements ScrollDirectionListene
102 102
     public void onScrollChanged(ScrollDirectionListener.Direction direction) {
103 103
 
104 104
     }
105
+
106
+    @Override
107
+    public boolean onBackPressed() {
108
+        return false;
109
+    }
110
+
111
+    @Override
112
+    public void onDestroy() {
113
+
114
+    }
115
+
116
+    @Override
117
+    public void removeAllReactViews() {
118
+        contentView.removeFromParentAndUnmount();
119
+    }
105 120
 }

+ 18
- 2
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java View File

@@ -5,9 +5,10 @@ import android.widget.FrameLayout;
5 5
 
6 6
 import com.reactnativenavigation.params.ScreenParams;
7 7
 
8
-public class SingleScreenLayout extends FrameLayout {
8
+public class SingleScreenLayout extends FrameLayout implements Layout {
9 9
 
10 10
     private final ScreenParams screenParams;
11
+    private ScreenLayout screenLayout;
11 12
 
12 13
     public SingleScreenLayout(Context context, ScreenParams screenParams) {
13 14
         super(context);
@@ -15,7 +16,22 @@ public class SingleScreenLayout extends FrameLayout {
15 16
     }
16 17
 
17 18
     public void createLayout() {
18
-        ScreenLayout screenLayout = new ScreenLayout(getContext(), screenParams);
19
+        screenLayout = new ScreenLayout(getContext(), screenParams);
19 20
         addView(screenLayout);
20 21
     }
22
+
23
+    @Override
24
+    public boolean onBackPressed() {
25
+        return false;
26
+    }
27
+
28
+    @Override
29
+    public void onDestroy() {
30
+
31
+    }
32
+
33
+    @Override
34
+    public void removeAllReactViews() {
35
+        screenLayout.removeAllReactViews();
36
+    }
21 37
 }