Skip to content

Commit 603000f

Browse files
committed
fix(refresher): adjust location after layout updates
1 parent 22fad4c commit 603000f

File tree

4 files changed

+53
-40
lines changed

4 files changed

+53
-40
lines changed

src/components/content/content.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ export class Content extends Ion {
6464
private _paddingRight: number;
6565
private _paddingBottom: number;
6666
private _paddingLeft: number;
67-
private _lastTop: number;
68-
private _lastBottom: number;
6967
private _scrollPadding: number;
7068
private _headerHeight: number;
7169
private _footerHeight: number;
@@ -78,6 +76,16 @@ export class Content extends Ion {
7876
private _sbPadding: boolean;
7977
private _fullscreen: boolean;
8078

79+
/**
80+
* @private
81+
*/
82+
adjustedTop: number;
83+
84+
/**
85+
* @private
86+
*/
87+
adjustedBottom: number;
88+
8189
constructor(
8290
private _elementRef: ElementRef,
8391
private _config: Config,
@@ -185,7 +193,7 @@ export class Content extends Ion {
185193
}
186194
};
187195
}
188-
196+
189197
/**
190198
* @private
191199
*/
@@ -510,16 +518,18 @@ export class Content extends Ion {
510518
if (this._tabbarPlacement === 'top') {
511519
newVal += this._tabbarHeight;
512520
}
513-
if (newVal !== this._lastTop) {
521+
if (newVal !== this.adjustedTop) {
514522
this._scrollEle.style.paddingTop = (newVal > 0 ? newVal + 'px' : '');
523+
this.adjustedTop = newVal;
515524
}
516525

517526
newVal = this._footerHeight + this._paddingBottom;
518527
if (this._tabbarPlacement === 'bottom') {
519528
newVal += this._tabbarHeight;
520529
}
521-
if (newVal !== this._lastBottom) {
530+
if (newVal !== this.adjustedBottom) {
522531
this._scrollEle.style.paddingBottom = (newVal > 0 ? newVal + 'px' : '');
532+
this.adjustedBottom = newVal;
523533
}
524534

525535
} else {
@@ -528,16 +538,18 @@ export class Content extends Ion {
528538
if (this._tabbarPlacement === 'top') {
529539
newVal += this._tabbarHeight;
530540
}
531-
if (newVal !== this._lastTop) {
541+
if (newVal !== this.adjustedTop) {
532542
this._scrollEle.style.marginTop = (newVal > 0 ? newVal + 'px' : '');
543+
this.adjustedTop = newVal;
533544
}
534545

535546
newVal = this._footerHeight;
536547
if (this._tabbarPlacement === 'bottom') {
537548
newVal += this._tabbarHeight;
538549
}
539-
if (newVal !== this._lastBottom) {
550+
if (newVal !== this.adjustedBottom) {
540551
this._scrollEle.style.marginBottom = (newVal > 0 ? newVal + 'px' : '');
552+
this.adjustedBottom = newVal;
541553
}
542554
}
543555

src/components/item/item-reorder.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ion-reorder {
1616

1717
pointer-events: all;
1818
touch-action: manipulation;
19-
19+
2020
ion-icon {
2121
pointer-events: none;
2222
}
@@ -39,7 +39,7 @@ ion-item.reorder-active {
3939
box-shadow: 0 0 10px rgba(0, 0, 0, .5);
4040
opacity: .8;
4141
transition: none;
42-
42+
4343
pointer-events: none;
4444

4545
ion-reorder {

src/components/refresher/refresher.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import {Directive, ElementRef, EventEmitter, Host, Input, Output, NgZone} from '@angular/core';
1+
import { Directive, EventEmitter, Host, Input, Output, NgZone } from '@angular/core';
22

3-
import {Content} from '../content/content';
4-
import {Icon} from '../icon/icon';
5-
import {isTrueProperty} from '../../util/util';
6-
import {CSS, pointerCoord, transitionEnd} from '../../util/dom';
7-
import {PointerEvents, UIEventManager} from '../../util/ui-event-manager';
3+
import { Content } from '../content/content';
4+
import { CSS, pointerCoord } from '../../util/dom';
5+
import { isTrueProperty } from '../../util/util';
6+
import { PointerEvents, UIEventManager } from '../../util/ui-event-manager';
87

98

109
/**
@@ -90,7 +89,8 @@ import {PointerEvents, UIEventManager} from '../../util/ui-event-manager';
9089
@Directive({
9190
selector: 'ion-refresher',
9291
host: {
93-
'[class.refresher-active]': 'state !== "inactive"'
92+
'[class.refresher-active]': 'state !== "inactive"',
93+
'[style.top]': '_top'
9494
}
9595
})
9696
export class Refresher {
@@ -100,6 +100,7 @@ export class Refresher {
100100
private _isEnabled: boolean = true;
101101
private _events: UIEventManager = new UIEventManager(false);
102102
private _pointerEvents: PointerEvents;
103+
private _top: string = '';
103104

104105
/**
105106
* The current state which the refresher is in. The refresher's states include:
@@ -195,23 +196,8 @@ export class Refresher {
195196
@Output() ionStart: EventEmitter<Refresher> = new EventEmitter();
196197

197198

198-
constructor(
199-
@Host() private _content: Content,
200-
private _zone: NgZone,
201-
elementRef: ElementRef) {
199+
constructor(@Host() private _content: Content, private _zone: NgZone) {
202200
_content.addCssClass('has-refresher');
203-
204-
// deprecated warning
205-
let ele = elementRef.nativeElement;
206-
let deprecatedAttrs = ['pullingIcon', 'pullingText', 'refreshingIcon', 'refreshingText', 'spinner'];
207-
deprecatedAttrs.forEach(attrName => {
208-
if (ele.hasAttribute(attrName)) {
209-
console.warn('<ion-refresher> property "' + attrName + '" should now be placed on the inner <ion-refresher-content> component instead of <ion-refresher>. Please review the Refresher docs for API updates.');
210-
}
211-
});
212-
if (!ele.children.length) {
213-
console.warn('<ion-refresher> should now have an inner <ion-refresher-content> component. Please review the Refresher docs for API updates.');
214-
}
215201
}
216202

217203
private _onStart(ev: TouchEvent): any {
@@ -233,6 +219,13 @@ export class Refresher {
233219
let coord = pointerCoord(ev);
234220
console.debug('Pull-to-refresh, onStart', ev.type, 'y:', coord.y);
235221

222+
if (this._content.adjustedTop > 0) {
223+
let newTop = this._content.adjustedTop + 'px';
224+
if (this._top !== newTop) {
225+
this._top = newTop;
226+
}
227+
}
228+
236229
this.startY = this.currentY = coord.y;
237230
this.progress = 0;
238231
this.state = STATE_PULLING;

src/components/refresher/test/basic/index.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import {Component} from '@angular/core';
2-
import {ionicBootstrap} from '../../../../../src';
2+
import {ionicBootstrap, Refresher} from '../../../../../src';
33

44

55
@Component({
66
templateUrl: 'main.html'
77
})
8-
class E2EApp {
9-
items = [];
8+
class Page1 {
9+
items: string[] = [];
1010

1111
constructor() {
1212
for (var i = 0; i < 15; i++) {
1313
this.items.push( getRandomData() );
1414
}
1515
}
1616

17-
doRefresh(refresher) {
17+
doRefresh(refresher: Refresher) {
1818
console.info('Begin async operation');
1919

20-
getAsyncData().then(newData => {
20+
getAsyncData().then((newData: string[]) => {
2121
for (var i = 0; i < newData.length; i++) {
2222
this.items.unshift( newData[i] );
2323
}
@@ -27,11 +27,11 @@ class E2EApp {
2727
});
2828
}
2929

30-
doStart(refresher) {
30+
doStart(refresher: Refresher) {
3131
console.info('Refresher, start');
3232
}
3333

34-
doPulling(refresher) {
34+
doPulling(refresher: Refresher) {
3535
console.info('Pulling', refresher.progress);
3636
}
3737

@@ -42,7 +42,7 @@ function getAsyncData() {
4242
return new Promise(resolve => {
4343

4444
setTimeout(() => {
45-
let data = [];
45+
let data: string[] = [];
4646
for (var i = 0; i < 3; i++) {
4747
data.push( getRandomData() );
4848
}
@@ -85,4 +85,12 @@ const data = [
8585
'Drive Angry'
8686
];
8787

88+
89+
@Component({
90+
template: '<ion-nav [root]="rootPage"></ion-nav>'
91+
})
92+
class E2EApp {
93+
rootPage = Page1;
94+
}
95+
8896
ionicBootstrap(E2EApp);

0 commit comments

Comments
 (0)