|
@@ -1,25 +1,32 @@
|
1
|
1
|
package com.reactnativenavigation.views.collapsingToolbar;
|
2
|
2
|
|
3
|
3
|
import android.content.Context;
|
|
4
|
+import android.content.res.TypedArray;
|
|
5
|
+import android.os.Bundle;
|
4
|
6
|
import android.view.View;
|
5
|
7
|
import android.widget.ScrollView;
|
6
|
8
|
|
7
|
9
|
import com.reactnativenavigation.params.CollapsingTopBarParams;
|
|
10
|
+import com.reactnativenavigation.params.NavigationParams;
|
8
|
11
|
import com.reactnativenavigation.utils.ViewUtils;
|
9
|
12
|
import com.reactnativenavigation.views.TitleBar;
|
10
|
13
|
import com.reactnativenavigation.views.TopBar;
|
11
|
14
|
|
12
|
15
|
public class CollapsingTopBar extends TopBar implements CollapsingView {
|
13
|
16
|
private CollapsingTopBarBackground collapsingTopBarBackground;
|
|
17
|
+ private CollapsingTopBarReactView headerView;
|
14
|
18
|
private ScrollListener scrollListener;
|
15
|
19
|
private float finalCollapsedTranslation;
|
16
|
20
|
private CollapsingTopBarParams params;
|
17
|
21
|
private final ViewCollapser viewCollapser;
|
|
22
|
+ private final int topBarHeight;
|
18
|
23
|
|
19
|
24
|
public CollapsingTopBar(Context context, final CollapsingTopBarParams params) {
|
20
|
25
|
super(context);
|
21
|
26
|
this.params = params;
|
22
|
|
- createCollapsingTopBar(params);
|
|
27
|
+ topBarHeight = calculateTopBarHeight();
|
|
28
|
+ createBackgroundImage(params);
|
|
29
|
+ createReactView(params);
|
23
|
30
|
calculateFinalCollapsedTranslation(params);
|
24
|
31
|
viewCollapser = new ViewCollapser(this);
|
25
|
32
|
}
|
|
@@ -29,8 +36,7 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
|
29
|
36
|
@Override
|
30
|
37
|
public void run() {
|
31
|
38
|
if (params.hasBackgroundImage()) {
|
32
|
|
- finalCollapsedTranslation =
|
33
|
|
- getCollapsingTopBarBackground().getCollapsedTopBarHeight() - getHeight();
|
|
39
|
+ finalCollapsedTranslation = getCollapsedHeight() - getHeight();
|
34
|
40
|
} else {
|
35
|
41
|
finalCollapsedTranslation = -titleBar.getHeight();
|
36
|
42
|
}
|
|
@@ -42,7 +48,7 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
|
42
|
48
|
this.scrollListener = scrollListener;
|
43
|
49
|
}
|
44
|
50
|
|
45
|
|
- private void createCollapsingTopBar(CollapsingTopBarParams params) {
|
|
51
|
+ private void createBackgroundImage(CollapsingTopBarParams params) {
|
46
|
52
|
if (params.hasBackgroundImage()) {
|
47
|
53
|
collapsingTopBarBackground = new CollapsingTopBarBackground(getContext(), params);
|
48
|
54
|
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, (int) CollapsingTopBarBackground.MAX_HEIGHT);
|
|
@@ -50,21 +56,27 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
|
50
|
56
|
}
|
51
|
57
|
}
|
52
|
58
|
|
|
59
|
+ private void createReactView(CollapsingTopBarParams params) {
|
|
60
|
+ if (params.hasReactView()) {
|
|
61
|
+ headerView = new CollapsingTopBarReactView(getContext(),
|
|
62
|
+ params.reactViewId,
|
|
63
|
+ new NavigationParams(Bundle.EMPTY));
|
|
64
|
+ LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, (int) ViewUtils.convertDpToPixel(400));
|
|
65
|
+ titleBarAndContextualMenuContainer.addView(headerView, lp);
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+
|
53
|
69
|
@Override
|
54
|
70
|
protected TitleBar createTitleBar() {
|
55
|
71
|
if (params.hasBackgroundImage()) {
|
56
|
72
|
return new CollapsingTitleBar(getContext(),
|
57
|
|
- collapsingTopBarBackground.getCollapsedTopBarHeight(),
|
|
73
|
+ getCollapsedHeight(),
|
58
|
74
|
scrollListener);
|
59
|
75
|
} else {
|
60
|
76
|
return super.createTitleBar();
|
61
|
77
|
}
|
62
|
78
|
}
|
63
|
79
|
|
64
|
|
- public CollapsingTopBarBackground getCollapsingTopBarBackground() {
|
65
|
|
- return collapsingTopBarBackground;
|
66
|
|
- }
|
67
|
|
-
|
68
|
80
|
@Override
|
69
|
81
|
public void collapse(CollapseAmount amount) {
|
70
|
82
|
viewCollapser.collapse(amount);
|
|
@@ -87,7 +99,9 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
|
87
|
99
|
|
88
|
100
|
public int getCollapsedHeight() {
|
89
|
101
|
if (params.hasBackgroundImage()) {
|
90
|
|
- return collapsingTopBarBackground.getCollapsedTopBarHeight();
|
|
102
|
+ return topBarHeight;
|
|
103
|
+ } else if (params.hasReactView()) {
|
|
104
|
+ return topBarHeight;
|
91
|
105
|
} else if (topTabs != null) {
|
92
|
106
|
return topTabs.getHeight();
|
93
|
107
|
} else {
|
|
@@ -95,6 +109,14 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
|
95
|
109
|
}
|
96
|
110
|
}
|
97
|
111
|
|
|
112
|
+ private int calculateTopBarHeight() {
|
|
113
|
+ int[] attrs = new int[] {android.R.attr.actionBarSize};
|
|
114
|
+ TypedArray ta = getContext().obtainStyledAttributes(attrs);
|
|
115
|
+ final int result = ta.getDimensionPixelSize(0, -1);
|
|
116
|
+ ta.recycle();
|
|
117
|
+ return result;
|
|
118
|
+ }
|
|
119
|
+
|
98
|
120
|
@Override
|
99
|
121
|
public float getCurrentCollapseValue() {
|
100
|
122
|
return getTranslationY();
|