Skip to content

Commit 67d0601

Browse files
AdrianLCAjianliang00
authored andcommitted
[BugFix] Stop foldview fling before expansion
- Stop FoldViewLayoutNG and AppBarLayout fling before applying setFoldExpanded offsets. - Guard posted fling frames with a generation counter so canceled fling work cannot update the offset later. - Add Android instrumentation coverage for stopping the scroller and resetting behavior fling state. issue:m-7328710665 AutoLand: release/3.9,release/3.8 AutoSubmit:True QuickRun: True
1 parent 61053f6 commit 67d0601

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

platform/android/lynx_xelement/lynx_xelement_scroll_coordinator/src/main/java/com/lynx/xelement/scroll/coordinator/LynxUIScrollCoordinator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ open class LynxUIScrollCoordinator(
444444
if (params.hasKey("smooth")) {
445445
enableAnimation = params.getBoolean("smooth")
446446
}
447+
coordinatorLayout.stopFling()
447448
if (enableAnimation) {
448449
animateToOffset(offsetPx = offset)
449450
} else {

platform/android/lynx_xelement/lynx_xelement_scroll_coordinator/src/main/java/com/lynx/xelement/scroll/coordinator/ScrollCoordinatorAppBarLayout.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public void setTouchStopFlingEnabled(boolean enabled) {
6666
enableTouchStopFling = enabled;
6767
}
6868

69+
public void stopFling() {
70+
Behavior behavior = (Behavior) getBehavior();
71+
behavior.stopAppBarLayoutFling(this);
72+
behavior.resetFlingStatus();
73+
}
74+
6975
class Behavior extends AppBarLayout.Behavior {
7076
private static final int TYPE_FLING = 1;
7177
private boolean isFlinging;
@@ -288,11 +294,15 @@ public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout chi
288294
public void onStopNestedScroll(
289295
CoordinatorLayout coordinatorLayout, AppBarLayout appBarLayout, View target, int type) {
290296
super.onStopNestedScroll(coordinatorLayout, appBarLayout, target, type);
291-
isFlinging = false;
292-
shouldBlockNestedScroll = false;
297+
resetFlingStatus();
293298
if (scrollListener != null) {
294299
scrollListener.onScrollStop();
295300
}
296301
}
302+
303+
private void resetFlingStatus() {
304+
isFlinging = false;
305+
shouldBlockNestedScroll = false;
306+
}
297307
}
298308
}

platform/android/lynx_xelement/lynx_xelement_scroll_coordinator/src/main/java/com/lynx/xelement/scroll/coordinator/ScrollCoordinatorLayout.kt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ScrollCoordinatorLayout(
3838
private val childHelper = NestedScrollingChildHelper(this)
3939
private var velocityTracker: VelocityTracker? = null
4040
private val scroller = OverScroller(context)
41+
private var flingGeneration = 0
4142
private var lastTouchY = 0
4243
private val scrollOffset = IntArray(2)
4344
private val scrollConsumed = IntArray(2)
@@ -99,6 +100,18 @@ class ScrollCoordinatorLayout(
99100
velocityTracker = null
100101
}
101102

103+
private fun stopOwnFling() {
104+
flingGeneration++
105+
if (!scroller.isFinished) {
106+
scroller.forceFinished(true)
107+
}
108+
}
109+
110+
fun stopFling() {
111+
stopOwnFling()
112+
appBarLayoutView.stopFling()
113+
}
114+
102115
private fun shouldSkipGestureConsumption(event: MotionEvent?): Boolean {
103116
return coordinatorHost.isEnableNewGesture &&
104117
(consumeGesture != null && !consumeGesture!!) &&
@@ -154,9 +167,7 @@ class ScrollCoordinatorLayout(
154167
val y = (motionEvent.y + 0.5f).toInt()
155168
when (motionEvent.actionMasked) {
156169
MotionEvent.ACTION_DOWN -> {
157-
if (!scroller.isFinished) {
158-
scroller.forceFinished(true)
159-
}
170+
stopOwnFling()
160171
lastTouchY = y
161172
isScrolling = false
162173
nestedOffsets[0] = 0
@@ -213,6 +224,7 @@ class ScrollCoordinatorLayout(
213224
if (abs(velocityY) > minimumVelocity) {
214225
val currentOffset = appBarLayoutView.topAndBottomOffset
215226
val totalScrollRange = appBarLayoutView.totalScrollRange
227+
flingGeneration++
216228
scroller.fling(0, currentOffset, 0, velocityY.toInt(), 0, 0, -totalScrollRange, 0)
217229
ViewCompat.postInvalidateOnAnimation(this)
218230
}
@@ -272,9 +284,7 @@ class ScrollCoordinatorLayout(
272284
MotionEvent.ACTION_DOWN -> {
273285
lastXIntercept = event.x
274286
lastYIntercept = event.y
275-
if (!scroller.isFinished) {
276-
scroller.forceFinished(true)
277-
}
287+
stopOwnFling()
278288
if (nestedScrollAsChild) {
279289
lastTouchY = (event.y + 0.5f).toInt()
280290
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL, ViewCompat.TYPE_TOUCH)
@@ -524,9 +534,12 @@ class ScrollCoordinatorLayout(
524534

525535
override fun computeScroll() {
526536
if (nestedScrollAsChild && scroller.computeScrollOffset()) {
537+
val generation = flingGeneration
527538
val dy = scroller.currY - appBarLayoutView.topAndBottomOffset
528539
ViewCompat.postOnAnimation(this) {
529-
scrollSelf(-dy)
540+
if (generation == flingGeneration) {
541+
scrollSelf(-dy)
542+
}
530543
}
531544
ViewCompat.postInvalidateOnAnimation(this)
532545
}

0 commit comments

Comments
 (0)