wait for scroll controller attachment
This commit is contained in:
+35
-21
@@ -346,31 +346,45 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final lastScroll = useRef<String?>(null);
|
final lastScroll = useRef<String?>(null);
|
||||||
useEffect(() {
|
final scrollControllerIsAttached = useListenableSelector(
|
||||||
if (lastScroll.value != activeTab) {
|
sheetScrollController,
|
||||||
final index = filteredTabEntities.value.indexWhere(
|
() => sheetScrollController.hasClients,
|
||||||
(entity) => entity.tabId == activeTab,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
if (index > -1) {
|
useEffect(
|
||||||
final offset = (index ~/ 2) * itemHeight;
|
() {
|
||||||
|
if (scrollControllerIsAttached) {
|
||||||
if (offset != sheetScrollController.offset) {
|
if (lastScroll.value != activeTab) {
|
||||||
lastScroll.value = activeTab;
|
final index = filteredTabEntities.value.indexWhere(
|
||||||
|
(entity) => entity.tabId == activeTab,
|
||||||
unawaited(
|
|
||||||
sheetScrollController.animateTo(
|
|
||||||
offset,
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
curve: Curves.easeInOut,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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;
|
return null;
|
||||||
}, [filteredTabEntities, activeTab]);
|
},
|
||||||
|
[
|
||||||
|
filteredTabEntities,
|
||||||
|
activeTab,
|
||||||
|
scrollControllerIsAttached,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
final tabs = useMemoized(() {
|
final tabs = useMemoized(() {
|
||||||
return filteredTabEntities.value
|
return filteredTabEntities.value
|
||||||
@@ -391,7 +405,7 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
child: FadingScroll(
|
child: FadingScroll(
|
||||||
fadingSize: 10,
|
fadingSize: 5,
|
||||||
controller: sheetScrollController,
|
controller: sheetScrollController,
|
||||||
builder: (context, controller) {
|
builder: (context, controller) {
|
||||||
return ReorderableBuilder.builder(
|
return ReorderableBuilder.builder(
|
||||||
|
|||||||
Reference in New Issue
Block a user