|
@@ -12,11 +12,13 @@ import com.facebook.react.uimanager.events.EventDispatcher;
|
12
|
12
|
import com.reactnativenavigation.NavigationApplication;
|
13
|
13
|
import com.reactnativenavigation.params.CollapsingTopBarParams;
|
14
|
14
|
import com.reactnativenavigation.params.NavigationParams;
|
|
15
|
+import com.reactnativenavigation.screens.Screen;
|
15
|
16
|
import com.reactnativenavigation.utils.ViewUtils;
|
16
|
17
|
import com.reactnativenavigation.views.ContentView;
|
17
|
18
|
|
18
|
|
-public class CollapsingTopBarReactHeader extends ContentView implements CollapsingTopBarReactHeaderAnimator.OnVisibleListener, CollapsingTopBarReactHeaderAnimator.OnHiddenListener {
|
|
19
|
+public class CollapsingTopBarReactHeader extends ContentView implements CollapsingTopBarReactHeaderAnimator.OnVisibleListener, CollapsingTopBarReactHeaderAnimator.OnHiddenListener, Screen.OnDisplayListener {
|
19
|
20
|
private ScrollListener listener;
|
|
21
|
+ private Screen.OnDisplayListener onDisplayListener;
|
20
|
22
|
private boolean mIsScrolling;
|
21
|
23
|
private int mTouchSlop;
|
22
|
24
|
private int touchDown = -1;
|
|
@@ -33,19 +35,33 @@ public class CollapsingTopBarReactHeader extends ContentView implements Collapsi
|
33
|
35
|
this.onHiddenListener = onHiddenListener;
|
34
|
36
|
}
|
35
|
37
|
|
36
|
|
- public CollapsingTopBarReactHeader(Context context, CollapsingTopBarParams params, NavigationParams navigationParams, ScrollListener scrollListener) {
|
|
38
|
+ public CollapsingTopBarReactHeader(Context context, CollapsingTopBarParams params, NavigationParams navigationParams, ScrollListener scrollListener, Screen.OnDisplayListener onDisplayListener) {
|
37
|
39
|
super(context, params.reactViewId, navigationParams);
|
38
|
40
|
listener = scrollListener;
|
|
41
|
+ this.onDisplayListener = onDisplayListener;
|
39
|
42
|
ViewConfiguration vc = ViewConfiguration.get(context);
|
40
|
43
|
mTouchSlop = vc.getScaledTouchSlop();
|
41
|
|
- createVisibilityAnimator(params.reactViewHeight);
|
|
44
|
+ setViewMeasurer(new CollapsingReactHeaderMeasurer(this));
|
|
45
|
+ setOnDisplayListener(this);
|
42
|
46
|
}
|
43
|
47
|
|
44
|
|
- private void createVisibilityAnimator(int reactViewHeight) {
|
45
|
|
- float height = ViewUtils.convertDpToPixel(reactViewHeight);
|
46
|
|
- visibilityAnimator = new CollapsingTopBarReactHeaderAnimator(this, height * 0.6f, height * 0.60f);
|
47
|
|
- visibilityAnimator.setOnHiddenListener(this);
|
48
|
|
- visibilityAnimator.setOnVisibleListener(this);
|
|
48
|
+ @Override
|
|
49
|
+ public void onDisplay() {
|
|
50
|
+ createVisibilityAnimator();
|
|
51
|
+ onDisplayListener.onDisplay();
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ private void createVisibilityAnimator() {
|
|
55
|
+ ViewUtils.runOnPreDraw(this, new Runnable() {
|
|
56
|
+ @Override
|
|
57
|
+ public void run() {
|
|
58
|
+ final CollapsingTopBarReactHeader header = CollapsingTopBarReactHeader.this;
|
|
59
|
+ float height = getHeight();
|
|
60
|
+ visibilityAnimator = new CollapsingTopBarReactHeaderAnimator(header, height * 0.6f, height * 0.60f);
|
|
61
|
+ visibilityAnimator.setOnHiddenListener(header);
|
|
62
|
+ visibilityAnimator.setOnVisibleListener(header);
|
|
63
|
+ }
|
|
64
|
+ });
|
49
|
65
|
}
|
50
|
66
|
|
51
|
67
|
public void collapse(float amount) {
|