@@ -259,18 +259,23 @@ open class StickyNestedLayout : LinearLayout,
259
259
}
260
260
261
261
if (mScroller.isFinished) {
262
- if (inStateOfFling) {
263
- stopNestedScroll(TYPE_NON_TOUCH )
264
- inStateOfFling = false
265
- }
266
- isNestedScrollingStartedByChild = false
267
- isNestedScrollingStartedByThisView = false
262
+ abortScrollerAnimation()
268
263
} else {
269
264
ViewCompat .postInvalidateOnAnimation(this )
270
265
}
271
266
}
272
267
}
273
268
269
+ private fun abortScrollerAnimation () {
270
+ mScroller.abortAnimation()
271
+ if (inStateOfFling) {
272
+ stopNestedScroll(TYPE_NON_TOUCH , " abortScrollerAnimation" )
273
+ inStateOfFling = false
274
+ }
275
+ isNestedScrollingStartedByChild = false
276
+ isNestedScrollingStartedByThisView = false
277
+ }
278
+
274
279
private fun fling (vx : Float , vy : Float ) {
275
280
log { " startFling velocityY = $vy " }
276
281
mScroller.fling(
@@ -280,7 +285,7 @@ open class StickyNestedLayout : LinearLayout,
280
285
lastFlingX = 0
281
286
lastFlingY = 0
282
287
inStateOfFling = true
283
- startNestedScroll(ViewCompat .SCROLL_AXIS_VERTICAL , TYPE_NON_TOUCH )
288
+ startNestedScroll(ViewCompat .SCROLL_AXIS_VERTICAL , TYPE_NON_TOUCH , " fling " )
284
289
ViewCompat .postInvalidateOnAnimation(this )
285
290
}
286
291
@@ -298,17 +303,24 @@ open class StickyNestedLayout : LinearLayout,
298
303
299
304
override fun isNestedScrollingEnabled () = childHelper.isNestedScrollingEnabled
300
305
301
- override fun startNestedScroll (axes : Int ) = startNestedScroll(axes, TYPE_TOUCH )
306
+ override fun startNestedScroll (axes : Int ) =
307
+ startNestedScroll(axes, TYPE_TOUCH , " callStartNestedScroll" )
308
+
309
+ override fun startNestedScroll (axes : Int , type : Int ): Boolean =
310
+ startNestedScroll(axes, type, " callStartNestedScroll(type)" )
302
311
303
- override fun startNestedScroll (axes : Int , type : Int ): Boolean {
304
- log { " startNestedScroll $type " }
312
+ private fun startNestedScroll (axes : Int , type : Int , reason : String ): Boolean {
313
+ log { " startNestedScroll $type by $reason " }
305
314
return childHelper.startNestedScroll(axes, type)
306
315
}
307
316
308
- override fun stopNestedScroll () = stopNestedScroll(TYPE_TOUCH )
317
+ override fun stopNestedScroll () = stopNestedScroll(TYPE_TOUCH , " CallStopNestedScroll " )
309
318
310
- override fun stopNestedScroll (type : Int ) {
311
- log { " stopNestedScroll $type " }
319
+ override fun stopNestedScroll (type : Int ) =
320
+ stopNestedScroll(TYPE_TOUCH , " CallStopNestedScroll(type)" )
321
+
322
+ private fun stopNestedScroll (type : Int , reason : String ) {
323
+ log { " stopNestedScroll $type by $reason " }
312
324
childHelper.stopNestedScroll(type)
313
325
}
314
326
@@ -394,7 +406,11 @@ open class StickyNestedLayout : LinearLayout,
394
406
isNestedScrollingStartedByThisView = false
395
407
isNestedScrollingStartedByChild = true
396
408
// 开始通知parent的嵌套滑动
397
- startNestedScroll(nestedScrollAxes or ViewCompat .SCROLL_AXIS_VERTICAL , type)
409
+ startNestedScroll(
410
+ nestedScrollAxes or ViewCompat .SCROLL_AXIS_VERTICAL ,
411
+ type,
412
+ " onStartNestedScroll"
413
+ )
398
414
return true
399
415
}
400
416
@@ -406,7 +422,7 @@ open class StickyNestedLayout : LinearLayout,
406
422
isNestedScrollingStartedByThisView = false
407
423
isNestedScrollingStartedByChild = false
408
424
}
409
- stopNestedScroll(type) // 结束parent的嵌套滑动
425
+ stopNestedScroll(type, " onStopNestedScroll " ) // 结束parent的嵌套滑动
410
426
}
411
427
412
428
override fun onNestedPreScroll (target : View , dx : Int , dy : Int , consumed : IntArray? , type : Int ) {
@@ -512,20 +528,24 @@ open class StickyNestedLayout : LinearLayout,
512
528
513
529
fling(vx, vy)
514
530
}
515
- stopNestedScroll(TYPE_TOUCH )
531
+ stopNestedScroll(TYPE_TOUCH , " onFling " )
516
532
return true
517
533
}
518
534
return false
519
535
}
520
536
521
537
override fun onDown (e : MotionEvent ): Boolean {
522
538
log { " onDown $e " }
523
- mScroller.abortAnimation ()
539
+ abortScrollerAnimation ()
524
540
lastY = e.y
525
541
lastX = e.x
526
- isNestedScrollingStartedByThisView = true
527
- isNestedScrollingStartedByChild = false
528
- startNestedScroll(ViewCompat .SCROLL_AXIS_VERTICAL )
542
+ if (e.x in headView.left.. headView.right &&
543
+ e.y in headView.top.. headView.bottom
544
+ ) {
545
+ isNestedScrollingStartedByThisView = true
546
+ isNestedScrollingStartedByChild = false
547
+ startNestedScroll(ViewCompat .SCROLL_AXIS_VERTICAL , TYPE_TOUCH , " onDown" )
548
+ }
529
549
return true
530
550
}
531
551
}
@@ -541,7 +561,10 @@ open class StickyNestedLayout : LinearLayout,
541
561
) {
542
562
log { if (action == MotionEvent .ACTION_UP ) " onUp" else " onCancel" }
543
563
if (isNestedScrollingStartedByThisView) {
544
- stopNestedScroll(TYPE_TOUCH )
564
+ stopNestedScroll(
565
+ TYPE_TOUCH ,
566
+ if (action == MotionEvent .ACTION_UP ) " onUp" else " onCancel"
567
+ )
545
568
return true
546
569
}
547
570
return false
@@ -561,14 +584,12 @@ open class StickyNestedLayout : LinearLayout,
561
584
when (action) {
562
585
MotionEvent .ACTION_DOWN -> {
563
586
log { " onIntercept onDown" }
564
- mScroller.abortAnimation ()
587
+ abortScrollerAnimation ()
565
588
lastY = event.y
566
589
lastX = event.x
567
590
downRawY = event.rawY
568
591
downRawX = event.rawX
569
- isNestedScrollingStartedByThisView = false
570
- isNestedScrollingStartedByChild = false
571
- startNestedScroll(ViewCompat .SCROLL_AXIS_VERTICAL )
592
+ startNestedScroll(ViewCompat .SCROLL_AXIS_VERTICAL , TYPE_TOUCH , " onInterceptDown" )
572
593
}
573
594
MotionEvent .ACTION_MOVE -> {
574
595
lastY = event.y
0 commit comments