Skip to content

Commit

Permalink
Add a way to toggle scrollToBottom so you can start scroll from the t…
Browse files Browse the repository at this point in the history
…op as well and continue reading

See `?continue=top` in matrix-org/matrix-viewer#114 for how this is used
  • Loading branch information
MadLittleMods committed Nov 2, 2022
1 parent 4e3f397 commit 5fdbe61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/SDK.md
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/web/ui/session/room/RoomView.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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,
Expand Down
13 changes: 12 additions & 1 deletion src/platform/web/ui/session/room/TimelineView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,27 @@ function findFirstNodeIndexAtOrBelow(tiles: HTMLElement, top: number, startIndex
return 0;
}

interface TimelineViewOpts {
viewClassForTile: ViewClassForEntryFn
stickToBottom: boolean
}
export class TimelineView extends TemplateView<TimelineViewModel> {

private anchoredNode?: HTMLElement;
private anchoredBottom: number = 0;
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<TimelineViewModel>, vm: TimelineViewModel) {
Expand Down

0 comments on commit 5fdbe61

Please sign in to comment.