mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
Fix infinite scrolling
This commit is contained in:
parent
ba8751bb75
commit
9f37196eb7
@ -70,8 +70,8 @@ module.exports = React.createClass({
|
|||||||
<RoomHeader room={this.state.room} />
|
<RoomHeader room={this.state.room} />
|
||||||
<div className="mx_RoomView_roomWrapper">
|
<div className="mx_RoomView_roomWrapper">
|
||||||
<div className="mx_RoomView_messagePanel">
|
<div className="mx_RoomView_messagePanel">
|
||||||
<div className="mx_RoomView_messageListWrapper">
|
<div ref="messageWrapper" className="mx_RoomView_messageListWrapper" onScroll={this.onMessageListScroll}>
|
||||||
<div className="mx_RoomView_MessageList" ref="messageList" aria-live="polite" onScroll={this.onMessageListScroll}>
|
<div className="mx_RoomView_MessageList" aria-live="polite">
|
||||||
<div className={scrollheader_classes}>
|
<div className={scrollheader_classes}>
|
||||||
</div>
|
</div>
|
||||||
{this.getEventTiles()}
|
{this.getEventTiles()}
|
||||||
|
@ -46,6 +46,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
|
if (this.refs.messageWrapper) {
|
||||||
|
var messageWrapper = this.refs.messageWrapper.getDOMNode();
|
||||||
|
messageWrapper.removeEventListener('drop', this.handleDrop);
|
||||||
|
}
|
||||||
dis.unregister(this.dispatcherRef);
|
dis.unregister(this.dispatcherRef);
|
||||||
if (MatrixClientPeg.get()) {
|
if (MatrixClientPeg.get()) {
|
||||||
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
|
MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline);
|
||||||
@ -82,9 +86,9 @@ module.exports = {
|
|||||||
if (this.state.joining) return;
|
if (this.state.joining) return;
|
||||||
if (room.roomId != this.props.roomId) return;
|
if (room.roomId != this.props.roomId) return;
|
||||||
|
|
||||||
if (this.refs.messageList) {
|
if (this.refs.messageWrapper) {
|
||||||
var messageUl = this.refs.messageList.getDOMNode();
|
var messageWrapper = this.refs.messageWrapper.getDOMNode();
|
||||||
this.atBottom = messageUl.scrollHeight - messageUl.scrollTop <= messageUl.clientHeight;
|
this.atBottom = messageWrapper.scrollHeight - messageWrapper.scrollTop <= messageWrapper.clientHeight;
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
room: MatrixClientPeg.get().getRoom(this.props.roomId)
|
room: MatrixClientPeg.get().getRoom(this.props.roomId)
|
||||||
@ -96,40 +100,40 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
if (this.refs.messageList) {
|
if (this.refs.messageWrapper) {
|
||||||
var messageUl = this.refs.messageList.getDOMNode();
|
var messageWrapper = this.refs.messageWrapper.getDOMNode();
|
||||||
|
|
||||||
messageUl.addEventListener('drop', handleDrop);
|
messageWrapper.addEventListener('drop', this.handleDrop);
|
||||||
|
|
||||||
messageUl.scrollTop = messageUl.scrollHeight;
|
messageWrapper.scrollTop = messageWrapper.scrollHeight;
|
||||||
|
|
||||||
this.fillSpace();
|
this.fillSpace();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidUpdate: function() {
|
componentDidUpdate: function() {
|
||||||
if (!this.refs.messageList) return;
|
if (!this.refs.messageWrapper) return;
|
||||||
|
|
||||||
var messageUl = this.refs.messageList.getDOMNode();
|
var messageWrapper = this.refs.messageWrapper.getDOMNode();
|
||||||
|
|
||||||
if (this.state.paginating && !this.waiting_for_paginate) {
|
if (this.state.paginating && !this.waiting_for_paginate) {
|
||||||
var heightGained = messageUl.scrollHeight - this.oldScrollHeight;
|
var heightGained = messageWrapper.scrollHeight - this.oldScrollHeight;
|
||||||
messageUl.scrollTop += heightGained;
|
messageWrapper.scrollTop += heightGained;
|
||||||
this.oldScrollHeight = undefined;
|
this.oldScrollHeight = undefined;
|
||||||
if (!this.fillSpace()) {
|
if (!this.fillSpace()) {
|
||||||
this.setState({paginating: false});
|
this.setState({paginating: false});
|
||||||
}
|
}
|
||||||
} else if (this.atBottom) {
|
} else if (this.atBottom) {
|
||||||
messageUl.scrollTop = messageUl.scrollHeight;
|
messageWrapper.scrollTop = messageWrapper.scrollHeight;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fillSpace: function() {
|
fillSpace: function() {
|
||||||
var messageUl = this.refs.messageList.getDOMNode();
|
var messageWrapper = this.refs.messageWrapper.getDOMNode();
|
||||||
if (messageUl.scrollTop < messageUl.clientHeight && this.state.room.oldState.paginationToken) {
|
if (messageWrapper.scrollTop < messageWrapper.clientHeight && this.state.room.oldState.paginationToken) {
|
||||||
this.setState({paginating: true});
|
this.setState({paginating: true});
|
||||||
|
|
||||||
this.oldScrollHeight = messageUl.scrollHeight;
|
this.oldScrollHeight = messageWrapper.scrollHeight;
|
||||||
|
|
||||||
if (this.state.messageCap < this.state.room.timeline.length) {
|
if (this.state.messageCap < this.state.room.timeline.length) {
|
||||||
this.waiting_for_paginate = false;
|
this.waiting_for_paginate = false;
|
||||||
@ -175,13 +179,20 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onMessageListScroll: function(ev) {
|
onMessageListScroll: function(ev) {
|
||||||
if (this.refs.messageList) {
|
if (this.refs.messageWrapper) {
|
||||||
var messageUl = this.refs.messageList.getDOMNode();
|
var messageWrapper = this.refs.messageWrapper.getDOMNode();
|
||||||
this.atBottom = messageUl.scrollHeight - messageUl.scrollTop <= messageUl.clientHeight;
|
this.atBottom = messageWrapper.scrollHeight - messageWrapper.scrollTop <= messageWrapper.clientHeight;
|
||||||
}
|
}
|
||||||
if (!this.state.paginating) this.fillSpace();
|
if (!this.state.paginating) this.fillSpace();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleDrop: function(ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
var files = evt.dataTransfer.files;
|
||||||
|
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
getEventTiles: function() {
|
getEventTiles: function() {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user