|
@@ -1,6 +1,9 @@
|
1
|
1
|
package com.reactnativenavigation.views.collapsingToolbar;
|
2
|
2
|
|
3
|
3
|
import android.content.Context;
|
|
4
|
+import android.graphics.Color;
|
|
5
|
+import android.graphics.drawable.ColorDrawable;
|
|
6
|
+import android.graphics.drawable.Drawable;
|
4
|
7
|
import android.view.MotionEvent;
|
5
|
8
|
import android.view.View;
|
6
|
9
|
|
|
@@ -9,7 +12,7 @@ import com.reactnativenavigation.params.StyleParams;
|
9
|
12
|
import com.reactnativenavigation.utils.ViewUtils;
|
10
|
13
|
import com.reactnativenavigation.views.TitleBar;
|
11
|
14
|
import com.reactnativenavigation.views.TitleBarBackground;
|
12
|
|
-import com.reactnativenavigation.views.TranslucentTitleBarBackground;
|
|
15
|
+import com.reactnativenavigation.views.TranslucentDrawable;
|
13
|
16
|
|
14
|
17
|
public class CollapsingTitleBar extends TitleBar implements View.OnTouchListener {
|
15
|
18
|
private CollapsingTextView title;
|
|
@@ -25,26 +28,32 @@ public class CollapsingTitleBar extends TitleBar implements View.OnTouchListener
|
25
|
28
|
this.params = params;
|
26
|
29
|
addCollapsingTitle();
|
27
|
30
|
setOnTouchListener(this);
|
28
|
|
- hideTitle(params);
|
|
31
|
+ setInitialTitleViewVisibility();
|
29
|
32
|
}
|
30
|
33
|
|
31
|
|
- private void hideTitle(CollapsingTopBarParams params) {
|
32
|
|
- if (params.showTitleWhenCollapsed) {
|
33
|
|
- ViewUtils.runOnPreDraw(this, new Runnable() {
|
34
|
|
- @Override
|
35
|
|
- public void run() {
|
36
|
|
- View titleView = getTitleView();
|
37
|
|
- if (titleView != null) {
|
38
|
|
- titleView.setAlpha(0);
|
39
|
|
- }
|
|
34
|
+ private void setInitialTitleViewVisibility() {
|
|
35
|
+ ViewUtils.runOnPreDraw(this, new Runnable() {
|
|
36
|
+ @Override
|
|
37
|
+ public void run() {
|
|
38
|
+ View titleView = getTitleView();
|
|
39
|
+ if (titleView == null) {
|
|
40
|
+ return;
|
40
|
41
|
}
|
41
|
|
- });
|
42
|
|
- }
|
|
42
|
+ if (params.showTitleWhenExpended) {
|
|
43
|
+ titleView.setAlpha(1);
|
|
44
|
+ } else if (params.showTitleWhenCollapsed) {
|
|
45
|
+ titleView.setAlpha(0);
|
|
46
|
+ }
|
|
47
|
+ }
|
|
48
|
+ });
|
|
49
|
+
|
43
|
50
|
}
|
44
|
51
|
|
45
|
52
|
@Override
|
46
|
53
|
public void hideTitle() {
|
47
|
|
- super.hideTitle();
|
|
54
|
+ if (!params.showTitleWhenExpended) {
|
|
55
|
+ super.hideTitle();
|
|
56
|
+ }
|
48
|
57
|
titleBarBackground.showTranslucentBackground();
|
49
|
58
|
}
|
50
|
59
|
|
|
@@ -88,18 +97,16 @@ public class CollapsingTitleBar extends TitleBar implements View.OnTouchListener
|
88
|
97
|
|
89
|
98
|
@Override
|
90
|
99
|
protected void setBackground(StyleParams params) {
|
91
|
|
- titleBarBackground = createBackground(params);
|
|
100
|
+ titleBarBackground = createBackground(params,
|
|
101
|
+ params.collapsingTopBarParams.expendedTitleBarColor,
|
|
102
|
+ params.collapsingTopBarParams.scrimColor);
|
92
|
103
|
setBackground(titleBarBackground);
|
93
|
104
|
}
|
94
|
105
|
|
95
|
|
- private TitleBarBackground createBackground(StyleParams params) {
|
96
|
|
- return hasTranslucentAndSolidBackground(params) ?
|
97
|
|
- new TitleBarBackground(params.collapsingTopBarParams.scrimColor) :
|
98
|
|
- new TranslucentTitleBarBackground();
|
99
|
|
- }
|
100
|
|
-
|
101
|
|
- private boolean hasTranslucentAndSolidBackground(StyleParams params) {
|
102
|
|
- return params.topBarTranslucent && params.collapsingTopBarParams.scrimColor.hasColor();
|
|
106
|
+ private TitleBarBackground createBackground(StyleParams styleParams, StyleParams.Color expendedColor, StyleParams.Color collapsedColor) {
|
|
107
|
+ final Drawable expendedDrawable = styleParams.topBarTranslucent ? new TranslucentDrawable() : new ColorDrawable(expendedColor.getColor(Color.TRANSPARENT));
|
|
108
|
+ final Drawable collapsedDrawable = new ColorDrawable(collapsedColor.getColor(Color.TRANSPARENT));
|
|
109
|
+ return new TitleBarBackground(expendedDrawable, collapsedDrawable);
|
103
|
110
|
}
|
104
|
111
|
|
105
|
112
|
public void collapse(CollapseAmount amount) {
|