Skip to content
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
3 changes: 2 additions & 1 deletion lib/src/animation/animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ extension _AnimationControllerX on AnimationController {
Animation<Offset> swipeAnimation({
required Offset startPosition,
required Offset endPosition,
required Curve curve,
}) {
return Tween<Offset>(
begin: startPosition,
end: endPosition,
).animate(
CurvedAnimation(
parent: this,
curve: const Cubic(0.7, 1, 0.73, 1),
curve: curve,
),
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/callback/callbacks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ typedef SwipeCompletionCallback = void Function(
SwipeDirection direction,
);

typedef DragReleaseCallback = void Function(
int index,
SwipeDirection direction,
);

/// Callback called just before launching the Swipe action.
typedef OnWillMoveNext = bool Function(
int index,
Expand Down
19 changes: 19 additions & 0 deletions lib/src/swipable_stack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SwipableStack extends StatefulWidget {
SwipableStack({
required this.builder,
SwipableStackController? controller,
this.onDragCompleted,
this.onSwipeCompleted,
this.onWillMoveNext,
this.overlayBuilder,
Expand All @@ -32,6 +33,7 @@ class SwipableStack extends StatefulWidget {
this.stackClipBehaviour = _defaultStackClipBehaviour,
this.detectableSwipeDirections = _defaultDetectableSwipeDirections,
this.allowVerticalSwipe = true,
Curve? nextAnimationCurve,
Curve? cancelAnimationCurve,
Curve? rewindAnimationCurve,
this.swipeAnchor,
Expand All @@ -40,6 +42,7 @@ class SwipableStack extends StatefulWidget {
this.dragStartDuration = const Duration(milliseconds: 150),
this.dragStartCurve = Curves.easeOut,
}) : controller = controller ?? SwipableStackController(),
nextAnimationCurve = nextAnimationCurve ?? _defaultNextAnimationCurve,
cancelAnimationCurve =
cancelAnimationCurve ?? _defaultCancelAnimationCurve,
rewindAnimationCurve =
Expand All @@ -56,6 +59,9 @@ class SwipableStack extends StatefulWidget {
/// An object to manipulate the [SwipableStack].
final SwipableStackController controller;

/// Callback called when letting go of a card that will be swiped.
final DragReleaseCallback? onDragCompleted;

/// Callback called when the Swipe is completed.
final SwipeCompletionCallback? onSwipeCompleted;

Expand Down Expand Up @@ -102,6 +108,9 @@ class SwipableStack extends StatefulWidget {
/// Where should the card be anchored on during swipe rotation
final SwipeAnchor? swipeAnchor;

/// A curve to animate the card when a swipe is complete.
final Curve nextAnimationCurve;

/// A curve to animate the card when canceling the swipe.
final Curve cancelAnimationCurve;

Expand Down Expand Up @@ -140,6 +149,8 @@ class SwipableStack extends StatefulWidget {
);
static const _defaultRewindAnimationCurve = ElasticOutCurve(0.95);

static const _defaultNextAnimationCurve = Cubic(0.7, 1, 0.73, 1);

@override
_SwipableStackState createState() => _SwipableStackState();
}
Expand Down Expand Up @@ -649,6 +660,12 @@ class _SwipableStackState extends State<SwipableStack>
if (currentSession == null) {
return;
}

widget.onDragCompleted?.call(
_currentIndex,
swipeDirection,
);

final distToAssist = _distanceToAssist(
swipeDirection: swipeDirection,
context: context,
Expand All @@ -669,6 +686,7 @@ class _SwipableStackState extends State<SwipableStack>
context: context,
swipeDirection: swipeDirection,
),
curve: widget.nextAnimationCurve,
);

void animate() {
Expand Down Expand Up @@ -736,6 +754,7 @@ class _SwipableStackState extends State<SwipableStack>
context: context,
swipeDirection: swipeDirection,
),
curve: widget.nextAnimationCurve,
);

void animate() {
Expand Down