Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the autoplay and autoplayDisableOnInteraction on all layouts #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/src/custom_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
if (_animationCount == null) {
return new Container();
}
return new AnimatedBuilder(
animation: _animationController, builder: _buildAnimation);
return new AnimatedBuilder( animation: _animationController, builder: _buildAnimation);
}

double _currentValue;
Expand Down Expand Up @@ -192,7 +191,6 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>

void _onPanEnd(DragEndDetails details) {
if (_lockScroll) return;

double velocity = widget.scrollDirection == Axis.horizontal
? details.velocity.pixelsPerSecond.dx
: details.velocity.pixelsPerSecond.dy;
Expand All @@ -210,6 +208,7 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
} else {
_move(0.5);
}
widget.onEndSwipe();
}

void _onPanStart(DragStartDetails details) {
Expand All @@ -218,10 +217,11 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
_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
Expand Down Expand Up @@ -367,6 +367,7 @@ class CustomLayoutOption {
class _CustomLayoutSwiper extends _SubSwiper {
final CustomLayoutOption option;


_CustomLayoutSwiper(
{this.option,
double itemWidth,
Expand All @@ -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,
Expand All @@ -394,7 +398,10 @@ class _CustomLayoutSwiper extends _SubSwiper {
index: index,
itemCount: itemCount,
controller: controller,
scrollDirection: scrollDirection);
scrollDirection: scrollDirection,
onStartSwipe: onStartSwipe,
onEndSwipe: onEndSwipe,
);

@override
State<StatefulWidget> createState() {
Expand Down Expand Up @@ -433,4 +440,5 @@ class _CustomLayoutState extends _CustomLayoutStateBase<_CustomLayoutSwiper> {

return child;
}

}
59 changes: 55 additions & 4 deletions lib/src/swiper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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();
}
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -715,7 +757,10 @@ class _TinderSwiper extends _SubSwiper {
index: index,
onIndexChanged: onIndexChanged,
itemCount: itemCount,
scrollDirection: scrollDirection);
scrollDirection: scrollDirection,
onStartSwipe: onStartSwipe,
onEndSwipe: onEndSwipe,
);

@override
State<StatefulWidget> createState() {
Expand All @@ -737,6 +782,9 @@ class _StackSwiper extends _SubSwiper {
bool loop,
int itemCount,
Axis scrollDirection,
VoidCallback onStartSwipe ,
VoidCallback onEndSwipe,

}) : super(
loop: loop,
key: key,
Expand All @@ -749,7 +797,10 @@ class _StackSwiper extends _SubSwiper {
index: index,
onIndexChanged: onIndexChanged,
itemCount: itemCount,
scrollDirection: scrollDirection);
scrollDirection: scrollDirection,
onStartSwipe: onStartSwipe,
onEndSwipe: onEndSwipe,
);

@override
State<StatefulWidget> createState() {
Expand Down