avoid unnecessary scrolling
This commit is contained in:
+38
-29
@@ -352,22 +352,27 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
[MediaQuery.of(context).size.width, crossAxisCount],
|
[MediaQuery.of(context).size.width, crossAxisCount],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final lastScroll = useRef<String?>(null);
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
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) {
|
||||||
unawaited(
|
lastScroll.value = activeTab;
|
||||||
sheetScrollController.animateTo(
|
|
||||||
offset,
|
unawaited(
|
||||||
duration: const Duration(milliseconds: 200),
|
sheetScrollController.animateTo(
|
||||||
curve: Curves.easeInOut,
|
offset,
|
||||||
),
|
duration: const Duration(milliseconds: 200),
|
||||||
);
|
curve: Curves.easeInOut,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,7 +545,7 @@ class ViewTabTreesSheetWidget extends HookConsumerWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: HookConsumer(
|
child: HookConsumer(
|
||||||
builder: (context, ref, child) {
|
builder: (context, ref, child) {
|
||||||
final filteredTabIds = ref.watch(
|
final filteredTabEntities = ref.watch(
|
||||||
seamlessFilteredTabEntitiesProvider(
|
seamlessFilteredTabEntitiesProvider(
|
||||||
searchPartition: TabSearchPartition.preview,
|
searchPartition: TabSearchPartition.preview,
|
||||||
// ignore: document_ignores using fast equatable
|
// ignore: document_ignores using fast equatable
|
||||||
@@ -561,13 +566,16 @@ class ViewTabTreesSheetWidget extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return math.max(
|
return math.max(
|
||||||
math.min(calculatedCount, filteredTabIds.value.length),
|
math.min(
|
||||||
|
calculatedCount,
|
||||||
|
filteredTabEntities.value.length,
|
||||||
|
),
|
||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
MediaQuery.of(context).size.width,
|
MediaQuery.of(context).size.width,
|
||||||
filteredTabIds.value.length,
|
filteredTabEntities.value.length,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -586,7 +594,7 @@ class ViewTabTreesSheetWidget extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
final index = filteredTabIds.value.indexWhere(
|
final index = filteredTabEntities.value.indexWhere(
|
||||||
(entity) => entity.tabId == activeTab,
|
(entity) => entity.tabId == activeTab,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -605,20 +613,21 @@ class ViewTabTreesSheetWidget extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}, [filteredTabIds, activeTab]);
|
}, [filteredTabEntities, activeTab]);
|
||||||
|
|
||||||
final tabs = useMemoized(() {
|
final tabs = useMemoized(() {
|
||||||
return filteredTabIds.value.whereType<TabTreeEntity>().map((
|
return filteredTabEntities.value
|
||||||
entity,
|
.whereType<TabTreeEntity>()
|
||||||
) {
|
.map((entity) {
|
||||||
return TabTreePreview(
|
return TabTreePreview(
|
||||||
entity: entity,
|
entity: entity,
|
||||||
activeTabId: activeTab,
|
activeTabId: activeTab,
|
||||||
onClose: onClose,
|
onClose: onClose,
|
||||||
stackPadding: const Offset(8, 8),
|
stackPadding: const Offset(8, 8),
|
||||||
);
|
);
|
||||||
}).toList();
|
})
|
||||||
}, [filteredTabIds, activeTab]);
|
.toList();
|
||||||
|
}, [filteredTabEntities, activeTab]);
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
|
|||||||
Reference in New Issue
Block a user