only start timer to end highlight after scroll complete
This commit is contained in:
parent
0fa0f57738
commit
9cd43f4e3c
1 changed files with 14 additions and 1 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import "dart:async";
|
||||
|
||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:flutter_hooks/flutter_hooks.dart";
|
||||
import "package:hooks_riverpod/hooks_riverpod.dart";
|
||||
|
|
@ -26,6 +28,12 @@ final class ChatScroll({
|
|||
final anchorId = useState<int?>(null);
|
||||
final atBottom = useState(true);
|
||||
final pendingJump = useState<int?>(null);
|
||||
final pendingJumpDone = useRef<Completer<void>?>(null);
|
||||
void finishPendingJump() {
|
||||
pendingJumpDone.value?.complete();
|
||||
pendingJumpDone.value = null;
|
||||
}
|
||||
|
||||
final scrollController = useScrollController();
|
||||
final centerKey = useMemoized(GlobalKey.new);
|
||||
|
||||
|
|
@ -52,7 +60,7 @@ final class ChatScroll({
|
|||
pendingJump.value = null;
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
if (!scrollController.hasClients) return;
|
||||
if (!scrollController.hasClients) return finishPendingJump();
|
||||
|
||||
final position = scrollController.position;
|
||||
scrollController.jumpTo(
|
||||
|
|
@ -71,6 +79,7 @@ final class ChatScroll({
|
|||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
finishPendingJump();
|
||||
});
|
||||
|
||||
return null;
|
||||
|
|
@ -185,6 +194,8 @@ final class ChatScroll({
|
|||
return;
|
||||
}
|
||||
|
||||
finishPendingJump();
|
||||
final done = pendingJumpDone.value = Completer();
|
||||
pendingJump.value = rowId;
|
||||
if (controllerData.value?.timeline.contains(rowId) ?? false) {
|
||||
anchorId.value = rowId;
|
||||
|
|
@ -192,8 +203,10 @@ final class ChatScroll({
|
|||
anchorId.value = null;
|
||||
contextualEvent.value = rowId;
|
||||
}
|
||||
await done.future;
|
||||
},
|
||||
jumpToBottom: () async {
|
||||
finishPendingJump();
|
||||
if (contextualEvent.value != null) {
|
||||
anchorId.value = null;
|
||||
contextualEvent.value = null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue