Browse Source

Fix collapse issue after list bounce back (#821)

When a view with collapsing header was fully expended, scrolling down
and quickly releasing the finger would couse the list to "bounce back".
Since the view can collapse only if its scrollY amount is less then the
scaled touch slop - the view didn't collapse and instead, scroll was
enabled.
Guy Carmeli 7 years ago
parent
commit
61b558bf8b

+ 5
- 7
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapseCalculator.java View File

@@ -9,7 +9,6 @@ import android.widget.ScrollView;
9 9
 
10 10
 import com.reactnativenavigation.NavigationApplication;
11 11
 import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseBehaviour;
12
-import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseTitleBarBehaviour;
13 12
 import com.reactnativenavigation.views.collapsingToolbar.behaviours.TitleBarHideOnScrollBehaviour;
14 13
 
15 14
 public class CollapseCalculator {
@@ -123,8 +122,9 @@ public class CollapseCalculator {
123 122
         }
124 123
         checkCollapseLimits();
125 124
         return (isNotCollapsedOrExpended() ||
126
-               (canCollapse && isExpendedAndScrollingUp(direction)) ||
127
-               (canExpend && isCollapsedAndScrollingDown(direction)));
125
+               (canCollapse && isExpendedAndScrollingUp(direction) && collapseBehaviour.canCollapse(scrollView.getScrollY(), scaledTouchSlop)) ||
126
+               (canExpend && isCollapsedAndScrollingDown(direction) && collapseBehaviour.canExpend(scrollView.getScrollY(), scaledTouchSlop))
127
+        );
128 128
     }
129 129
 
130 130
     private boolean isScrolling() {
@@ -157,14 +157,12 @@ public class CollapseCalculator {
157 157
 
158 158
     private boolean calculateCanCollapse(float currentTopBarTranslation, float finalExpendedTranslation, float finalCollapsedTranslation) {
159 159
         return currentTopBarTranslation > finalCollapsedTranslation &&
160
-               currentTopBarTranslation <= finalExpendedTranslation &&
161
-               (scrollView.getScrollY() <= scaledTouchSlop || (collapseBehaviour instanceof TitleBarHideOnScrollBehaviour || collapseBehaviour instanceof CollapseTitleBarBehaviour));
160
+               currentTopBarTranslation <= finalExpendedTranslation;
162 161
     }
163 162
 
164 163
     private boolean calculateCanExpend(float currentTopBarTranslation, float finalExpendedTranslation, float finalCollapsedTranslation) {
165 164
         return currentTopBarTranslation >= finalCollapsedTranslation &&
166
-               currentTopBarTranslation < finalExpendedTranslation &&
167
-               (scrollView.getScrollY() <= scaledTouchSlop || (collapseBehaviour instanceof TitleBarHideOnScrollBehaviour || collapseBehaviour instanceof CollapseTitleBarBehaviour));
165
+               currentTopBarTranslation < finalExpendedTranslation;
168 166
     }
169 167
 
170 168
     private boolean isCollapsedAndScrollingDown(Direction direction) {

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/behaviours/CollapseBehaviour.java View File

@@ -4,4 +4,8 @@ public interface CollapseBehaviour {
4 4
     boolean shouldCollapseOnFling();
5 5
 
6 6
     boolean shouldCollapseOnTouchUp();
7
+
8
+    boolean canCollapse(int scrollY, int scaledTouchSlop);
9
+
10
+    boolean canExpend(int scrollY, int scaledTouchSlop);
7 11
 }

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/behaviours/CollapseTitleBarBehaviour.java View File

@@ -10,4 +10,14 @@ public class CollapseTitleBarBehaviour implements CollapseBehaviour {
10 10
     public boolean shouldCollapseOnTouchUp() {
11 11
         return true;
12 12
     }
13
+
14
+    @Override
15
+    public boolean canCollapse(int scrollY, int scaledTouchSlop) {
16
+        return true;
17
+    }
18
+
19
+    @Override
20
+    public boolean canExpend(int scrollY, int scaledTouchSlop) {
21
+        return true;
22
+    }
13 23
 }

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/behaviours/CollapseTopBarBehaviour.java View File

@@ -10,4 +10,14 @@ public class CollapseTopBarBehaviour implements CollapseBehaviour {
10 10
     public boolean shouldCollapseOnTouchUp() {
11 11
         return false;
12 12
     }
13
+
14
+    @Override
15
+    public boolean canCollapse(int scrollY, int scaledTouchSlop) {
16
+        return scrollY <= scaledTouchSlop;
17
+    }
18
+
19
+    @Override
20
+    public boolean canExpend(int scrollY, int scaledTouchSlop) {
21
+        return scrollY <= scaledTouchSlop;
22
+    }
13 23
 }

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/behaviours/TitleBarHideOnScrollBehaviour.java View File

@@ -10,4 +10,14 @@ public class TitleBarHideOnScrollBehaviour implements CollapseBehaviour {
10 10
     public boolean shouldCollapseOnTouchUp() {
11 11
         return true;
12 12
     }
13
+
14
+    @Override
15
+    public boolean canCollapse(int scrollY, int scaledTouchSlop) {
16
+        return true;
17
+    }
18
+
19
+    @Override
20
+    public boolean canExpend(int scrollY, int scaledTouchSlop) {
21
+        return true;
22
+    }
13 23
 }