MOBILE-3401 iframe: Fix app re-loaded inside iframe in iOS

main
Dani Palou 2020-06-16 14:59:54 +02:00
parent 2bcf3e2e14
commit 8f3806360b
2 changed files with 20 additions and 6 deletions

View File

@ -1,5 +1,7 @@
<div [class.core-loading-container]="loading" [ngStyle]="{'width': iframeWidth, 'height': iframeHeight}"> <div [class.core-loading-container]="loading || !safeUrl" [ngStyle]="{'width': iframeWidth, 'height': iframeHeight}">
<iframe #iframe [hidden]="loading" class="core-iframe" [ngStyle]="{'width': iframeWidth, 'height': iframeHeight}" [src]="safeUrl" [attr.allowfullscreen]="allowFullscreen ? 'allowfullscreen' : null"></iframe> <!-- Don't add the iframe until the safeUrl is set, adding an iframe with null as src causes the iframe to load the whole app. -->
<iframe #iframe *ngIf="safeUrl" [hidden]="loading" class="core-iframe" [ngStyle]="{'width': iframeWidth, 'height': iframeHeight}" [src]="safeUrl" [attr.allowfullscreen]="allowFullscreen ? 'allowfullscreen' : null"></iframe>
<span class="core-loading-spinner"> <span class="core-loading-spinner">
<ion-spinner *ngIf="loading"></ion-spinner> <ion-spinner *ngIf="loading"></ion-spinner>
</span> </span>

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { import {
Component, Input, Output, OnInit, ViewChild, ElementRef, EventEmitter, OnChanges, SimpleChange, Optional Component, Input, Output, ViewChild, ElementRef, EventEmitter, OnChanges, SimpleChange, Optional
} from '@angular/core'; } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'; import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { NavController, Platform } from 'ionic-angular'; import { NavController, Platform } from 'ionic-angular';
@ -30,7 +30,7 @@ import { CoreUrl } from '@singletons/url';
selector: 'core-iframe', selector: 'core-iframe',
templateUrl: 'core-iframe.html' templateUrl: 'core-iframe.html'
}) })
export class CoreIframeComponent implements OnInit, OnChanges { export class CoreIframeComponent implements OnChanges {
@ViewChild('iframe') iframe: ElementRef; @ViewChild('iframe') iframe: ElementRef;
@Input() src: string; @Input() src: string;
@ -43,6 +43,7 @@ export class CoreIframeComponent implements OnInit, OnChanges {
protected logger; protected logger;
protected IFRAME_TIMEOUT = 15000; protected IFRAME_TIMEOUT = 15000;
protected initialized = false;
constructor(logger: CoreLoggerProvider, constructor(logger: CoreLoggerProvider,
protected iframeUtils: CoreIframeUtilsProvider, 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; const iframe: HTMLIFrameElement = this.iframe && this.iframe.nativeElement;
this.iframeWidth = this.domUtils.formatPixelsSize(this.iframeWidth) || '100%'; 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)); 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();
});
} }
} }
} }