mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
Scroll to top
This commit is contained in:
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
Reference in New Issue
Block a user