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 Hero animation when drag-dismissing WoltModalSheet at zero threshold #368

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ArinFaraj
Copy link

@ArinFaraj ArinFaraj commented Feb 24, 2025

Description

Fixes an issue where Hero widgets fail to animate properly when drag-dismissing a WoltModalSheet that reaches a near-zero position. Previously, when dragging the sheet to a position very close to zero and releasing, the Hero widgets on the underlying route would not animate back correctly, while they worked fine when drag-dismissing from halfway or using fling gestures.

The fix prevents the animation controller from reaching a fully dismissed state during drag operations by implementing a minimum threshold of 0.01. This ensures the proper dismissal sequence is always followed, allowing Hero widgets to complete their transitions correctly.

Changes:

  • Added minimum threshold check in vertical and horizontal drag update handlers
  • Ensures consistent Hero widget behavior across all dismissal scenarios

Sample Code

import 'package:flutter/material.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

void main() {
  runApp(
    MaterialApp(
      title: 'Flutter Demo',
      home: Builder(
        builder: (context) {
          return Scaffold(
            body: Padding(
              padding: const EdgeInsets.all(40),
              child: Align(
                alignment: Alignment.bottomCenter,
                child: ElevatedButton(
                  onPressed: () {
                    showWoltDialog(context);
                  },
                  child: Hero(
                    tag: 'hero',
                    child: const Icon(Icons.person, size: 100),
                  ),
                ),
              ),
            ),
          );
        },
      ),
    ),
  );
}

void showWoltDialog(BuildContext context) {
  WoltModalSheet.show(
    context: context,
    modalTypeBuilder: (context) => WoltModalType.bottomSheet(),
    pageListBuilder:
        (bottomSheetContext) => [
          WoltModalSheetPage(
            child: Hero(
              tag: 'hero',
              child: const Icon(Icons.person, size: 100),
            ),
          ),
        ],
  );
}

Sample video

Recording.2025-03-04.212803.mp4

Related Issues

Replace this paragraph with a list of issues related to this PR from the issue database. Indicate, which of these issues are resolved or fixed by this PR.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes tests for all changed/updated/fixed behaviors.
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • The package compiles with the minimum Flutter version stated in the pubspec.yaml

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

- Refactor drag handling logic for vertical and horizontal dismissals
- Add minimum value check to prevent unintended dismissals
- Use pattern matching for vertical drag direction
- Ensure consistent animation controller value updates
@ulusoyca
Copy link
Collaborator

ulusoyca commented Mar 3, 2025

@TahaTesser Do you think you may have time to check this?

@TahaTesser TahaTesser self-requested a review March 3, 2025 14:01
Copy link
Collaborator

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing!

Introducing a threshold might make sense with more information.

Previously, when dragging the sheet to a position very close to zero and releasing, the Hero widgets on the underlying route would not animate back correctly, while they worked fine when drag-dismissing from halfway or using fling gestures.

Could you please share a code sample to reproduce this behavior? It would be great in the context of this fix. I can reproduce the described behavior with a sample and write tests to verify that this fix is consistent.

@ArinFaraj
Copy link
Author

Thank you for your time, I have updated the pr with a code sample and a video of the issue

@TahaTesser
Copy link
Collaborator

Thank you for your time, I have updated the pr with a code sample and a video of the issue

Thanks so much for the code sample and demo video. I've tried both iOS, Android, and macOS desktop. I couldn't reproduce the failed Hero animation as seen in your demo. Could you please share where you reproduced it and how you ensured this is consistent?

@ArinFaraj
Copy link
Author

Since i can reproduce it in a new flutter project with the latest flutter version and package version, here are the steps to reproduce:

  • Create a flutter project and add wolt_modal_sheet package
  • Copy and paste the sample code into the main file
  • Run on any platform
  • Open the sheet
  • Start dragging the sheet down until it reaches zero (completely hidden)
  • Stop the drag and you will see that the sheet is gone but the hero widget has not come back to its original place (the hero did not have time to animate because the transition duration became 0, since the transition starts once you stop dragging)

@TahaTesser
Copy link
Collaborator

  • Start dragging the sheet down until it reaches zero (completely hidden)
  • Stop the drag and you will see that the sheet is gone but the hero widget has not come back to its original place (the hero did not have time to animate because the transition duration became 0, since the transition starts once you stop dragging)

Following these steps, Hero widget always appear in my sample reproduction. I couldn't get the blank button like show in your demo.

External.Device.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants