Skip to content

Commit

Permalink
Update the scroll position when 'fetch more messages' is complete
Browse files Browse the repository at this point in the history
FREEBIE
  • Loading branch information
scottnonnenberg committed Jun 1, 2017
1 parent 3dbb21c commit 0b6d5de
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion js/views/conversation_view.js
Expand Up @@ -156,7 +156,7 @@
'focus .send-message': 'focusBottomBar',
'change .file-input': 'toggleMicrophone',
'blur .send-message': 'unfocusBottomBar',
'loadMore .message-list': 'fetchMessages',
'loadMore .message-list': 'loadMoreMessages',
'newOffscreenMessage .message-list': 'addScrollDownButtonWithCount',
'atBottom .message-list': 'hideScrollDownButton',
'farFromBottom .message-list': 'addScrollDownButton',
Expand Down Expand Up @@ -312,6 +312,27 @@
this.$messageField.focus();
},

loadMoreMessages: function() {
if (this.inProgressFetch) {
return;
}

this.view.measureScrollPosition();
var startingHeight = this.view.scrollHeight;

this.fetchMessages().then(function() {
// We delay this work to let scrolling/layout settle down first
setTimeout(function() {
this.view.measureScrollPosition();
var endingHeight = this.view.scrollHeight;
var delta = endingHeight - startingHeight;

var newScrollPosition = this.view.scrollPosition + delta - this.view.
this.view.$el.scrollTop(newScrollPosition);
}.bind(this), 1);
}.bind(this));
},

fetchMessages: function() {
console.log('fetchMessages');
this.$('.bar-container').show();
Expand Down

0 comments on commit 0b6d5de

Please sign in to comment.