do not reverse the scrollview
This commit is contained in:
parent
d2ec5f035b
commit
29157c7252
2 changed files with 44 additions and 29 deletions
|
|
@ -38,16 +38,11 @@ class RoomChatController extends AsyncNotifier<IList<Event>> {
|
|||
loadOlder();
|
||||
}
|
||||
|
||||
return IMap<int, int?>.fromValues(
|
||||
keyMapper: (id) => 9999999999 + (id ?? 0),
|
||||
values: room.sticky,
|
||||
)
|
||||
.addAll(room.timeline)
|
||||
.toEntryIList(compare: (a, b) => (b?.key ?? 0).compareTo(a?.key ?? 0))
|
||||
return room.timeline
|
||||
.toValueIList(sort: true, compare: (a, b) => (a ?? 0).compareTo(b ?? 0))
|
||||
.addAll(room.sticky)
|
||||
.map((entry) {
|
||||
final foundEvent = entry.value == null
|
||||
? null
|
||||
: room.events[entry.value!];
|
||||
final foundEvent = entry == null ? null : room.events[entry];
|
||||
|
||||
final editedEvent =
|
||||
foundEvent == null || foundEvent.lastEditRowId == 0
|
||||
|
|
|
|||
|
|
@ -77,6 +77,29 @@ class RoomChat extends HookConsumerWidget {
|
|||
|
||||
final listController = useRef(ListController());
|
||||
final scrollController = useScrollController();
|
||||
final controllerData = ref.watch(controllerProvider);
|
||||
|
||||
useEffect(() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (scrollController.hasClients) {
|
||||
scrollController.jumpTo(scrollController.position.maxScrollExtent);
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}, [scrollController.hasClients]);
|
||||
|
||||
useEffect(() {
|
||||
if (scrollController.position.atEdge &&
|
||||
scrollController.position.pixels != 0) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (scrollController.hasClients) {
|
||||
scrollController.jumpTo(scrollController.position.maxScrollExtent);
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}, [controllerData]);
|
||||
|
||||
useEffect(() {
|
||||
Future<void> listener() async {
|
||||
|
|
@ -88,9 +111,9 @@ class RoomChat extends HookConsumerWidget {
|
|||
if (room == null) return;
|
||||
|
||||
if (scrollController.position.pixels == 0) {
|
||||
await client.markRead(room);
|
||||
} else {
|
||||
if (room.hasMore) await notifier.loadOlder();
|
||||
} else {
|
||||
await client.markRead(room);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -316,8 +339,6 @@ class RoomChat extends HookConsumerWidget {
|
|||
].toIList();
|
||||
}
|
||||
|
||||
final controllerData = ref.watch(controllerProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: RoomAppbar(
|
||||
roomId: roomId,
|
||||
|
|
@ -339,11 +360,20 @@ class RoomChat extends HookConsumerWidget {
|
|||
child: switch (controllerData) {
|
||||
AsyncData(:final value) ||
|
||||
AsyncLoading(:final value?) => CustomScrollView(
|
||||
reverse: true,
|
||||
controller: scrollController,
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: .only(bottom: composerSize.value),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: .symmetric(vertical: 36),
|
||||
child: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: controllerData is AsyncData
|
||||
? notifier.loadOlder
|
||||
: null,
|
||||
child: Text("Load More"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SuperSliverList.builder(
|
||||
|
|
@ -351,7 +381,7 @@ class RoomChat extends HookConsumerWidget {
|
|||
itemCount: value.length,
|
||||
itemBuilder: (_, index) {
|
||||
final event = value[index];
|
||||
final previousEvent = value.getOrNull(index + 1);
|
||||
final previousEvent = value.getOrNull(index - 1);
|
||||
return FlashWrapper(
|
||||
EventRenderer(
|
||||
event,
|
||||
|
|
@ -389,18 +419,8 @@ class RoomChat extends HookConsumerWidget {
|
|||
},
|
||||
),
|
||||
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: .symmetric(vertical: 36),
|
||||
child: Center(
|
||||
child: controllerData is AsyncLoading
|
||||
? Loading()
|
||||
: ElevatedButton(
|
||||
onPressed: notifier.loadOlder,
|
||||
child: Text("Load More"),
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: .only(bottom: composerSize.value),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue