From 3217c17ea01e61ecd3ab79a89d55532819a40fc3 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Sat, 26 Sep 2026 13:58:30 -0400 Subject: [PATCH] don't depend on SuperSliverList for scrolls --- lib/helpers/hooks/chat_scroll.dart | 51 ++++++------------------ lib/widgets/room_chat/chat_timeline.dart | 2 - 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/lib/helpers/hooks/chat_scroll.dart b/lib/helpers/hooks/chat_scroll.dart index e1fbf9f..f278385 100644 --- a/lib/helpers/hooks/chat_scroll.dart +++ b/lib/helpers/hooks/chat_scroll.dart @@ -7,15 +7,12 @@ import "package:material_ui/material_ui.dart"; import "package:nexus/models/direction.dart"; import "package:nexus/models/event.dart"; import "package:nexus/models/room_chat.dart"; -import "package:super_sliver_list/super_sliver_list.dart"; final class ChatScroll({ required final IList historyItems, required final IList liveItems, required final GlobalKey centerKey, required final GlobalKey anchorItemKey, - required final ListController historyListController, - required final ListController liveListController, required final ScrollController scrollController, required final bool atBottom, required final Future Function(String id) jumpToId, @@ -31,8 +28,6 @@ final class ChatScroll({ final anchorItemKey = useMemoized(GlobalKey.new, [anchorId.value]); - final historyListController = useMemoized(ListController.new); - final liveListController = useMemoized(ListController.new); final scrollController = useScrollController(); final centerKey = useMemoized(GlobalKey.new); @@ -156,47 +151,29 @@ final class ChatScroll({ ], ); - double? resolveOffset(String itemId) { - final historyIndex = split.history.indexWhere( - (item) => item.eventId == itemId, - ); - if (historyIndex != -1) { - // TODO: Replace SuperSliverView because of the bug that requires this: #94 - // ignore: invalid_use_of_visible_for_testing_member - return historyListController.getOffsetToReveal(historyIndex, 0.5); - } - - final liveIndex = split.live.indexWhere((item) => item.eventId == itemId); - if (liveIndex != -1) { - // ignore: invalid_use_of_visible_for_testing_member - return liveListController.getOffsetToReveal(liveIndex, 0.5); - } - - return null; - } - Future jumpToId(String itemId) async { if (!scrollController.hasClients) return; - final offset = resolveOffset(itemId); + if (anchorId.value != itemId) { + final completer = Completer(); + anchorMountedCompleter.value = completer; + pendingAnchorTarget.value = itemId; + contextualEvent.value = itemId; - if (offset != null) { - await scrollController.animateTo( - offset, + final context = await completer.future; + if (!context.mounted) return; + + await Scrollable.ensureVisible( + context, + alignment: 0.5, duration: const .new(milliseconds: 700), curve: Curves.easeInOut, ); return; } - final completer = Completer(); - anchorMountedCompleter.value = completer; - pendingAnchorTarget.value = itemId; - contextualEvent.value = itemId; - - final context = await completer.future; - - if (context.mounted) { + final context = anchorItemKey.currentContext; + if (context != null && context.mounted) { await Scrollable.ensureVisible( context, alignment: 0.5, @@ -226,8 +203,6 @@ final class ChatScroll({ liveItems: split.live, centerKey: centerKey, anchorItemKey: anchorItemKey, - historyListController: historyListController, - liveListController: liveListController, scrollController: scrollController, atBottom: atBottom.value, jumpToId: jumpToId, diff --git a/lib/widgets/room_chat/chat_timeline.dart b/lib/widgets/room_chat/chat_timeline.dart index 77164c4..049a09d 100644 --- a/lib/widgets/room_chat/chat_timeline.dart +++ b/lib/widgets/room_chat/chat_timeline.dart @@ -50,7 +50,6 @@ class const ChatTimeline({ SliverToBoxAdapter(child: SizedBox(height: composerHeight)), SuperSliverList.builder( - listController: scroll.liveListController, itemCount: scroll.liveItems.length, itemBuilder: (_, index) => eventRow( scroll.liveItems[index], @@ -68,7 +67,6 @@ class const ChatTimeline({ SuperSliverList.builder( key: scroll.centerKey, - listController: scroll.historyListController, itemCount: scroll.historyItems.length, itemBuilder: (_, index) => eventRow( scroll.historyItems[index],