From 8f3806360b5ffd2eda177cf24ba3b73823b1d959 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 16 Jun 2020 14:59:54 +0200 Subject: [PATCH] MOBILE-3401 iframe: Fix app re-loaded inside iframe in iOS --- src/components/iframe/core-iframe.html | 6 ++++-- src/components/iframe/iframe.ts | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/components/iframe/core-iframe.html b/src/components/iframe/core-iframe.html index 9e5f98ae6..0ba267b63 100644 --- a/src/components/iframe/core-iframe.html +++ b/src/components/iframe/core-iframe.html @@ -1,5 +1,7 @@ -
- +
+ + + diff --git a/src/components/iframe/iframe.ts b/src/components/iframe/iframe.ts index 84560094c..dd77bd5e8 100644 --- a/src/components/iframe/iframe.ts +++ b/src/components/iframe/iframe.ts @@ -13,7 +13,7 @@ // limitations under the License. import { - Component, Input, Output, OnInit, ViewChild, ElementRef, EventEmitter, OnChanges, SimpleChange, Optional + Component, Input, Output, ViewChild, ElementRef, EventEmitter, OnChanges, SimpleChange, Optional } from '@angular/core'; import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'; import { NavController, Platform } from 'ionic-angular'; @@ -30,7 +30,7 @@ import { CoreUrl } from '@singletons/url'; selector: 'core-iframe', templateUrl: 'core-iframe.html' }) -export class CoreIframeComponent implements OnInit, OnChanges { +export class CoreIframeComponent implements OnChanges { @ViewChild('iframe') iframe: ElementRef; @Input() src: string; @@ -43,6 +43,7 @@ export class CoreIframeComponent implements OnInit, OnChanges { protected logger; protected IFRAME_TIMEOUT = 15000; + protected initialized = false; constructor(logger: CoreLoggerProvider, protected iframeUtils: CoreIframeUtilsProvider, @@ -59,9 +60,15 @@ export class CoreIframeComponent implements OnInit, OnChanges { } /** - * Component being initialized. + * Init the data. */ - ngOnInit(): void { + protected init(): void { + if (this.initialized) { + return; + } + + this.initialized = true; + const iframe: HTMLIFrameElement = this.iframe && this.iframe.nativeElement; this.iframeWidth = this.domUtils.formatPixelsSize(this.iframeWidth) || '100%'; @@ -116,6 +123,11 @@ export class CoreIframeComponent implements OnInit, OnChanges { } this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(CoreFile.instance.convertFileSrc(url)); + + // Now that the URL has been set, initialize the iframe. Wait for the iframe to the added to the DOM. + setTimeout(() => { + this.init(); + }); } } }