|
@@ -10,7 +10,9 @@ import com.facebook.react.uimanager.JSTouchDispatcher;
|
10
|
10
|
import com.facebook.react.uimanager.UIManagerModule;
|
11
|
11
|
import com.facebook.react.uimanager.events.EventDispatcher;
|
12
|
12
|
import com.reactnativenavigation.NavigationApplication;
|
|
13
|
+import com.reactnativenavigation.params.CollapsingTopBarParams;
|
13
|
14
|
import com.reactnativenavigation.params.NavigationParams;
|
|
15
|
+import com.reactnativenavigation.utils.ViewUtils;
|
14
|
16
|
import com.reactnativenavigation.views.ContentView;
|
15
|
17
|
|
16
|
18
|
public class CollapsingTopBarReactHeader extends ContentView {
|
|
@@ -19,12 +21,23 @@ public class CollapsingTopBarReactHeader extends ContentView {
|
19
|
21
|
private int mTouchSlop;
|
20
|
22
|
private int touchDown = -1;
|
21
|
23
|
private final JSTouchDispatcher mJSTouchDispatcher = new JSTouchDispatcher(this);
|
|
24
|
+ private CollapsingTopBarReactHeaderAnimator visibilityAnimator;
|
22
|
25
|
|
23
|
|
- public CollapsingTopBarReactHeader(Context context, String screenId, NavigationParams navigationParams, ScrollListener scrollListener) {
|
24
|
|
- super(context, screenId, navigationParams);
|
|
26
|
+ public CollapsingTopBarReactHeader(Context context, CollapsingTopBarParams params, NavigationParams navigationParams, ScrollListener scrollListener) {
|
|
27
|
+ super(context, params.reactViewId, navigationParams);
|
25
|
28
|
listener = scrollListener;
|
26
|
29
|
ViewConfiguration vc = ViewConfiguration.get(context);
|
27
|
30
|
mTouchSlop = vc.getScaledTouchSlop();
|
|
31
|
+ visibilityAnimator = createVisibilityAnimator(params.reactViewHeight);
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ private CollapsingTopBarReactHeaderAnimator createVisibilityAnimator(int reactViewHeight) {
|
|
35
|
+ float height = ViewUtils.convertDpToPixel(reactViewHeight);
|
|
36
|
+ return new CollapsingTopBarReactHeaderAnimator(this, height / 2, height / 2);
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ public void collapse(float amount) {
|
|
40
|
+ visibilityAnimator.collapse(amount);
|
28
|
41
|
}
|
29
|
42
|
|
30
|
43
|
@Override
|
|
@@ -56,17 +69,6 @@ public class CollapsingTopBarReactHeader extends ContentView {
|
56
|
69
|
return false;
|
57
|
70
|
}
|
58
|
71
|
|
59
|
|
- private void onTouchDown(MotionEvent ev) {
|
60
|
|
- if (touchDown == -1) {
|
61
|
|
- touchDown = (int) ev.getRawY();
|
62
|
|
- }
|
63
|
|
- dispatchTouchEventToJs(ev);
|
64
|
|
- }
|
65
|
|
-
|
66
|
|
- private int calculateDistanceY(MotionEvent ev) {
|
67
|
|
- return (int) Math.abs(ev.getRawY() - touchDown);
|
68
|
|
- }
|
69
|
|
-
|
70
|
72
|
@Override
|
71
|
73
|
public boolean onTouchEvent(MotionEvent ev) {
|
72
|
74
|
listener.onTouch(ev);
|
|
@@ -76,6 +78,7 @@ public class CollapsingTopBarReactHeader extends ContentView {
|
76
|
78
|
releaseScroll(ev);
|
77
|
79
|
break;
|
78
|
80
|
case MotionEvent.ACTION_MOVE:
|
|
81
|
+
|
79
|
82
|
break;
|
80
|
83
|
default:
|
81
|
84
|
break;
|
|
@@ -83,6 +86,17 @@ public class CollapsingTopBarReactHeader extends ContentView {
|
83
|
86
|
return super.onTouchEvent(ev);
|
84
|
87
|
}
|
85
|
88
|
|
|
89
|
+ private void onTouchDown(MotionEvent ev) {
|
|
90
|
+ if (touchDown == -1) {
|
|
91
|
+ touchDown = (int) ev.getRawY();
|
|
92
|
+ }
|
|
93
|
+ dispatchTouchEventToJs(ev);
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ private int calculateDistanceY(MotionEvent ev) {
|
|
97
|
+ return (int) Math.abs(ev.getRawY() - touchDown);
|
|
98
|
+ }
|
|
99
|
+
|
86
|
100
|
private void releaseScroll(MotionEvent ev) {
|
87
|
101
|
mIsScrolling = false;
|
88
|
102
|
touchDown = -1;
|