|
@@ -2,8 +2,6 @@ package com.reactnativenavigation.views;
|
2
|
2
|
|
3
|
3
|
import android.content.Context;
|
4
|
4
|
import android.os.Bundle;
|
5
|
|
-import android.view.View;
|
6
|
|
-import android.widget.ScrollView;
|
7
|
5
|
|
8
|
6
|
import com.facebook.react.ReactInstanceManager;
|
9
|
7
|
import com.facebook.react.ReactRootView;
|
|
@@ -15,57 +13,13 @@ public class ContentView extends ReactRootView {
|
15
|
13
|
private final String screenId;
|
16
|
14
|
private final Bundle passProps;
|
17
|
15
|
private Bundle navigationParams;
|
18
|
|
- private ScrollViewDelegate scrollViewDelegate = new ScrollViewDelegate();
|
19
|
16
|
|
20
|
|
- public ContentView(Context context, final String screenId, Bundle passProps, Bundle navigationParams, final TopBar topBar) {
|
|
17
|
+ public ContentView(Context context, final String screenId, Bundle passProps, Bundle navigationParams) {
|
21
|
18
|
super(context);
|
22
|
19
|
this.screenId = screenId;
|
23
|
20
|
this.passProps = passProps;
|
24
|
21
|
this.navigationParams = navigationParams;
|
25
|
22
|
attachToJS();
|
26
|
|
-
|
27
|
|
- scrollViewDelegate.setListener(new ScrollViewDelegate.OnScrollListener() {
|
28
|
|
-
|
29
|
|
- private ScrollDirection scrollDirectionComputer;
|
30
|
|
-
|
31
|
|
-
|
32
|
|
- @Override
|
33
|
|
- public void onScroll(ScrollView scrollView) {
|
34
|
|
- /**
|
35
|
|
- * do our magic
|
36
|
|
- */
|
37
|
|
- if (scrollDirectionComputer == null) {
|
38
|
|
- scrollDirectionComputer = new ScrollDirection(scrollView);
|
39
|
|
- }
|
40
|
|
-
|
41
|
|
- int currentTopBarTranslation = (int) topBar.getTranslationY();
|
42
|
|
- int delta = scrollDirectionComputer.getScrollDelta();
|
43
|
|
-
|
44
|
|
- int minTranslation = -topBar.getTitleBar().getHeight();
|
45
|
|
- int maxTranslation = 0;
|
46
|
|
-
|
47
|
|
- ScrollDirection.Direction direction = scrollDirectionComputer.getScrollDirection();
|
48
|
|
-
|
49
|
|
- boolean reachedMinimum = direction == ScrollDirection.Direction.Up && currentTopBarTranslation <= minTranslation;
|
50
|
|
- boolean reachedMaximum = direction == ScrollDirection.Direction.Down && currentTopBarTranslation >= maxTranslation;
|
51
|
|
-
|
52
|
|
- if (direction == ScrollDirection.Direction.None || reachedMinimum || reachedMaximum) {
|
53
|
|
- if (reachedMinimum) {
|
54
|
|
- topBar.animate().translationY(minTranslation);
|
55
|
|
- }
|
56
|
|
- if (reachedMaximum) {
|
57
|
|
- topBar.animate().translationY(maxTranslation);
|
58
|
|
- }
|
59
|
|
- } else {
|
60
|
|
-
|
61
|
|
- int target = currentTopBarTranslation - delta;
|
62
|
|
- int bound = Math.min(Math.max(minTranslation, target), maxTranslation);
|
63
|
|
-
|
64
|
|
- topBar.setTranslationY(bound);
|
65
|
|
- }
|
66
|
|
-
|
67
|
|
- }
|
68
|
|
- });
|
69
|
23
|
}
|
70
|
24
|
|
71
|
25
|
private void attachToJS() {
|
|
@@ -73,12 +27,6 @@ public class ContentView extends ReactRootView {
|
73
|
27
|
startReactApplication(react, screenId, mergePropsAndNavigationParams());
|
74
|
28
|
}
|
75
|
29
|
|
76
|
|
- @Override
|
77
|
|
- public void onViewAdded(View child) {
|
78
|
|
- super.onViewAdded(child);
|
79
|
|
- scrollViewDelegate.onViewAdded(child);
|
80
|
|
- }
|
81
|
|
-
|
82
|
30
|
private Bundle mergePropsAndNavigationParams() {
|
83
|
31
|
if (passProps != null) {
|
84
|
32
|
navigationParams.putAll(passProps);
|