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
 
9
 
10
 import com.reactnativenavigation.NavigationApplication;
10
 import com.reactnativenavigation.NavigationApplication;
11
 import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseBehaviour;
11
 import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseBehaviour;
12
-import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseTitleBarBehaviour;
13
 import com.reactnativenavigation.views.collapsingToolbar.behaviours.TitleBarHideOnScrollBehaviour;
12
 import com.reactnativenavigation.views.collapsingToolbar.behaviours.TitleBarHideOnScrollBehaviour;
14
 
13
 
15
 public class CollapseCalculator {
14
 public class CollapseCalculator {
123
         }
122
         }
124
         checkCollapseLimits();
123
         checkCollapseLimits();
125
         return (isNotCollapsedOrExpended() ||
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
     private boolean isScrolling() {
130
     private boolean isScrolling() {
157
 
157
 
158
     private boolean calculateCanCollapse(float currentTopBarTranslation, float finalExpendedTranslation, float finalCollapsedTranslation) {
158
     private boolean calculateCanCollapse(float currentTopBarTranslation, float finalExpendedTranslation, float finalCollapsedTranslation) {
159
         return currentTopBarTranslation > finalCollapsedTranslation &&
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
     private boolean calculateCanExpend(float currentTopBarTranslation, float finalExpendedTranslation, float finalCollapsedTranslation) {
163
     private boolean calculateCanExpend(float currentTopBarTranslation, float finalExpendedTranslation, float finalCollapsedTranslation) {
165
         return currentTopBarTranslation >= finalCollapsedTranslation &&
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
     private boolean isCollapsedAndScrollingDown(Direction direction) {
168
     private boolean isCollapsedAndScrollingDown(Direction direction) {

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

4
     boolean shouldCollapseOnFling();
4
     boolean shouldCollapseOnFling();
5
 
5
 
6
     boolean shouldCollapseOnTouchUp();
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
     public boolean shouldCollapseOnTouchUp() {
10
     public boolean shouldCollapseOnTouchUp() {
11
         return true;
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
     public boolean shouldCollapseOnTouchUp() {
10
     public boolean shouldCollapseOnTouchUp() {
11
         return false;
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
     public boolean shouldCollapseOnTouchUp() {
10
     public boolean shouldCollapseOnTouchUp() {
11
         return true;
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
 }