|
@@ -1,50 +1,44 @@
|
1
|
1
|
package com.reactnativenavigation.screens;
|
2
|
2
|
|
3
|
3
|
import android.support.v7.app.AppCompatActivity;
|
4
|
|
-import android.view.ViewManager;
|
5
|
|
-import android.widget.FrameLayout;
|
|
4
|
+import android.view.View;
|
|
5
|
+import android.widget.RelativeLayout;
|
6
|
6
|
|
7
|
7
|
import com.reactnativenavigation.params.ScreenParams;
|
8
|
8
|
import com.reactnativenavigation.params.StyleParams;
|
9
|
9
|
import com.reactnativenavigation.params.TitleBarButtonParams;
|
10
|
10
|
import com.reactnativenavigation.params.TitleBarLeftButtonParams;
|
11
|
11
|
import com.reactnativenavigation.utils.Task;
|
12
|
|
-import com.reactnativenavigation.utils.ViewUtils;
|
13
|
12
|
import com.reactnativenavigation.views.TitleBarBackButtonListener;
|
14
|
13
|
|
15
|
14
|
import java.util.List;
|
16
|
15
|
import java.util.Stack;
|
17
|
16
|
|
18
|
|
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
19
|
|
-
|
20
|
|
-// TODO there's really no reason for ScreenStack to extend FrameLayout. All screens can be added to parent.
|
21
|
|
-public class ScreenStack extends FrameLayout {
|
|
17
|
+public class ScreenStack {
|
22
|
18
|
|
23
|
19
|
private final AppCompatActivity activity;
|
|
20
|
+ private RelativeLayout parent;
|
24
|
21
|
private TitleBarBackButtonListener titleBarBackButtonListener;
|
25
|
22
|
private Stack<Screen> stack = new Stack<>();
|
26
|
|
- private final int bottomTabsHeight;
|
27
|
23
|
|
28
|
24
|
public ScreenStack(AppCompatActivity activity,
|
29
|
|
- ScreenParams initialScreenParams,
|
|
25
|
+ RelativeLayout parent,
|
30
|
26
|
TitleBarBackButtonListener titleBarBackButtonListener) {
|
31
|
|
- super(activity);
|
32
|
27
|
this.activity = activity;
|
|
28
|
+ this.parent = parent;
|
33
|
29
|
this.titleBarBackButtonListener = titleBarBackButtonListener;
|
34
|
|
- bottomTabsHeight = (int) ViewUtils.convertDpToPixel(56);
|
35
|
|
- pushInitialScreen(initialScreenParams);
|
36
|
30
|
}
|
37
|
31
|
|
38
|
|
- private void pushInitialScreen(ScreenParams initialScreenParams) {
|
|
32
|
+ public void pushInitialScreen(ScreenParams initialScreenParams, RelativeLayout.LayoutParams params) {
|
39
|
33
|
Screen initialScreen = ScreenFactory.create(activity, initialScreenParams, titleBarBackButtonListener);
|
40
|
|
- addScreen(initialScreen);
|
41
|
|
- initialScreen.show(initialScreenParams.animateScreenTransitions);
|
|
34
|
+ initialScreen.setVisibility(View.INVISIBLE);
|
|
35
|
+ addScreen(initialScreen, params);
|
42
|
36
|
}
|
43
|
37
|
|
44
|
|
- public void push(final ScreenParams params) {
|
|
38
|
+ public void push(final ScreenParams params, RelativeLayout.LayoutParams layoutParams) {
|
45
|
39
|
Screen nextScreen = ScreenFactory.create(activity, params, titleBarBackButtonListener);
|
46
|
40
|
final Screen previousScreen = stack.peek();
|
47
|
|
- addScreen(nextScreen);
|
|
41
|
+ addScreen(nextScreen, layoutParams);
|
48
|
42
|
nextScreen.show(params.animateScreenTransitions, new Runnable() {
|
49
|
43
|
@Override
|
50
|
44
|
public void run() {
|
|
@@ -53,19 +47,14 @@ public class ScreenStack extends FrameLayout {
|
53
|
47
|
});
|
54
|
48
|
}
|
55
|
49
|
|
56
|
|
- private void addScreen(Screen screen) {
|
57
|
|
- screen.setVisibility(INVISIBLE);
|
58
|
|
- LayoutParams params = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
59
|
|
- if (screen.screenParams.styleParams.drawScreenAboveBottomTabs) {
|
60
|
|
- params.setMargins(0, 0, 0, bottomTabsHeight);
|
61
|
|
- }
|
62
|
|
- addView(screen, params);
|
|
50
|
+ private void addScreen(Screen screen, RelativeLayout.LayoutParams layoutParams) {
|
|
51
|
+ parent.addView(screen, layoutParams);
|
63
|
52
|
stack.push(screen);
|
64
|
53
|
}
|
65
|
54
|
|
66
|
55
|
private void removePreviousWithoutUnmount(Screen previous) {
|
67
|
56
|
previous.preventUnmountOnDetachedFromWindow();
|
68
|
|
- removeView(previous);
|
|
57
|
+ parent.removeView(previous);
|
69
|
58
|
}
|
70
|
59
|
|
71
|
60
|
public void pop(boolean animated) {
|
|
@@ -81,13 +70,17 @@ public class ScreenStack extends FrameLayout {
|
81
|
70
|
@Override
|
82
|
71
|
public void run() {
|
83
|
72
|
toRemove.ensureUnmountOnDetachedFromWindow();
|
84
|
|
- removeView(toRemove);
|
|
73
|
+ parent.removeView(toRemove);
|
85
|
74
|
}
|
86
|
75
|
});
|
87
|
76
|
}
|
88
|
77
|
|
|
78
|
+ public Screen peek() {
|
|
79
|
+ return stack.peek();
|
|
80
|
+ }
|
|
81
|
+
|
89
|
82
|
private void readdPrevious(Screen previous) {
|
90
|
|
- addView(previous, 0, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
|
83
|
+ parent.addView(previous, 0);
|
91
|
84
|
previous.preventMountAfterReattachedToWindow();
|
92
|
85
|
}
|
93
|
86
|
|
|
@@ -100,17 +93,9 @@ public class ScreenStack extends FrameLayout {
|
100
|
93
|
public void destroy() {
|
101
|
94
|
for (Screen screen : stack) {
|
102
|
95
|
screen.ensureUnmountOnDetachedFromWindow();
|
103
|
|
- removeView(screen);
|
|
96
|
+ parent.removeView(screen);
|
104
|
97
|
}
|
105
|
98
|
stack.clear();
|
106
|
|
- removeFromScreen();
|
107
|
|
- }
|
108
|
|
-
|
109
|
|
- private void removeFromScreen() {
|
110
|
|
- ViewManager parent = (ViewManager) getParent();
|
111
|
|
- if (parent != null) {
|
112
|
|
- parent.removeView(this);
|
113
|
|
- }
|
114
|
99
|
}
|
115
|
100
|
|
116
|
101
|
public int getStackSize() {
|
|
@@ -173,4 +158,12 @@ public class ScreenStack extends FrameLayout {
|
173
|
158
|
}
|
174
|
159
|
}
|
175
|
160
|
}
|
|
161
|
+
|
|
162
|
+ public void showScreen() {
|
|
163
|
+ stack.peek().setVisibility(View.VISIBLE);
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ public void hideScreen() {
|
|
167
|
+ stack.peek().setVisibility(View.INVISIBLE);
|
|
168
|
+ }
|
176
|
169
|
}
|