From 02e5069c687c6d1f60e514c51018f03203c0cf6d Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 1 Nov 2022 23:25:57 -0500 Subject: [PATCH] Add a way to toggle scrollToBottom so you can start scroll from the top as well and continue reading See `?continue=top` in https://github.com/matrix-org/matrix-public-archive/pull/114 for how this is used --- doc/SDK.md | 2 +- src/platform/web/ui/session/room/RoomView.js | 2 +- src/platform/web/ui/session/room/TimelineView.ts | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/SDK.md b/doc/SDK.md index c8f5197fc1..d7286deb5f 100644 --- a/doc/SDK.md +++ b/doc/SDK.md @@ -89,7 +89,7 @@ async function main() { navigation, }); await vm.load(); - const view = new TimelineView(vm.timelineViewModel, viewClassForTile); + const view = new TimelineView(vm.timelineViewModel, { viewClassForTile }); app.appendChild(view.mount()); } } diff --git a/src/platform/web/ui/session/room/RoomView.js b/src/platform/web/ui/session/room/RoomView.js index e3eb058707..dde5dc385a 100644 --- a/src/platform/web/ui/session/room/RoomView.js +++ b/src/platform/web/ui/session/room/RoomView.js @@ -55,7 +55,7 @@ export class RoomView extends TemplateView { )]), t.mapView(vm => vm.timelineViewModel, timelineViewModel => { return timelineViewModel ? - new TimelineView(timelineViewModel, this._viewClassForTile) : + new TimelineView(timelineViewModel, { viewClassForTile: this._viewClassForTile }) : new TimelineLoadingView(vm); // vm is just needed for i18n }), t.mapView(vm => vm.composerViewModel, diff --git a/src/platform/web/ui/session/room/TimelineView.ts b/src/platform/web/ui/session/room/TimelineView.ts index 5a04991fba..50e665d5cf 100644 --- a/src/platform/web/ui/session/room/TimelineView.ts +++ b/src/platform/web/ui/session/room/TimelineView.ts @@ -57,6 +57,10 @@ function findFirstNodeIndexAtOrBelow(tiles: HTMLElement, top: number, startIndex return 0; } +interface TimelineViewOpts { + viewClassForTile: ViewClassForEntryFn + stickToBottom: boolean +} export class TimelineView extends TemplateView { private anchoredNode?: HTMLElement; @@ -64,9 +68,16 @@ export class TimelineView extends TemplateView { private stickToBottom: boolean = true; private tilesView?: TilesListView; private resizeObserver?: ResizeObserver; + private viewClassForTile: ViewClassForEntryFn; - constructor(vm: TimelineViewModel, private readonly viewClassForTile: ViewClassForEntryFn) { + constructor(vm: TimelineViewModel, { + viewClassForTile, + stickToBottom = true + }: TimelineViewOpts) { super(vm); + + this.viewClassForTile = viewClassForTile; + this.stickToBottom = stickToBottom; } render(t: Builder, vm: TimelineViewModel) {