From 1dbe943f11a14e122900407d75f1ef774b0fbebb Mon Sep 17 00:00:00 2001 From: Fabian Freund Date: Sun, 20 Jul 2025 12:17:51 +0200 Subject: [PATCH] wait for scroll controller attachment --- .../widgets/sheets/view_tabs.dart | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/app/lib/features/geckoview/features/browser/presentation/widgets/sheets/view_tabs.dart b/app/lib/features/geckoview/features/browser/presentation/widgets/sheets/view_tabs.dart index c7405474..0bc4d40e 100644 --- a/app/lib/features/geckoview/features/browser/presentation/widgets/sheets/view_tabs.dart +++ b/app/lib/features/geckoview/features/browser/presentation/widgets/sheets/view_tabs.dart @@ -346,31 +346,45 @@ class ViewTabsSheetWidget extends HookConsumerWidget { ); final lastScroll = useRef(null); - useEffect(() { - if (lastScroll.value != activeTab) { - final index = filteredTabEntities.value.indexWhere( - (entity) => entity.tabId == activeTab, - ); + final scrollControllerIsAttached = useListenableSelector( + sheetScrollController, + () => sheetScrollController.hasClients, + ); - if (index > -1) { - final offset = (index ~/ 2) * itemHeight; - - if (offset != sheetScrollController.offset) { - lastScroll.value = activeTab; - - unawaited( - sheetScrollController.animateTo( - offset, - duration: const Duration(milliseconds: 200), - curve: Curves.easeInOut, - ), + useEffect( + () { + if (scrollControllerIsAttached) { + if (lastScroll.value != activeTab) { + final index = filteredTabEntities.value.indexWhere( + (entity) => entity.tabId == activeTab, ); + + if (index > -1) { + final offset = (index ~/ 2) * itemHeight; + + if (offset != sheetScrollController.offset) { + lastScroll.value = activeTab; + + unawaited( + sheetScrollController.animateTo( + offset, + duration: const Duration(milliseconds: 200), + curve: Curves.easeInOut, + ), + ); + } + } } } - } - return null; - }, [filteredTabEntities, activeTab]); + return null; + }, + [ + filteredTabEntities, + activeTab, + scrollControllerIsAttached, + ], + ); final tabs = useMemoized(() { return filteredTabEntities.value @@ -391,7 +405,7 @@ class ViewTabsSheetWidget extends HookConsumerWidget { return Padding( padding: const EdgeInsets.symmetric(horizontal: 4.0), child: FadingScroll( - fadingSize: 10, + fadingSize: 5, controller: sheetScrollController, builder: (context, controller) { return ReorderableBuilder.builder(