Skip to content

Commit bef4a67

Browse files
committed
feat(content): add scrollToBottom
1 parent 1c755dc commit bef4a67

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

ionic/components/content/content.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export class Content extends Ion {
268268
* @returns {Promise} Returns a promise which is resolved when the scroll has completed.
269269
*/
270270
scrollToTop(duration: number = 300) {
271-
return this.scrollTo(0, 0, duration);
271+
return this._scroll.scrollToTop(duration);
272272
}
273273

274274
/**
@@ -287,6 +287,15 @@ export class Content extends Ion {
287287
this._scroll.setTop(top);
288288
}
289289

290+
/**
291+
* Scroll to the bottom of the content component.
292+
* @param {number} [duration] Duration of the scroll animation in milliseconds. Defaults to `300`.
293+
* @returns {Promise} Returns a promise which is resolved when the scroll has completed.
294+
*/
295+
scrollToBottom(duration: number = 300) {
296+
return this._scroll.scrollToBottom(duration);
297+
}
298+
290299
/**
291300
* @private
292301
*/

ionic/components/nav/test/basic/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class MyCmpTest{}
4848
<button ion-item (click)="quickPush()">New push during transition</button>
4949
<button ion-item (click)="quickPop()">New pop during transition</button>
5050
<button ion-item (click)="reload()">Reload</button>
51+
<button ion-item (click)="scrollToBottom()">Scroll to bottom</button>
5152
<button *ngFor="#i of pages" ion-item (click)="pushPrimaryHeaderPage()">Page {{i}}</button>
5253
<button ion-item (click)="content.scrollToTop()">Scroll to top</button>
5354
</ion-list>
@@ -121,6 +122,10 @@ class FirstPage {
121122
scrollToTop() {
122123
this.content.scrollToTop();
123124
}
125+
126+
scrollToBottom() {
127+
this.content.scrollToBottom(1000);
128+
}
124129
}
125130

126131

ionic/util/scroll-view.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ export class ScrollView {
104104
});
105105
}
106106

107+
scrollToTop(duration: number): Promise<any> {
108+
return this.scrollTo(0, 0, duration);
109+
}
110+
111+
scrollToBottom(duration: number): Promise<any> {
112+
let y = 0;
113+
if (this._el) {
114+
y = this._el.scrollHeight - this._el.clientHeight;
115+
}
116+
return this.scrollTo(0, y, duration);
117+
}
118+
107119
stop() {
108120
this.isPlaying = false;
109121
}

0 commit comments

Comments
 (0)