|
@@ -1,5 +1,6 @@
|
1
|
1
|
package com.reactnativenavigation.screens;
|
2
|
2
|
|
|
3
|
+import android.support.annotation.Nullable;
|
3
|
4
|
import android.support.v7.app.AppCompatActivity;
|
4
|
5
|
import android.view.View;
|
5
|
6
|
import android.widget.RelativeLayout;
|
|
@@ -8,6 +9,7 @@ import com.reactnativenavigation.params.ScreenParams;
|
8
|
9
|
import com.reactnativenavigation.params.StyleParams;
|
9
|
10
|
import com.reactnativenavigation.params.TitleBarButtonParams;
|
10
|
11
|
import com.reactnativenavigation.params.TitleBarLeftButtonParams;
|
|
12
|
+import com.reactnativenavigation.utils.KeyboardVisibilityDetector;
|
11
|
13
|
import com.reactnativenavigation.utils.Task;
|
12
|
14
|
import com.reactnativenavigation.views.TitleBarBackButtonListener;
|
13
|
15
|
|
|
@@ -16,10 +18,15 @@ import java.util.Stack;
|
16
|
18
|
|
17
|
19
|
public class ScreenStack {
|
18
|
20
|
|
|
21
|
+ public interface OnScreenPop {
|
|
22
|
+ void onScreenPopAnimationEnd();
|
|
23
|
+ }
|
|
24
|
+
|
19
|
25
|
private final AppCompatActivity activity;
|
20
|
26
|
private RelativeLayout parent;
|
21
|
27
|
private TitleBarBackButtonListener titleBarBackButtonListener;
|
22
|
28
|
private Stack<Screen> stack = new Stack<>();
|
|
29
|
+ private final KeyboardVisibilityDetector keyboardVisibilityDetector;
|
23
|
30
|
|
24
|
31
|
public ScreenStack(AppCompatActivity activity,
|
25
|
32
|
RelativeLayout parent,
|
|
@@ -27,6 +34,7 @@ public class ScreenStack {
|
27
|
34
|
this.activity = activity;
|
28
|
35
|
this.parent = parent;
|
29
|
36
|
this.titleBarBackButtonListener = titleBarBackButtonListener;
|
|
37
|
+ keyboardVisibilityDetector = new KeyboardVisibilityDetector(parent);
|
30
|
38
|
}
|
31
|
39
|
|
32
|
40
|
public void pushInitialScreen(ScreenParams initialScreenParams, RelativeLayout.LayoutParams params) {
|
|
@@ -58,13 +66,30 @@ public class ScreenStack {
|
58
|
66
|
}
|
59
|
67
|
|
60
|
68
|
public void pop(boolean animated) {
|
|
69
|
+ pop(animated, null);
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ public void pop(final boolean animated, @Nullable final OnScreenPop onScreenPop) {
|
61
|
73
|
if (!canPop()) {
|
62
|
74
|
return;
|
63
|
75
|
}
|
64
|
76
|
|
65
|
77
|
final Screen toRemove = stack.pop();
|
66
|
|
- Screen previous = stack.peek();
|
|
78
|
+ final Screen previous = stack.peek();
|
|
79
|
+
|
|
80
|
+ if (keyboardVisibilityDetector.isKeyboardVisible()) {
|
|
81
|
+ keyboardVisibilityDetector.closeKeyboard(new Runnable() {
|
|
82
|
+ @Override
|
|
83
|
+ public void run() {
|
|
84
|
+ swapScreens(animated, toRemove, previous, onScreenPop);
|
|
85
|
+ }
|
|
86
|
+ });
|
|
87
|
+ } else {
|
|
88
|
+ swapScreens(animated, toRemove, previous, onScreenPop);
|
|
89
|
+ }
|
|
90
|
+ }
|
67
|
91
|
|
|
92
|
+ private void swapScreens(boolean animated, final Screen toRemove, Screen previous, OnScreenPop onScreenPop) {
|
68
|
93
|
readdPrevious(previous);
|
69
|
94
|
toRemove.hide(animated, new Runnable() {
|
70
|
95
|
@Override
|
|
@@ -73,6 +98,10 @@ public class ScreenStack {
|
73
|
98
|
parent.removeView(toRemove);
|
74
|
99
|
}
|
75
|
100
|
});
|
|
101
|
+
|
|
102
|
+ if (onScreenPop != null) {
|
|
103
|
+ onScreenPop.onScreenPopAnimationEnd();
|
|
104
|
+ }
|
76
|
105
|
}
|
77
|
106
|
|
78
|
107
|
public Screen peek() {
|