Skip to content

Commit

Permalink
wip; nav: Disable bottom sheet dragging when scrolled
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan James Li <zixuan@zulip.com>
  • Loading branch information
PIG208 committed Nov 23, 2024
1 parent 3ecca15 commit 5c927c1
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions lib/widgets/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,28 @@ class _HomePageState extends State<HomePage> {
}
}

void showMenu(BuildContext context) {
const Duration _bottomSheetEnterDuration = Duration(milliseconds: 250);
const Duration _bottomSheetExitDuration = Duration(milliseconds: 200);

class _PausableAnimationController extends AnimationController {
_PausableAnimationController({
required super.vsync,
super.duration,
super.reverseDuration,
});

bool paused = false;

@override
set value(double newValue) {
if (paused) {
return;
}
super.value = (newValue);
}
}

void showMenu(BuildContext context) async {
final store = PerAccountStoreWidget.of(context);
final designVariables = DesignVariables.of(context);
final menuItems = <Widget>[
Expand Down Expand Up @@ -127,8 +148,16 @@ void showMenu(BuildContext context) {
const SizedBox(height: 8),
const _VersionInfo(),
];

showModalBottomSheet<void>(
final animationController = _PausableAnimationController(
vsync: Navigator.of(context),
duration: _bottomSheetEnterDuration,
reverseDuration: _bottomSheetExitDuration,
);
bool handleScroll(ScrollNotification notification) {
animationController.paused = notification.metrics.extentBefore != 0;
return false;
}
await showModalBottomSheet<void>(
context: context,
// Clip.hardEdge looks bad; Clip.antiAliasWithSaveLayer looks pixel-perfect
// on my iPhone 13 Pro but is marked as "much slower":
Expand All @@ -137,6 +166,7 @@ void showMenu(BuildContext context) {
useSafeArea: true,
isScrollControlled: true,
backgroundColor: designVariables.bgBotBar,
transitionAnimationController: animationController,
builder: (BuildContext _) {
return SafeArea(
minimum: const EdgeInsets.only(bottom: 8),
Expand All @@ -148,18 +178,24 @@ void showMenu(BuildContext context) {
Expanded(child: InsetShadowBox(
top: 8, bottom: 8,
color: designVariables.bgBotBar,
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: menuItems)))),
child: NotificationListener<ScrollNotification>(
onNotification: handleScroll,
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: menuItems))))),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Scaled(
scaleEnd: 0.95,
duration: Duration(milliseconds: 100),
child: SizedBox(height: 44, child: ActionSheetCancelButton()))),
]));
}).whenComplete(() {
// See [TransitionRoute.didPop].
animationController.paused = false;
animationController.reverse().whenComplete(() => animationController.dispose());
});
}

Expand Down

0 comments on commit 5c927c1

Please sign in to comment.