Kaynağa Gözat

Revert "Fling collapsing react view screens (#1213)" (#1214)

This reverts commit a2a9324b1e.
Guy Carmeli 7 yıl önce
ebeveyn
işleme
2960e8db7f

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/screens/CollapsingSingleScreen.java Dosyayı Görüntüle

@@ -81,9 +81,9 @@ public class CollapsingSingleScreen extends SingleScreen {
81 81
                     @Override
82 82
                     public void onFling(CollapseAmount amount) {
83 83
                         if (screenParams.styleParams.drawScreenBelowTopBar) {
84
-                            ((CollapsingView) contentView).fling(amount);
84
+                            ((CollapsingView) contentView).collapse(amount);
85 85
                         }
86
-                        topBar.fling(amount);
86
+                        topBar.collapse(amount);
87 87
                     }
88 88
                 },
89 89
                 getCollapseBehaviour()

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/screens/CollapsingViewPagerScreen.java Dosyayı Görüntüle

@@ -80,8 +80,8 @@ public class CollapsingViewPagerScreen extends ViewPagerScreen {
80 80
 
81 81
                     @Override
82 82
                     public void onFling(CollapseAmount amount) {
83
-                        topBar.fling(amount);
84
-                        ((CollapsingView) viewPager).fling(amount);
83
+                        topBar.collapse(amount);
84
+                        ((CollapsingView) viewPager).collapse(amount);
85 85
                     }
86 86
                 },
87 87
                 getCollapseBehaviour()

+ 0
- 5
android/app/src/main/java/com/reactnativenavigation/views/CollapsingContentView.java Dosyayı Görüntüle

@@ -57,11 +57,6 @@ public class CollapsingContentView extends ContentView implements CollapsingView
57 57
         viewCollapser.collapse(amount);
58 58
     }
59 59
 
60
-    @Override
61
-    public void fling(CollapseAmount amount) {
62
-        viewCollapser.fling(amount);
63
-    }
64
-
65 60
     public void destroy() {
66 61
         if (scrollViewDetector != null) {
67 62
             scrollViewDetector.destroy();

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapseAmount.java Dosyayı Görüntüle

@@ -24,11 +24,11 @@ public class CollapseAmount {
24 24
         return amount != null;
25 25
     }
26 26
 
27
-    boolean collapseToTop() {
27
+    public boolean collapseToTop() {
28 28
         return direction == CollapseCalculator.Direction.Up;
29 29
     }
30 30
 
31
-    boolean collapseToBottom() {
31
+    public boolean collapseToBottom() {
32 32
         return direction == CollapseCalculator.Direction.Down;
33 33
     }
34 34
 

+ 8
- 29
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapseCalculator.java Dosyayı Görüntüle

@@ -2,7 +2,6 @@ package com.reactnativenavigation.views.collapsingToolbar;
2 2
 
3 3
 import android.support.annotation.NonNull;
4 4
 import android.support.annotation.Nullable;
5
-import android.util.Log;
6 5
 import android.view.GestureDetector;
7 6
 import android.view.MotionEvent;
8 7
 import android.view.ViewConfiguration;
@@ -13,9 +12,6 @@ import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseBeha
13 12
 import com.reactnativenavigation.views.collapsingToolbar.behaviours.TitleBarHideOnScrollBehaviour;
14 13
 
15 14
 public class CollapseCalculator {
16
-    private static final int FLING_DISTANCE_PIXELS_THRESHOLD = 100;
17
-    private static final int FLING_VELOCITY = 7000;
18
-
19 15
     public enum Direction {
20 16
         Up, Down, None
21 17
     }
@@ -36,12 +32,12 @@ public class CollapseCalculator {
36 32
     private int scrollY = 0;
37 33
     private float totalCollapse = 0;
38 34
     private float totalCollapseDeltaSinceTouchDown = 0;
39
-    private final ViewConfiguration viewConfiguration;
35
+    private final int scaledTouchSlop;
40 36
 
41 37
     public CollapseCalculator(final CollapsingView collapsingView, CollapseBehaviour collapseBehaviour) {
42 38
         this.view = collapsingView;
43 39
         this.collapseBehaviour = collapseBehaviour;
44
-        viewConfiguration = ViewConfiguration.get(NavigationApplication.instance);
40
+        scaledTouchSlop = ViewConfiguration.get(NavigationApplication.instance).getScaledTouchSlop();
45 41
         setFlingDetector();
46 42
     }
47 43
 
@@ -50,27 +46,10 @@ public class CollapseCalculator {
50 46
             flingDetector =
51 47
                     new GestureDetector(NavigationApplication.instance, new GestureDetector.SimpleOnGestureListener() {
52 48
                         @Override
53
-                        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, final float velocityY) {
49
+                        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
54 50
                             final Direction direction = getScrollDirection(e1, e2);
55
-                            final float diff = Math.abs(e2.getRawY() - e1.getRawY());
56
-                            if (Math.abs(velocityY) < viewConfiguration.getScaledMinimumFlingVelocity() ||
57
-                                diff < FLING_DISTANCE_PIXELS_THRESHOLD) {
58
-                                Log.w("FLING", "Consuming fling v: [" + velocityY + "] dy: [" + diff + "]");
59
-                                return false;
60
-                            }
61
-
62 51
                             if (canCollapse(direction) && totalCollapse != 0) {
63 52
                                 flingListener.onFling(new CollapseAmount(direction));
64
-                                if (direction == Direction.Up) {
65
-                                    scrollView.postDelayed(new Runnable() {
66
-                                        @Override
67
-                                        public void run() {
68
-                                            int max = (int) Math.max(Math.abs(velocityY), FLING_VELOCITY);
69
-                                            scrollView.fling(max);
70
-                                        }
71
-                                    }, ViewCollapser.FLING_DURATION);
72
-                                }
73
-
74 53
                                 return true;
75 54
                             }
76 55
                             return false;
@@ -97,8 +76,7 @@ public class CollapseCalculator {
97 76
     @NonNull
98 77
     CollapseAmount calculate(MotionEvent event) {
99 78
         updateInitialTouchY(event);
100
-        final boolean isFling = flingDetector.onTouchEvent(event);
101
-        CollapseAmount touchUpCollapse = shouldCollapseOnTouchUp(event, isFling);
79
+        CollapseAmount touchUpCollapse = shouldCollapseOnTouchUp(event);
102 80
         if (touchUpCollapse != CollapseAmount.None) {
103 81
             previousTouchEvent = MotionEvent.obtain(event);
104 82
             return touchUpCollapse;
@@ -119,8 +97,9 @@ public class CollapseCalculator {
119 97
         }
120 98
     }
121 99
 
122
-    private CollapseAmount shouldCollapseOnTouchUp(MotionEvent event, boolean isFling) {
123
-        if (isTouchUp(event) && collapseBehaviour.shouldCollapseOnTouchUp() && !isFling) {
100
+    private CollapseAmount shouldCollapseOnTouchUp(MotionEvent event) {
101
+        if ((collapseBehaviour.shouldCollapseOnTouchUp())
102
+            && !flingDetector.onTouchEvent(event) && isTouchUp(event)) {
124 103
             final float visibilityPercentage = view.getCurrentCollapseValue() / view.getFinalCollapseValue();
125 104
             Direction direction = visibilityPercentage >= 0.5f ? Direction.Up : Direction.Down;
126 105
             if (canCollapse(direction) && totalCollapse != 0) {
@@ -216,7 +195,7 @@ public class CollapseCalculator {
216 195
         totalCollapseDeltaSinceTouchDown += Math.abs(y - previousCollapseY);
217 196
         previousCollapseY = y;
218 197
         previousTouchEvent = MotionEvent.obtain(event);
219
-        return totalCollapseDeltaSinceTouchDown < viewConfiguration.getScaledTouchSlop() ? CollapseAmount.None : new CollapseAmount(collapse);
198
+        return totalCollapseDeltaSinceTouchDown < scaledTouchSlop ? CollapseAmount.None : new CollapseAmount(collapse);
220 199
     }
221 200
 
222 201
     private float calculateCollapse(float y) {

+ 0
- 5
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingTopBar.java Dosyayı Görüntüle

@@ -138,11 +138,6 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
138 138
         }
139 139
     }
140 140
 
141
-    @Override
142
-    public void fling(CollapseAmount amount) {
143
-        viewCollapser.fling(amount, (CollapsingTitleBar) titleBar, header);
144
-    }
145
-
146 141
     public void onScrollViewAdded(ScrollView scrollView) {
147 142
         scrollListener.onScrollViewAdded(scrollView);
148 143
     }

+ 0
- 1
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingTopBarReactHeader.java Dosyayı Görüntüle

@@ -115,7 +115,6 @@ public class CollapsingTopBarReactHeader extends ContentView implements Collapsi
115 115
     }
116 116
 
117 117
     private void onTouchDown(MotionEvent ev) {
118
-        listener.onTouch(ev);
119 118
         if (touchDown == -1) {
120 119
             touchDown = (int) ev.getRawY();
121 120
         }

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingView.java Dosyayı Görüntüle

@@ -10,6 +10,4 @@ public interface CollapsingView {
10 10
     View asView();
11 11
 
12 12
     void collapse(CollapseAmount amount);
13
-
14
-    void fling(CollapseAmount amount);
15 13
 }

+ 0
- 5
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingViewPager.java Dosyayı Görüntüle

@@ -43,9 +43,4 @@ public class CollapsingViewPager extends ViewPager implements CollapsingView {
43 43
     public void collapse(CollapseAmount amount) {
44 44
         viewCollapser.collapse(amount);
45 45
     }
46
-
47
-    @Override
48
-    public void fling(CollapseAmount amount) {
49
-        viewCollapser.fling(amount);
50
-    }
51 46
 }

+ 0
- 40
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/ViewCollapser.java Dosyayı Görüntüle

@@ -2,24 +2,12 @@ package com.reactnativenavigation.views.collapsingToolbar;
2 2
 
3 3
 import android.animation.Animator;
4 4
 import android.animation.AnimatorListenerAdapter;
5
-import android.animation.ObjectAnimator;
6
-import android.animation.ValueAnimator;
7
-import android.support.annotation.NonNull;
8
-import android.view.View;
9 5
 import android.view.ViewPropertyAnimator;
10
-import android.view.animation.DecelerateInterpolator;
11 6
 
12 7
 public class ViewCollapser {
13 8
     private static final int DURATION = 160;
14
-    public static final int FLING_DURATION = 40;
15 9
     private CollapsingView view;
16 10
     private ViewPropertyAnimator animator;
17
-    private final ValueAnimator.AnimatorUpdateListener LISTENER =
18
-            new ValueAnimator.AnimatorUpdateListener() {
19
-                @Override
20
-                public void onAnimationUpdate(ValueAnimator animation) {
21
-                }
22
-            };
23 11
 
24 12
     public ViewCollapser(CollapsingView view) {
25 13
         this.view = view;
@@ -67,32 +55,4 @@ public class ViewCollapser {
67 55
                 });
68 56
         animator.start();
69 57
     }
70
-
71
-    void fling(final CollapseAmount amount, final CollapsingTitleBar titleBar, final CollapsingTopBarReactHeader header) {
72
-        fling(amount, new ValueAnimator.AnimatorUpdateListener() {
73
-            @Override
74
-            public void onAnimationUpdate(ValueAnimator animation) {
75
-                titleBar.collapse(new CollapseAmount((Float) animation.getAnimatedValue()));
76
-                header.collapse((Float) animation.getAnimatedValue());
77
-            }
78
-        });
79
-    }
80
-
81
-    public void fling(CollapseAmount amount) {
82
-        fling(amount, LISTENER);
83
-    }
84
-
85
-    private void fling(final CollapseAmount amount, @NonNull final ValueAnimator.AnimatorUpdateListener updateListener) {
86
-        final float translation = amount.collapseToTop() ? view.getFinalCollapseValue() : 0;
87
-        ObjectAnimator animator = ObjectAnimator.ofFloat(view.asView(), View.TRANSLATION_Y, translation);
88
-        animator.setDuration(FLING_DURATION);
89
-        animator.setInterpolator(new DecelerateInterpolator());
90
-        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
91
-            @Override
92
-            public void onAnimationUpdate(ValueAnimator animation) {
93
-                updateListener.onAnimationUpdate(animation);
94
-            }
95
-        });
96
-        animator.start();
97
-    }
98 58
 }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/behaviours/CollapseTopBarBehaviour.java Dosyayı Görüntüle

@@ -3,7 +3,7 @@ package com.reactnativenavigation.views.collapsingToolbar.behaviours;
3 3
 public class CollapseTopBarBehaviour implements CollapseBehaviour {
4 4
     @Override
5 5
     public boolean shouldCollapseOnFling() {
6
-        return true;
6
+        return false;
7 7
     }
8 8
 
9 9
     @Override