Scroll to top

This commit is contained in:
Max Lynch
2015-09-30 13:35:12 -05:00
parent 3d36cc6e07
commit 89f131b2de
4 changed files with 40 additions and 4 deletions

View File

@ -1,9 +1,11 @@
import {Component, View, ElementRef} from 'angular2/angular2'; import {Component, View, ElementRef, Optional, Host} from 'angular2/angular2';
import {Ion} from '../ion'; import {Ion} from '../ion';
import {IonicConfig} from '../../config/config'; import {IonicConfig} from '../../config/config';
import {IonicPlatform} from '../../platform/platform'; import {IonicPlatform} from '../../platform/platform';
import {IonicComponent} from '../../config/decorators'; import {IonicComponent} from '../../config/decorators';
import {ViewController} from '../nav/view-controller';
import {Tab} from '../tabs/tab';
import {ScrollTo} from '../../animations/scroll-to'; import {ScrollTo} from '../../animations/scroll-to';
@ -38,10 +40,14 @@ export class Content extends Ion {
* @param {ElementRef} elementRef A reference to the component's DOM element. * @param {ElementRef} elementRef A reference to the component's DOM element.
* @param {IonicConfig} config The config object to change content's default settings. * @param {IonicConfig} config The config object to change content's default settings.
*/ */
constructor(elementRef: ElementRef, config: IonicConfig, platform: IonicPlatform) { constructor(elementRef: ElementRef, config: IonicConfig, platform: IonicPlatform, @Optional() viewCtrl: ViewController) {
super(elementRef, config); super(elementRef, config);
this.scrollPadding = 0; this.scrollPadding = 0;
this.platform = platform; this.platform = platform;
if(viewCtrl) {
viewCtrl.setContent(this);
}
} }
/** /**
@ -107,6 +113,16 @@ export class Content extends Ion {
return this._scrollTo.start(x, y, duration, tolerance); return this._scrollTo.start(x, y, duration, tolerance);
} }
scrollToTop() {
if (this._scrollTo) {
this._scrollTo.dispose();
}
this._scrollTo = new ScrollTo(this.scrollElement);
return this._scrollTo.start(0, 0, 300, 0);
}
/** /**
* Returns the content and scroll elements' dimensions. * Returns the content and scroll elements' dimensions.
* @returns {Object} dimensions The content and scroll elements' dimensions * @returns {Object} dimensions The content and scroll elements' dimensions

View File

@ -23,6 +23,14 @@ export class ViewController {
this.templateRefs = {}; this.templateRefs = {};
} }
setContent(content) {
this._content = content;
}
getContent() {
return this._content;
}
/** /**
* TODO * TODO
* @param {TODO} name TODO * @param {TODO} name TODO

View File

@ -1,8 +1,10 @@
import {Directive, Component, View, Host, ElementRef, forwardRef, Injector, NgZone} from 'angular2/angular2'; import {Directive, Component, View, Host, ElementRef, forwardRef,
Injector, NgZone, Query, ViewQuery, QueryList} from 'angular2/angular2';
import {NavController} from '../nav/nav-controller'; import {NavController} from '../nav/nav-controller';
import {ViewController} from '../nav/view-controller'; import {ViewController} from '../nav/view-controller';
import {Tabs} from './tabs'; import {Tabs} from './tabs';
import {Content} from '../content/content';
/** /**
@ -47,7 +49,7 @@ export class Tab extends NavController {
@Host() tabs: Tabs, @Host() tabs: Tabs,
elementRef: ElementRef, elementRef: ElementRef,
injector: Injector, injector: Injector,
zone: NgZone zone: NgZone,
) { ) {
// A Tab is both a container of many views, and is a view itself. // A Tab is both a container of many views, and is a view itself.
// A Tab is one ViewController within it's Host Tabs (which extends NavController) // A Tab is one ViewController within it's Host Tabs (which extends NavController)
@ -141,6 +143,7 @@ class TabPaneAnchor {
* @param {ElementRef} elementRef TODO * @param {ElementRef} elementRef TODO
*/ */
constructor(@Host() tab: Tab, elementRef: ElementRef) { constructor(@Host() tab: Tab, elementRef: ElementRef) {
tab.anchorElementRef(elementRef); tab.anchorElementRef(elementRef);
} }
} }

View File

@ -166,6 +166,15 @@ export class Tabs extends NavController {
// Pop to the root view // Pop to the root view
tab.popToRoot(); tab.popToRoot();
} }
/*
TODO: Uncomment to enable root scroll to top
else {
let content = tab.views[0] && tab.views[0].getContent();
if(content) {
content.scrollToTop();
}
}
*/
} }
get tabs() { get tabs() {