fix tab sheet scroll logic
This commit is contained in:
+20
-22
@@ -456,38 +456,36 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final lastScroll = useRef<String?>(null);
|
final lastScroll = useRef<String?>(null);
|
||||||
final scrollControllerIsAttached = useListenableSelector(
|
|
||||||
sheetScrollController,
|
|
||||||
() => sheetScrollController.hasClients,
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
if (scrollControllerIsAttached) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (lastScroll.value != activeTab) {
|
if (sheetScrollController.hasClients) {
|
||||||
final index = filteredTabEntities.value.indexWhere(
|
if (lastScroll.value != activeTab) {
|
||||||
(entity) => entity.tabId == activeTab,
|
final index = filteredTabEntities.value.indexWhere(
|
||||||
);
|
(entity) => entity.tabId == activeTab,
|
||||||
|
);
|
||||||
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
final offset = (index ~/ 2) * itemHeight;
|
final offset = (index ~/ 2) * itemHeight;
|
||||||
|
|
||||||
if (offset != sheetScrollController.offset) {
|
if (offset != sheetScrollController.offset) {
|
||||||
lastScroll.value = activeTab;
|
lastScroll.value = activeTab;
|
||||||
|
|
||||||
unawaited(
|
unawaited(
|
||||||
sheetScrollController.animateTo(
|
sheetScrollController.animateTo(
|
||||||
offset,
|
offset,
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}, [filteredTabEntities, activeTab, scrollControllerIsAttached]);
|
}, [filteredTabEntities, activeTab]);
|
||||||
|
|
||||||
final tabs = useMemoized(() {
|
final tabs = useMemoized(() {
|
||||||
return [
|
return [
|
||||||
|
|||||||
Reference in New Issue
Block a user