From 6a0c92c509fac10a077020a2863046d5e4603b91 Mon Sep 17 00:00:00 2001 From: Justin Willis Date: Mon, 13 Feb 2017 11:39:29 -0600 Subject: [PATCH] fix(content): check for scroll element before modifying it (#10374) * test(refresher): add nav based refresher e2e test * test(refresher): tweak test to repro issue * fix(content): check for scroll element * chore(content): double check for a scroll element --- src/components/content/content.ts | 13 +- .../refresher/test/navigation/app.module.ts | 122 ++++++++++++++++++ .../refresher/test/navigation/main.html | 32 +++++ .../refresher/test/navigation/page2.html | 14 ++ 4 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 src/components/refresher/test/navigation/app.module.ts create mode 100644 src/components/refresher/test/navigation/main.html create mode 100644 src/components/refresher/test/navigation/page2.html diff --git a/src/components/content/content.ts b/src/components/content/content.ts index 5221bd3cab..00eee2aef6 100644 --- a/src/components/content/content.ts +++ b/src/components/content/content.ts @@ -498,9 +498,16 @@ export class Content extends Ion implements OnDestroy, OnInit { * DOM WRITE */ setScrollElementStyle(prop: string, val: any) { - this._dom.write(() => { - (this._scrollEle.style)[prop] = val; - }); + if (this._scrollEle) { + this._dom.write(() => { + // double check here as the scroll element + // could have been destroyed in the 16ms it took + // for this dom write to happen + if (this._scrollEle) { + (this._scrollEle.style)[prop] = val; + } + }); + } } /** diff --git a/src/components/refresher/test/navigation/app.module.ts b/src/components/refresher/test/navigation/app.module.ts new file mode 100644 index 0000000000..2ff93f5eb9 --- /dev/null +++ b/src/components/refresher/test/navigation/app.module.ts @@ -0,0 +1,122 @@ +import { Component, NgModule } from '@angular/core'; +import { IonicApp, IonicModule, Refresher, NavController } from '../../../../../ionic-angular'; + + +@Component({ + templateUrl: 'main.html' +}) +export class Page1 { + items: string[] = []; + + constructor(public nav: NavController) { + for (var i = 0; i < 15; i++) { + this.items.push( getRandomData() ); + } + } + + doRefresh(refresher: Refresher) { + console.info('Begin async operation'); + + getAsyncData().then((newData: string[]) => { + for (var i = 0; i < newData.length; i++) { + this.items.unshift( newData[i] ); + } + + console.info('Finished receiving data, async operation complete'); + refresher.complete(); + }); + } + + doStart(refresher: Refresher) { + console.info('Refresher, start'); + } + + doPulling(refresher: Refresher) { + console.info('Pulling', refresher.progress); + } + + navigate() { + this.nav.setRoot(Page2); + } + +} + +function getAsyncData() { + // async return mock data + return new Promise(resolve => { + + setTimeout(() => { + let data: string[] = []; + for (var i = 0; i < 3; i++) { + data.push( getRandomData() ); + } + + resolve(data); + }, 3000); + + }); +} + +function getRandomData() { + let i = Math.floor( Math.random() * data.length ); + return data[i]; +} + +const data = [ + 'Fast Times at Ridgemont High', + 'Peggy Sue Got Married', + 'Raising Arizona', + 'Moonstruck', + 'Fire Birds', + 'Honeymoon in Vegas', + 'Amos & Andrew', + 'It Could Happen to You', + 'Trapped in Paradise', + 'Leaving Las Vegas', + 'The Rock', + 'Con Air', + 'Face/Off', + 'City of Angels', + 'Gone in Sixty Seconds', + 'The Family Man', + 'Windtalkers', + 'Matchstick Men', + 'National Treasure', + 'Ghost Rider', + 'Grindhouse', + 'Next', + 'Kick-Ass', + 'Drive Angry' +]; + +@Component({ + templateUrl: 'page2.html' +}) +export class Page2 { + constructor() {} +} + +@Component({ + template: '' +}) +export class E2EApp { + rootPage = Page1; +} + +@NgModule({ + declarations: [ + E2EApp, + Page1, + Page2 + ], + imports: [ + IonicModule.forRoot(E2EApp) + ], + bootstrap: [IonicApp], + entryComponents: [ + E2EApp, + Page1, + Page2 + ] +}) +export class AppModule {} diff --git a/src/components/refresher/test/navigation/main.html b/src/components/refresher/test/navigation/main.html new file mode 100644 index 0000000000..65c1d9fe90 --- /dev/null +++ b/src/components/refresher/test/navigation/main.html @@ -0,0 +1,32 @@ + + + + Pull To Refresh Navigation + + + + + + + + + + + + + + +

Pull to refresh and then navigate with the button below

+ + + + + + {{ item }} + + + +
\ No newline at end of file diff --git a/src/components/refresher/test/navigation/page2.html b/src/components/refresher/test/navigation/page2.html new file mode 100644 index 0000000000..38a33da54f --- /dev/null +++ b/src/components/refresher/test/navigation/page2.html @@ -0,0 +1,14 @@ + + + + Pull To Refresh Navigation + + + + + + + +

Page Two

+ +
\ No newline at end of file