Skip to content

Commit e037e11

Browse files
authored
Merge pull request #1011 from AppFlowy-IO/fix/grid_scroll_bar_listener
fix: listen on the scroll position changed after widget was dpated
2 parents d770003 + fa73900 commit e037e11

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/scrolling/styled_scroll_bar.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ class StyledScrollbar extends StatefulWidget {
1717
final bool autoHideScrollbar;
1818
final Color? handleColor;
1919
final Color? trackColor;
20-
21-
// ignore: todo
22-
// TODO: Remove contentHeight if we can fix this issue
23-
// https://stackoverflow.com/questions/60855712/flutter-how-to-force-scrollcontroller-to-recalculate-position-maxextents
2420
final double? contentSize;
2521

2622
const StyledScrollbar(
@@ -48,25 +44,7 @@ class ScrollbarState extends State<StyledScrollbar> {
4844
@override
4945
void initState() {
5046
widget.controller.addListener(() => setState(() {}));
51-
widget.controller.position.isScrollingNotifier.addListener(
52-
() {
53-
if (!mounted) return;
54-
if (!widget.autoHideScrollbar) return;
55-
_hideScrollbarOperation?.cancel();
56-
if (!widget.controller.position.isScrollingNotifier.value) {
57-
_hideScrollbarOperation = CancelableOperation.fromFuture(
58-
Future.delayed(const Duration(seconds: 2), () {}),
59-
).then((_) {
60-
hideHandler = true;
61-
if (mounted) {
62-
setState(() {});
63-
}
64-
});
65-
} else {
66-
hideHandler = false;
67-
}
68-
},
69-
);
47+
_listenOnScrollPositionChanged();
7048
super.initState();
7149
}
7250

@@ -77,6 +55,7 @@ class ScrollbarState extends State<StyledScrollbar> {
7755

7856
@override
7957
void didUpdateWidget(StyledScrollbar oldWidget) {
58+
_listenOnScrollPositionChanged();
8059
if (oldWidget.contentSize != widget.contentSize) setState(() {});
8160
super.didUpdateWidget(oldWidget);
8261
}
@@ -210,6 +189,27 @@ class ScrollbarState extends State<StyledScrollbar> {
210189
.clamp(0.0, widget.controller.position.maxScrollExtent));
211190
widget.onDrag?.call(details.delta.dy);
212191
}
192+
193+
void _listenOnScrollPositionChanged() {
194+
widget.controller.position.isScrollingNotifier.addListener(
195+
() {
196+
if (!mounted) return;
197+
if (!widget.autoHideScrollbar) return;
198+
199+
_hideScrollbarOperation?.cancel();
200+
if (!widget.controller.position.isScrollingNotifier.value) {
201+
_hideScrollbarOperation = CancelableOperation.fromFuture(
202+
Future.delayed(const Duration(seconds: 2), () {}),
203+
).then((_) {
204+
hideHandler = true;
205+
if (mounted) setState(() {});
206+
});
207+
} else {
208+
hideHandler = false;
209+
}
210+
},
211+
);
212+
}
213213
}
214214

215215
class ScrollbarListStack extends StatelessWidget {

frontend/app_flowy/packages/flowy_infra_ui/lib/style_widget/scrolling/styled_scrollview.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class StyledSingleChildScrollViewState
4343

4444
@override
4545
void dispose() {
46-
// scrollController.dispose();
46+
if (widget.controller == null) {
47+
scrollController.dispose();
48+
}
4749
super.dispose();
4850
}
4951

@@ -109,6 +111,9 @@ class StyledCustomScrollViewState extends State<StyledCustomScrollView> {
109111

110112
@override
111113
void dispose() {
114+
if (widget.verticalController == null) {
115+
controller.dispose();
116+
}
112117
super.dispose();
113118
}
114119

0 commit comments

Comments
 (0)