Skip to content

Commit

Permalink
Step 4.27: Add auto-scroll to chat controller
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 23, 2016
1 parent 9f73408 commit 2856a23
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client/scripts/controllers/chat.controller.js
Expand Up @@ -20,6 +20,8 @@ export default class ChatCtrl extends Controller {
return Chats.findOne(this.chatId);
}
});

this.autoScroll();
}

sendMessage() {
Expand Down Expand Up @@ -56,6 +58,17 @@ export default class ChatCtrl extends Controller {
}
}

autoScroll() {
let recentMessagesNum = this.messages.length;

this.autorun(() => {
const currMessagesNum = this.getCollectionReactively('messages').length;
const animate = recentMessagesNum != currMessagesNum;
recentMessagesNum = currMessagesNum;
this.scrollBottom(animate);
});
}

scrollBottom(animate) {
this.$timeout(() => {
this.$ionicScrollDelegate.$getByHandle('chatScroll').scrollBottom(animate);
Expand Down

0 comments on commit 2856a23

Please sign in to comment.