fix(ui): fix scroll to bottom logic
This commit is contained in:
+4
-1
@@ -325,9 +325,12 @@ class _PositionedListState extends State<PositionedList> {
|
|||||||
for (final element in registeredElements.value!) {
|
for (final element in registeredElements.value!) {
|
||||||
final box = element.renderObject as RenderBox;
|
final box = element.renderObject as RenderBox;
|
||||||
viewport ??= RenderAbstractViewport.of(box) as RenderViewport?;
|
viewport ??= RenderAbstractViewport.of(box) as RenderViewport?;
|
||||||
|
if (viewport == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
final key = element.widget.key as IndexedKey;
|
final key = element.widget.key as IndexedKey;
|
||||||
if (widget.scrollDirection == Axis.vertical) {
|
if (widget.scrollDirection == Axis.vertical) {
|
||||||
final reveal = viewport!.getOffsetToReveal(box, 0).offset;
|
final reveal = viewport.getOffsetToReveal(box, 0).offset;
|
||||||
if (!reveal.isFinite) continue;
|
if (!reveal.isFinite) continue;
|
||||||
final itemOffset = reveal -
|
final itemOffset = reveal -
|
||||||
viewport.offset.pixels +
|
viewport.offset.pixels +
|
||||||
|
|||||||
-8
@@ -325,14 +325,6 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
|
|||||||
secondary.target = widget.itemCount - 1;
|
secondary.target = widget.itemCount - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.initialScrollIndex != oldWidget.initialScrollIndex ||
|
|
||||||
widget.initialAlignment != oldWidget.initialAlignment) {
|
|
||||||
_jumpTo(
|
|
||||||
index: widget.initialScrollIndex,
|
|
||||||
alignment: widget.initialAlignment,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -465,6 +465,9 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
_inBetweenList = true;
|
_inBetweenList = true;
|
||||||
},
|
},
|
||||||
child: ScrollablePositionedList.separated(
|
child: ScrollablePositionedList.separated(
|
||||||
|
key: (initialIndex != 0 && initialAlignment != 0)
|
||||||
|
? ValueKey('$initialIndex-$initialAlignment')
|
||||||
|
: null,
|
||||||
itemPositionsListener: _itemPositionListener,
|
itemPositionsListener: _itemPositionListener,
|
||||||
initialScrollIndex: initialIndex,
|
initialScrollIndex: initialIndex,
|
||||||
initialAlignment: initialAlignment,
|
initialAlignment: initialAlignment,
|
||||||
@@ -795,13 +798,19 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
children: [
|
children: [
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
backgroundColor: _streamTheme.colorTheme.barsBg,
|
backgroundColor: _streamTheme.colorTheme.barsBg,
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
if (unreadCount > 0) {
|
if (unreadCount > 0) {
|
||||||
streamChannel!.channel.markRead();
|
streamChannel!.channel.markRead();
|
||||||
}
|
}
|
||||||
if (!_upToDate) {
|
if (!_upToDate) {
|
||||||
_bottomPaginationActive = false;
|
_bottomPaginationActive = false;
|
||||||
streamChannel!.reloadChannel();
|
initialAlignment = 0;
|
||||||
|
initialIndex = 0;
|
||||||
|
await streamChannel!.reloadChannel();
|
||||||
|
|
||||||
|
WidgetsBinding.instance?.addPostFrameCallback((_) {
|
||||||
|
_scrollController!.jumpTo(index: 0);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
_showScrollToBottom.value = false;
|
_showScrollToBottom.value = false;
|
||||||
_scrollController!.scrollTo(
|
_scrollController!.scrollTo(
|
||||||
@@ -1057,8 +1066,10 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
final scrollToIndex = () {
|
final scrollToIndex = () {
|
||||||
final index = messages.indexWhere((m) => m.id == quotedMessageId);
|
final index = messages.indexWhere((m) => m.id == quotedMessageId);
|
||||||
_scrollController?.scrollTo(
|
_scrollController?.scrollTo(
|
||||||
index: index,
|
index: index + 2, // +2 to account for loader and footer
|
||||||
duration: const Duration(milliseconds: 350),
|
duration: const Duration(seconds: 1),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
alignment: 0.1,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
if (messages.map((e) => e.id).contains(quotedMessageId)) {
|
if (messages.map((e) => e.id).contains(quotedMessageId)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user