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

added onDoubleTap and onLongPress gestures #35

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 3 additions & 1 deletion lib/src/custom_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
}

void _getSize(_) {
afterRender();
if(context != null) {
afterRender();
}
}

@mustCallSuper
Expand Down
28 changes: 26 additions & 2 deletions lib/src/swiper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:transformer_page_view/transformer_page_view.dart';
part 'custom_layout.dart';

typedef void SwiperOnTap(int index);
typedef void SwiperOnDoubleTap(int index);
typedef void SwiperOnLongPress(int index);

typedef Widget SwiperDataBuilder(BuildContext context, dynamic data, int index);

Expand Down Expand Up @@ -79,6 +81,12 @@ class Swiper extends StatefulWidget {
///Called when tap
final SwiperOnTap onTap;

///Called when double tap
final SwiperOnDoubleTap onDoubleTap;

///Called when long press
final SwiperOnLongPress onLongPress;

///The swiper pagination plugin
final SwiperPlugin pagination;

Expand Down Expand Up @@ -125,6 +133,8 @@ class Swiper extends StatefulWidget {
this.onIndexChanged,
this.index,
this.onTap,
this.onDoubleTap,
this.onLongPress,
this.control,
this.loop: true,
this.curve: Curves.ease,
Expand Down Expand Up @@ -169,6 +179,8 @@ class Swiper extends StatefulWidget {
ValueChanged<int> onIndexChanged,
int index,
SwiperOnTap onTap,
SwiperOnDoubleTap onDoubleTap,
SwiperOnLongPress onLongPress,
bool loop: true,
Curve curve: Curves.ease,
Axis scrollDirection: Axis.horizontal,
Expand Down Expand Up @@ -206,6 +218,8 @@ class Swiper extends StatefulWidget {
onIndexChanged: onIndexChanged,
index: index,
onTap: onTap,
onDoubleTap: onDoubleTap,
onLongPress: onLongPress,
curve: curve,
scrollDirection: scrollDirection,
pagination: pagination,
Expand Down Expand Up @@ -234,6 +248,8 @@ class Swiper extends StatefulWidget {
ValueChanged<int> onIndexChanged,
int index,
SwiperOnTap onTap,
SwiperOnDoubleTap onDoubleTap,
SwiperOnLongPress onLongPress,
bool loop: true,
Curve curve: Curves.ease,
Axis scrollDirection: Axis.horizontal,
Expand Down Expand Up @@ -268,6 +284,8 @@ class Swiper extends StatefulWidget {
onIndexChanged: onIndexChanged,
index: index,
onTap: onTap,
onDoubleTap: onDoubleTap,
onLongPress: onLongPress,
curve: curve,
key: key,
scrollDirection: scrollDirection,
Expand Down Expand Up @@ -387,7 +405,13 @@ class _SwiperState extends _SwiperTimerMixin {
return new GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
this.widget.onTap(index);
this.widget.onTap?.call(index);
},
onDoubleTap: () {
this.widget.onDoubleTap?.call(index);
},
onLongPress: () {
this.widget.onLongPress?.call(index);
},
child: widget.itemBuilder(context, index),
);
Expand Down Expand Up @@ -462,7 +486,7 @@ class _SwiperState extends _SwiperTimerMixin {

Widget _buildSwiper() {
IndexedWidgetBuilder itemBuilder;
if (widget.onTap != null) {
if (widget.onTap != null || widget.onDoubleTap != null || widget.onLongPress != null) {
itemBuilder = _wrapTap;
} else {
itemBuilder = widget.itemBuilder;
Expand Down