diff --git a/src/pages/stream/stream.html b/src/pages/stream/stream.html index c1dcdde..a38f5de 100644 --- a/src/pages/stream/stream.html +++ b/src/pages/stream/stream.html @@ -96,4 +96,10 @@ + + + + diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts index 63f1c74..ae34fe3 100644 --- a/src/pages/stream/stream.ts +++ b/src/pages/stream/stream.ts @@ -1,5 +1,5 @@ -import { Component } from '@angular/core'; -import { ViewController, NavController, NavParams, ModalController } from 'ionic-angular'; +import { Component, ViewChild, ChangeDetectorRef } from '@angular/core'; +import { ViewController, NavController, NavParams, ModalController, Content } from 'ionic-angular'; import { ThreadPage } from '../thread/thread'; import * as pnut from 'pnut-butter'; @@ -16,6 +16,8 @@ import * as pnut from 'pnut-butter'; }) export class StreamPage { + @ViewChild(Content) content: Content; + title: string; posts: Array = []; since_id: string; @@ -23,9 +25,12 @@ export class StreamPage { fetcher: any; fcaller: any; myUsername: string; + showScrollBtn: boolean = false; - constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController) { + constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, + private changeDetectorRef: ChangeDetectorRef) { // console.log(JSON.stringify(navParams)); + switch (navParams.data.stream) { case 'global': this.title = 'Global'; @@ -55,6 +60,18 @@ export class StreamPage { }); } + ngAfterViewInit() { + this.content.ionScroll.subscribe((event) => { + // console.log('scrolling ', event); + if (event.scrollTop > 0) { + this.showScrollBtn = true; + } else { + this.showScrollBtn = false; + } + this.changeDetectorRef.detectChanges(); + }); + } + fetchOlderPosts(infiniteScroll) { let params = {include_raw: 1, include_reposted_by:1, before_id: this.before_id, count: 40}; if (this.title === 'Mentions') { @@ -231,6 +248,10 @@ export class StreamPage { newPostModal.present(); } + scrollToTop() { + this.content.scrollToTop(); + } + } @Component({