Merge pull request #1213 from GetStream/feature/openToUnread
feat(ui): open message list to unread position
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
color of pinned messages.
|
color of pinned messages.
|
||||||
- Added unread messages divider in `StreamMessageListView`.
|
- Added unread messages divider in `StreamMessageListView`.
|
||||||
- Added `StreamMessageListView.unreadMessagesSeparatorBuilder`.
|
- Added `StreamMessageListView.unreadMessagesSeparatorBuilder`.
|
||||||
|
- Now `StreamMessageListView` opens to the oldest unread message by default.
|
||||||
|
|
||||||
## 4.2.0
|
## 4.2.0
|
||||||
|
|
||||||
|
|||||||
@@ -387,6 +387,11 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
if (index != 0) return index + 1;
|
if (index != 0) return index + 1;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unreadCount > 0) {
|
||||||
|
return unreadCount + 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -932,6 +937,9 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
if (unreadCount > 0) {
|
if (unreadCount > 0) {
|
||||||
streamChannel!.channel.markRead();
|
streamChannel!.channel.markRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final index = unreadCount > 0 ? unreadCount + 1 : 0;
|
||||||
|
|
||||||
if (!_upToDate) {
|
if (!_upToDate) {
|
||||||
_bottomPaginationActive = false;
|
_bottomPaginationActive = false;
|
||||||
initialAlignment = 0;
|
initialAlignment = 0;
|
||||||
@@ -939,11 +947,11 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
await streamChannel!.reloadChannel();
|
await streamChannel!.reloadChannel();
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_scrollController!.jumpTo(index: unreadCount);
|
_scrollController!.jumpTo(index: index);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
_scrollController!.scrollTo(
|
_scrollController!.scrollTo(
|
||||||
index: unreadCount,
|
index: index,
|
||||||
duration: const Duration(seconds: 1),
|
duration: const Duration(seconds: 1),
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
);
|
);
|
||||||
@@ -1366,6 +1374,8 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
if (newStreamChannel != streamChannel) {
|
if (newStreamChannel != streamChannel) {
|
||||||
streamChannel = newStreamChannel;
|
streamChannel = newStreamChannel;
|
||||||
_messageNewListener?.cancel();
|
_messageNewListener?.cancel();
|
||||||
|
|
||||||
|
unreadCount = streamChannel?.channel.state?.unreadCount ?? 0;
|
||||||
initialIndex = _initialIndex;
|
initialIndex = _initialIndex;
|
||||||
initialAlignment = _initialAlignment;
|
initialAlignment = _initialAlignment;
|
||||||
|
|
||||||
@@ -1377,7 +1387,10 @@ class _StreamMessageListViewState extends State<StreamMessageListView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_messageNewListener =
|
_messageNewListener =
|
||||||
streamChannel!.channel.on(EventType.messageNew).listen((event) {
|
streamChannel!.channel.on(EventType.messageNew).skip(1)
|
||||||
|
//skipping the first event because
|
||||||
|
//the StreamController is a BehaviorSubject
|
||||||
|
.listen((event) {
|
||||||
if (_upToDate) {
|
if (_upToDate) {
|
||||||
_bottomPaginationActive = false;
|
_bottomPaginationActive = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user