Skip to content

Commit 96b81dc

Browse files
committed
msglist [nfc]: Introduce MessageListScrollPosition
1 parent 92676fd commit 96b81dc

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/widgets/message_list.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class MessageList extends StatefulWidget {
466466

467467
class _MessageListState extends State<MessageList> with PerAccountStoreAwareStateMixin<MessageList> {
468468
MessageListView? model;
469-
final ScrollController scrollController = ScrollController();
469+
final ScrollController scrollController = MessageListScrollController();
470470
final ValueNotifier<bool> _scrollToBottomVisibleValue = ValueNotifier<bool>(false);
471471

472472
@override

lib/widgets/scrolling.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,43 @@ class RenderCustomPaintOrderViewport extends RenderViewport {
248248
}
249249
}
250250

251+
/// A version of [ScrollPosition] adapted for the Zulip message list,
252+
/// used by [MessageListScrollController].
253+
class MessageListScrollPosition extends ScrollPositionWithSingleContext {
254+
MessageListScrollPosition({
255+
required super.physics,
256+
required super.context,
257+
super.initialPixels,
258+
super.keepScrollOffset,
259+
super.oldPosition,
260+
super.debugLabel,
261+
});
262+
}
263+
264+
/// A version of [ScrollController] adapted for the Zulip message list.
265+
class MessageListScrollController extends ScrollController {
266+
MessageListScrollController({
267+
super.initialScrollOffset,
268+
super.keepScrollOffset,
269+
super.debugLabel,
270+
super.onAttach,
271+
super.onDetach,
272+
});
273+
274+
@override
275+
ScrollPosition createScrollPosition(ScrollPhysics physics,
276+
ScrollContext context, ScrollPosition? oldPosition) {
277+
return MessageListScrollPosition(
278+
physics: physics,
279+
context: context,
280+
initialPixels: initialScrollOffset,
281+
keepScrollOffset: keepScrollOffset,
282+
oldPosition: oldPosition,
283+
debugLabel: debugLabel,
284+
);
285+
}
286+
}
287+
251288
/// A version of [CustomScrollView] adapted for the Zulip message list.
252289
///
253290
/// This lets us customize behavior in ways that aren't currently supported

0 commit comments

Comments
 (0)