Skip to content

Commit

Permalink
Fixed Dismissible animation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
letsar committed Jul 24, 2021
1 parent bc53b41 commit 72ecb7b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.0-dev.8
### Fixed
* Fixes an issue where the Dismissible animation stopped in middle when the gesture was too fast.

## 1.0.0-dev.7
### Fixed
* Fixes an issue where the Slidable animation stopped in middle when the gesture was too fast.
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0-dev.7"
version: "1.0.0-dev.8"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
16 changes: 11 additions & 5 deletions lib/src/action_pane.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
SlidableController? controller;
late double openThreshold;
late double closeThreshold;
bool? showMotion;
bool showMotion = true;

@override
double get extentRatio => widget.extentRatio;
Expand All @@ -120,7 +120,6 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
if (widget.dismissible != null) {
controller!.animation.addListener(handleRatioChanged);
}
showMotion = true;
updateThresholds();
controller!.actionPaneConfigurator = this;
}
Expand Down Expand Up @@ -173,7 +172,13 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
final position = controller!.animation.value;

if (widget.dismissible != null && position > widget.extentRatio) {
controller!.dismissGesture.value = DismissGesture(gesture);
if (controller!.isDismissibleReady) {
controller!.dismissGesture.value = DismissGesture(gesture);
} else {
// If the dismissible is not ready, the animation will stop.
// So we prefere to open the action pane instead.
controller!.openCurrentActionPane();
}
return;
}

Expand All @@ -190,7 +195,8 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {
}

void handleRatioChanged() {
final show = controller!.ratio.abs() <= widget.extentRatio;
final show = controller!.ratio.abs() <= widget.extentRatio &&
!controller!.isDismissibleReady;
if (show != showMotion) {
setState(() {
showMotion = show;
Expand All @@ -204,7 +210,7 @@ class _ActionPaneState extends State<ActionPane> implements RatioConfigurator {

Widget? child;

if (showMotion!) {
if (showMotion) {
final factor = widget.extentRatio;
child = FractionallySizedBox(
alignment: config.alignment,
Expand Down
14 changes: 12 additions & 2 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ class SlidableController {
SlidableController(TickerProvider vsync)
: _animationController = AnimationController(vsync: vsync),
endGesture = ValueNotifier(null),
dismissGesture = ValueNotifier(null),
_dismissGesture = _ValueNotifier(null),
resizeRequest = ValueNotifier(null),
actionPaneType = ValueNotifier(ActionPaneType.none) {
_animationController.addListener(_onRatioChanged);
}

final AnimationController _animationController;
final _ValueNotifier<DismissGesture?> _dismissGesture;

/// Whether the start action pane is enabled.
bool enableStartActionPane = true;
Expand Down Expand Up @@ -156,14 +157,17 @@ class SlidableController {
final ValueNotifier<EndGesture?> endGesture;

/// Track the dismiss gestures.
final ValueNotifier<DismissGesture?> dismissGesture;
ValueNotifier<DismissGesture?> get dismissGesture => _dismissGesture;

/// Track the resize requests.
final ValueNotifier<ResizeRequest?> resizeRequest;

/// Track the type of the action pane.
final ValueNotifier<ActionPaneType> actionPaneType;

/// Indicates whether the dismissible registered to gestures.
bool get isDismissibleReady => _dismissGesture._hasListeners;

/// Whether this [close()] method has been called and not finished.
bool get closing => _closing;
bool _closing = false;
Expand Down Expand Up @@ -323,6 +327,12 @@ class SlidableController {
}
}

class _ValueNotifier<T> extends ValueNotifier<T> {
_ValueNotifier(T value) : super(value);

bool get _hasListeners => hasListeners;
}

/// Extensions for [ActionPaneType].
extension ActionPaneTypeX on ActionPaneType {
/// Transforms this [ActionPaneType] to a sign.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_slidable
description: A Flutter implementation of slidable list item with directional slide actions that can be dismissed.
version: 1.0.0-dev.7
version: 1.0.0-dev.8
homepage: https://github.com/letsar/flutter_slidable

environment:
Expand Down

0 comments on commit 72ecb7b

Please sign in to comment.