diff --git a/lib/src/custom_layout.dart b/lib/src/custom_layout.dart index 8ce77f2..7d0c45a 100644 --- a/lib/src/custom_layout.dart +++ b/lib/src/custom_layout.dart @@ -118,8 +118,7 @@ abstract class _CustomLayoutStateBase extends State if (_animationCount == null) { return new Container(); } - return new AnimatedBuilder( - animation: _animationController, builder: _buildAnimation); + return new AnimatedBuilder( animation: _animationController, builder: _buildAnimation); } double _currentValue; @@ -192,7 +191,6 @@ abstract class _CustomLayoutStateBase extends State void _onPanEnd(DragEndDetails details) { if (_lockScroll) return; - double velocity = widget.scrollDirection == Axis.horizontal ? details.velocity.pixelsPerSecond.dx : details.velocity.pixelsPerSecond.dy; @@ -210,6 +208,7 @@ abstract class _CustomLayoutStateBase extends State } else { _move(0.5); } + widget.onEndSwipe(); } void _onPanStart(DragStartDetails details) { @@ -218,10 +217,11 @@ abstract class _CustomLayoutStateBase extends State _currentPos = widget.scrollDirection == Axis.horizontal ? details.globalPosition.dx : details.globalPosition.dy; + widget.onStartSwipe(); } void _onPanUpdate(DragUpdateDetails details) { - if (_lockScroll) return; + if (_lockScroll ) return; double value = _currentValue + ((widget.scrollDirection == Axis.horizontal ? details.globalPosition.dx @@ -367,6 +367,7 @@ class CustomLayoutOption { class _CustomLayoutSwiper extends _SubSwiper { final CustomLayoutOption option; + _CustomLayoutSwiper( {this.option, double itemWidth, @@ -380,7 +381,10 @@ class _CustomLayoutSwiper extends _SubSwiper { int index, int itemCount, Axis scrollDirection, - SwiperController controller}) + SwiperController controller, + VoidCallback onStartSwipe , + VoidCallback onEndSwipe , + }) : assert(option != null), super( loop: loop, @@ -394,7 +398,10 @@ class _CustomLayoutSwiper extends _SubSwiper { index: index, itemCount: itemCount, controller: controller, - scrollDirection: scrollDirection); + scrollDirection: scrollDirection, + onStartSwipe: onStartSwipe, + onEndSwipe: onEndSwipe, + ); @override State createState() { @@ -433,4 +440,5 @@ class _CustomLayoutState extends _CustomLayoutStateBase<_CustomLayoutSwiper> { return child; } + } diff --git a/lib/src/swiper.dart b/lib/src/swiper.dart index 9783740..c694143 100644 --- a/lib/src/swiper.dart +++ b/lib/src/swiper.dart @@ -481,6 +481,16 @@ class _SwiperState extends _SwiperTimerMixin { onIndexChanged: _onIndexChanged, controller: _controller, scrollDirection: widget.scrollDirection, + onStartSwipe: () { + if (widget.autoplayDisableOnInteraction && widget.autoplay) { + if (_timer != null) _stopAutoplay(); + } + }, + onEndSwipe: () { + if (widget.autoplayDisableOnInteraction && widget.autoplay) { + if (_timer == null) _startAutoplay(); + } + }, ); } else if (_isPageViewLayout()) { PageTransformer transformer = widget.transformer; @@ -536,9 +546,20 @@ class _SwiperState extends _SwiperTimerMixin { onIndexChanged: _onIndexChanged, controller: _controller, scrollDirection: widget.scrollDirection, + onStartSwipe: () { + if (widget.autoplayDisableOnInteraction && widget.autoplay) { + if (_timer != null) _stopAutoplay(); + } + }, + onEndSwipe: () { + if (widget.autoplayDisableOnInteraction && widget.autoplay) { + if (_timer == null) _startAutoplay(); + } + }, ); } else if (widget.layout == SwiperLayout.CUSTOM) { - return new _CustomLayoutSwiper( + + Widget child = new _CustomLayoutSwiper( loop: widget.loop, option: widget.customLayoutOption, itemWidth: widget.itemWidth, @@ -551,7 +572,21 @@ class _SwiperState extends _SwiperTimerMixin { onIndexChanged: _onIndexChanged, controller: _controller, scrollDirection: widget.scrollDirection, + onStartSwipe: () { + if (widget.autoplayDisableOnInteraction && widget.autoplay) { + if (_timer != null) _stopAutoplay(); + } + }, + onEndSwipe: () { + if (widget.autoplayDisableOnInteraction && widget.autoplay) { + if (_timer == null) _startAutoplay(); + } + }, + ); + + return child; + } else { return new Container(); } @@ -659,6 +694,8 @@ abstract class _SubSwiper extends StatefulWidget { final double itemHeight; final bool loop; final Axis scrollDirection; + final VoidCallback onStartSwipe; + final VoidCallback onEndSwipe; _SubSwiper( {Key key, @@ -672,7 +709,9 @@ abstract class _SubSwiper extends StatefulWidget { this.index, this.itemCount, this.scrollDirection: Axis.horizontal, - this.onIndexChanged}) + this.onIndexChanged, + this.onStartSwipe, + this.onEndSwipe}) : super(key: key); @override @@ -702,6 +741,9 @@ class _TinderSwiper extends _SubSwiper { bool loop, int itemCount, Axis scrollDirection, + VoidCallback onStartSwipe , + VoidCallback onEndSwipe, + }) : assert(itemWidth != null && itemHeight != null), super( loop: loop, @@ -715,7 +757,10 @@ class _TinderSwiper extends _SubSwiper { index: index, onIndexChanged: onIndexChanged, itemCount: itemCount, - scrollDirection: scrollDirection); + scrollDirection: scrollDirection, + onStartSwipe: onStartSwipe, + onEndSwipe: onEndSwipe, + ); @override State createState() { @@ -737,6 +782,9 @@ class _StackSwiper extends _SubSwiper { bool loop, int itemCount, Axis scrollDirection, + VoidCallback onStartSwipe , + VoidCallback onEndSwipe, + }) : super( loop: loop, key: key, @@ -749,7 +797,10 @@ class _StackSwiper extends _SubSwiper { index: index, onIndexChanged: onIndexChanged, itemCount: itemCount, - scrollDirection: scrollDirection); + scrollDirection: scrollDirection, + onStartSwipe: onStartSwipe, + onEndSwipe: onEndSwipe, + ); @override State createState() {