|
@@ -1,130 +0,0 @@
|
1
|
|
-package com.reactnativenavigation.layouts;
|
2
|
|
-
|
3
|
|
-import android.annotation.TargetApi;
|
4
|
|
-import android.app.Activity;
|
5
|
|
-import android.content.Context;
|
6
|
|
-import android.graphics.Color;
|
7
|
|
-import android.os.Build;
|
8
|
|
-import android.view.View;
|
9
|
|
-import android.view.Window;
|
10
|
|
-import android.widget.RelativeLayout;
|
11
|
|
-
|
12
|
|
-import com.reactnativenavigation.animation.OnScrollAnimator;
|
13
|
|
-import com.reactnativenavigation.params.ScreenParams;
|
14
|
|
-import com.reactnativenavigation.params.ScreenStyleParams;
|
15
|
|
-import com.reactnativenavigation.utils.SdkSupports;
|
16
|
|
-import com.reactnativenavigation.views.ContentView;
|
17
|
|
-import com.reactnativenavigation.views.ScrollDirectionListener;
|
18
|
|
-import com.reactnativenavigation.views.TopBar;
|
19
|
|
-
|
20
|
|
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
21
|
|
-import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
22
|
|
-
|
23
|
|
-public class ScreenImpl extends RelativeLayout implements Screen, ScrollDirectionListener.OnScrollChanged {
|
24
|
|
-
|
25
|
|
- private final ScreenParams screenParams;
|
26
|
|
- private ContentView contentView;
|
27
|
|
- private TopBar topBar;
|
28
|
|
- private OnScrollAnimator scrollAnimator;
|
29
|
|
-
|
30
|
|
- public ScreenImpl(Context context, ScreenParams screenParams) {
|
31
|
|
- super(context);
|
32
|
|
- this.screenParams = screenParams;
|
33
|
|
-
|
34
|
|
- createViews();
|
35
|
|
- setStyle(screenParams.styleParams);
|
36
|
|
- }
|
37
|
|
-
|
38
|
|
- private void createViews() {
|
39
|
|
- addTopBar();
|
40
|
|
- addTitleBar();
|
41
|
|
- addContentView();
|
42
|
|
- }
|
43
|
|
-
|
44
|
|
- private void addTitleBar() {
|
45
|
|
- topBar.addTitleBarAndSetButtons(screenParams.buttons, screenParams.navigatorEventId);
|
46
|
|
- topBar.setTitle(screenParams.title);
|
47
|
|
- }
|
48
|
|
-
|
49
|
|
- private void addTopBar() {
|
50
|
|
- topBar = new TopBar(getContext());
|
51
|
|
- addView(topBar, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
|
52
|
|
- }
|
53
|
|
-
|
54
|
|
- private void addContentView() {
|
55
|
|
- contentView = new ContentView(getContext(), screenParams, this);
|
56
|
|
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
57
|
|
- if (!screenParams.styleParams.drawUnderTopBar) {
|
58
|
|
- params.addRule(RelativeLayout.BELOW, topBar.getId());
|
59
|
|
- }
|
60
|
|
- addView(contentView, params);
|
61
|
|
- contentView.init();
|
62
|
|
- }
|
63
|
|
-
|
64
|
|
- private void setStyle(ScreenStyleParams styleParams) {
|
65
|
|
- setStatusBarColor(styleParams.statusBarColor);
|
66
|
|
- setTopBarColor(styleParams.topBarColor);
|
67
|
|
- setNavigationBarColor(styleParams.navigationBarColor);
|
68
|
|
- topBar.setTitleBarVisibility(styleParams.titleBarHidden);
|
69
|
|
- topBar.setVisibility(styleParams.topBarHidden ? GONE : VISIBLE);
|
70
|
|
- }
|
71
|
|
-
|
72
|
|
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
73
|
|
- private void setStatusBarColor(ScreenStyleParams.Color statusBarColor) {
|
74
|
|
- if (!SdkSupports.lollipop()) {
|
75
|
|
- return;
|
76
|
|
- }
|
77
|
|
-
|
78
|
|
- final Activity context = (Activity) getContext();
|
79
|
|
- final Window window = context.getWindow();
|
80
|
|
- if (statusBarColor.hasColor()) {
|
81
|
|
- window.setStatusBarColor(statusBarColor.getColor());
|
82
|
|
- } else {
|
83
|
|
- window.setStatusBarColor(Color.BLACK);
|
84
|
|
- }
|
85
|
|
- }
|
86
|
|
-
|
87
|
|
- private void setTopBarColor(ScreenStyleParams.Color topBarColor) {
|
88
|
|
- if (topBarColor.hasColor()) {
|
89
|
|
- topBar.setBackgroundColor(topBarColor.getColor());
|
90
|
|
- }
|
91
|
|
- }
|
92
|
|
-
|
93
|
|
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
94
|
|
- public void setNavigationBarColor(ScreenStyleParams.Color navigationBarColor) {
|
95
|
|
- if (!SdkSupports.lollipop()) {
|
96
|
|
- return;
|
97
|
|
- }
|
98
|
|
-
|
99
|
|
- final Activity context = (Activity) getContext();
|
100
|
|
- final Window window = context.getWindow();
|
101
|
|
- if (navigationBarColor.hasColor()) {
|
102
|
|
- window.setNavigationBarColor(navigationBarColor.getColor());
|
103
|
|
- } else {
|
104
|
|
- window.setNavigationBarColor(Color.BLACK);
|
105
|
|
- }
|
106
|
|
- }
|
107
|
|
-
|
108
|
|
- @Override
|
109
|
|
- public void onScrollChanged(ScrollDirectionListener.Direction direction) {
|
110
|
|
- if (scrollAnimator == null) {
|
111
|
|
- scrollAnimator = new OnScrollAnimator(topBar, OnScrollAnimator.HideDirection.Up, topBar.getHeight());
|
112
|
|
- }
|
113
|
|
- scrollAnimator.onScrollChanged(direction);
|
114
|
|
- }
|
115
|
|
-
|
116
|
|
- @Override
|
117
|
|
- public View asView() {
|
118
|
|
- return this;
|
119
|
|
- }
|
120
|
|
-
|
121
|
|
- @Override
|
122
|
|
- public void ensureUnmountOnDetachedFromWindow() {
|
123
|
|
- contentView.ensureUnmountOnDetachedFromWindow();
|
124
|
|
- }
|
125
|
|
-
|
126
|
|
- @Override
|
127
|
|
- public void preventUnmountOnDetachedFromWindow() {
|
128
|
|
- contentView.preventUnmountOnDetachedFromWindow();
|
129
|
|
- }
|
130
|
|
-}
|