From 680a3a0a2cd86602cfc01589472e49a369809ac3 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sun, 25 Jun 2017 21:19:49 -0700 Subject: [PATCH] added button to scroll back to top of feed issue #24 --- src/pages/stream/stream.html | 6 ++++++ src/pages/stream/stream.ts | 27 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) 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({