Skip to content

Commit eb8c896

Browse files
committed
wip; nav: Disable bottom sheet dragging when scrolled
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 24a7abb commit eb8c896

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

lib/widgets/home.dart

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,28 @@ class _HomePageState extends State<HomePage> {
8989
}
9090
}
9191

92-
void showMenu(BuildContext context) {
92+
const Duration _bottomSheetEnterDuration = Duration(milliseconds: 250);
93+
const Duration _bottomSheetExitDuration = Duration(milliseconds: 200);
94+
95+
class _PausableAnimationController extends AnimationController {
96+
_PausableAnimationController({
97+
required super.vsync,
98+
super.duration,
99+
super.reverseDuration,
100+
});
101+
102+
bool paused = false;
103+
104+
@override
105+
set value(double newValue) {
106+
if (paused) {
107+
return;
108+
}
109+
super.value = (newValue);
110+
}
111+
}
112+
113+
void showMenu(BuildContext context) async {
93114
final store = PerAccountStoreWidget.of(context);
94115
final designVariables = DesignVariables.of(context);
95116
final menuItems = <Widget>[
@@ -127,8 +148,16 @@ void showMenu(BuildContext context) {
127148
const SizedBox(height: 8),
128149
const _VersionInfo(),
129150
];
130-
131-
showModalBottomSheet<void>(
151+
final animationController = _PausableAnimationController(
152+
vsync: Navigator.of(context),
153+
duration: _bottomSheetEnterDuration,
154+
reverseDuration: _bottomSheetExitDuration,
155+
);
156+
bool handleScroll(ScrollNotification notification) {
157+
animationController.paused = notification.metrics.extentBefore != 0;
158+
return false;
159+
}
160+
await showModalBottomSheet<void>(
132161
context: context,
133162
// Clip.hardEdge looks bad; Clip.antiAliasWithSaveLayer looks pixel-perfect
134163
// on my iPhone 13 Pro but is marked as "much slower":
@@ -137,6 +166,7 @@ void showMenu(BuildContext context) {
137166
useSafeArea: true,
138167
isScrollControlled: true,
139168
backgroundColor: designVariables.bgBotBar,
169+
transitionAnimationController: animationController,
140170
builder: (BuildContext _) {
141171
return SafeArea(
142172
minimum: const EdgeInsets.only(bottom: 8),
@@ -148,18 +178,24 @@ void showMenu(BuildContext context) {
148178
Expanded(child: InsetShadowBox(
149179
top: 8, bottom: 8,
150180
color: designVariables.bgBotBar,
151-
child: SingleChildScrollView(
152-
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
153-
child: Column(
154-
mainAxisAlignment: MainAxisAlignment.start,
155-
children: menuItems)))),
181+
child: NotificationListener<ScrollNotification>(
182+
onNotification: handleScroll,
183+
child: SingleChildScrollView(
184+
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
185+
child: Column(
186+
mainAxisAlignment: MainAxisAlignment.start,
187+
children: menuItems))))),
156188
const Padding(
157189
padding: EdgeInsets.symmetric(horizontal: 16),
158190
child: Scaled(
159191
scaleEnd: 0.95,
160192
duration: Duration(milliseconds: 100),
161193
child: SizedBox(height: 44, child: ActionSheetCancelButton()))),
162194
]));
195+
}).whenComplete(() {
196+
// See [TransitionRoute.didPop].
197+
animationController.paused = false;
198+
animationController.reverse().whenComplete(() => animationController.dispose());
163199
});
164200
}
165201

0 commit comments

Comments
 (0)