From bef4a67025c76af80b5482a2878244152a1b9288 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 18 Apr 2016 21:22:39 -0500 Subject: [PATCH] feat(content): add scrollToBottom --- ionic/components/content/content.ts | 11 ++++++++++- ionic/components/nav/test/basic/index.ts | 5 +++++ ionic/util/scroll-view.ts | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ionic/components/content/content.ts b/ionic/components/content/content.ts index 667d13cd2c..cda57396d7 100644 --- a/ionic/components/content/content.ts +++ b/ionic/components/content/content.ts @@ -268,7 +268,7 @@ export class Content extends Ion { * @returns {Promise} Returns a promise which is resolved when the scroll has completed. */ scrollToTop(duration: number = 300) { - return this.scrollTo(0, 0, duration); + return this._scroll.scrollToTop(duration); } /** @@ -287,6 +287,15 @@ export class Content extends Ion { this._scroll.setTop(top); } + /** + * Scroll to the bottom of the content component. + * @param {number} [duration] Duration of the scroll animation in milliseconds. Defaults to `300`. + * @returns {Promise} Returns a promise which is resolved when the scroll has completed. + */ + scrollToBottom(duration: number = 300) { + return this._scroll.scrollToBottom(duration); + } + /** * @private */ diff --git a/ionic/components/nav/test/basic/index.ts b/ionic/components/nav/test/basic/index.ts index 5b52e09d47..cb70681b7c 100644 --- a/ionic/components/nav/test/basic/index.ts +++ b/ionic/components/nav/test/basic/index.ts @@ -48,6 +48,7 @@ class MyCmpTest{} + @@ -121,6 +122,10 @@ class FirstPage { scrollToTop() { this.content.scrollToTop(); } + + scrollToBottom() { + this.content.scrollToBottom(1000); + } } diff --git a/ionic/util/scroll-view.ts b/ionic/util/scroll-view.ts index 212acae63f..c0ab1e7d28 100644 --- a/ionic/util/scroll-view.ts +++ b/ionic/util/scroll-view.ts @@ -104,6 +104,18 @@ export class ScrollView { }); } + scrollToTop(duration: number): Promise { + return this.scrollTo(0, 0, duration); + } + + scrollToBottom(duration: number): Promise { + let y = 0; + if (this._el) { + y = this._el.scrollHeight - this._el.clientHeight; + } + return this.scrollTo(0, y, duration); + } + stop() { this.isPlaying = false; }