collection: sloppy scroll physics to improve scale gesture recognition

This commit is contained in:
Thibault Deckers 2020-06-09 10:17:35 +09:00
parent 85a1ebf8b4
commit 20c40020c0
2 changed files with 27 additions and 1 deletions

View file

@ -12,6 +12,7 @@ import 'package:aves/widgets/album/grid/scaling.dart';
import 'package:aves/widgets/album/grid/tile_extent_manager.dart';
import 'package:aves/widgets/common/icons.dart';
import 'package:aves/widgets/common/scroll_thumb.dart';
import 'package:aves/widgets/common/sloppy_scroll_physics.dart';
import 'package:draggable_scrollbar/draggable_scrollbar.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
@ -153,7 +154,7 @@ class _CollectionScrollViewState extends State<CollectionScrollView> {
primary: true,
// workaround to prevent scrolling the app bar away
// when there is no content and we use `SliverFillRemaining`
physics: collection.isEmpty ? const NeverScrollableScrollPhysics() : null,
physics: collection.isEmpty ? const NeverScrollableScrollPhysics() : const SloppyScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
cacheExtent: widget.cacheExtent,
slivers: [
appBar,

View file

@ -0,0 +1,25 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';
class SloppyScrollPhysics extends ScrollPhysics {
const SloppyScrollPhysics({
this.touchSlopFactor = 1,
ScrollPhysics parent,
}) : super(parent: parent);
// in [0, 1]
// 0: most reactive but will not let other recognizers accept gestures
// 1: less reactive but gives the most leeway to other recognizers
final double touchSlopFactor;
@override
SloppyScrollPhysics applyTo(ScrollPhysics ancestor) {
return SloppyScrollPhysics(
touchSlopFactor: touchSlopFactor,
parent: buildParent(ancestor),
);
}
@override
double get dragStartDistanceMotionThreshold => kTouchSlop * touchSlopFactor;
}