-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Press-and-hold gesture in PageView doesn't stop momentum scrolli…
…ng (#219) ## Fixes / Closes (optional) <!-- List any issues or pull requests that this PR fixes or closes. Use the format: "Fixes #123" or "Closes #456". --> Fixes #214. ## Description This PR adds `holdWithScrollPosition()` to `ScrollableSheetExtent` to handle press-and-hold gestures in scrollable sheet content. It starts a `HoldScrollDrivenSheetActivity`, which stops momentum scrolling (if it is running). The absence of this handling logic hasn't been problematic for simple ListViews or PageViews with only one page. This is because the SDK triggers `ScrollPosition.drag()` immediately after calling `ScrollPosition.hold()` when the user performs a press-and-hold gesture. However, in a PageView with multiple ListViews, `drag()` won't be called after `hold()` until the user actually moves their finger. ## Summary (check all that apply) <!-- Mark the boxes that apply to this PR. Add details if necessary. --> - [x] Modified / added code - [x] Modified / added tests - [x] Modified / added examples - [ ] Modified / added others (pubspec.yaml, workflows, etc...) - [ ] Updated README - [ ] Contains breaking changes - [ ] Created / updated migration guide - [x] Incremented version number - [x] Updated CHANGELOG
- Loading branch information
Showing
12 changed files
with
310 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:smooth_sheets/smooth_sheets.dart'; | ||
|
||
void main() { | ||
runApp(const _ScrollablePageViewSheetExample()); | ||
} | ||
|
||
/// An example of [ScrollableSheet] + [PageView]. | ||
class _ScrollablePageViewSheetExample extends StatelessWidget { | ||
const _ScrollablePageViewSheetExample(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: Scaffold( | ||
body: Center( | ||
child: Builder( | ||
builder: (context) { | ||
return ElevatedButton( | ||
onPressed: () { | ||
Navigator.push( | ||
context, | ||
ModalSheetRoute(builder: (_) => const _MySheet()), | ||
); | ||
}, | ||
child: const Text('Show Sheet'), | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
final pageController = PageController(); | ||
|
||
class _MySheet extends StatelessWidget { | ||
const _MySheet(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ScrollableSheet( | ||
child: Material( | ||
child: SizedBox( | ||
height: 600, | ||
child: PageView( | ||
controller: pageController, | ||
children: const [ | ||
_PageViewItem(), | ||
_PageViewItem(), | ||
_PageViewItem(), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _PageViewItem extends StatefulWidget { | ||
const _PageViewItem(); | ||
|
||
@override | ||
State<_PageViewItem> createState() => _PageViewItemState(); | ||
} | ||
|
||
class _PageViewItemState extends State<_PageViewItem> | ||
with AutomaticKeepAliveClientMixin { | ||
@override | ||
bool get wantKeepAlive => true; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
super.build(context); | ||
return ListView.builder( | ||
itemCount: 100, | ||
itemBuilder: (context, index) { | ||
return ListTile( | ||
onTap: () {}, | ||
title: Text('Item $index'), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.