Skip to content

Commit 8f38063

Browse files
committed
MOBILE-3401 iframe: Fix app re-loaded inside iframe in iOS
1 parent 2bcf3e2 commit 8f38063

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/components/iframe/core-iframe.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
<div [class.core-loading-container]="loading" [ngStyle]="{'width': iframeWidth, 'height': iframeHeight}">
2-
<iframe #iframe [hidden]="loading" class="core-iframe" [ngStyle]="{'width': iframeWidth, 'height': iframeHeight}" [src]="safeUrl" [attr.allowfullscreen]="allowFullscreen ? 'allowfullscreen' : null"></iframe>
1+
<div [class.core-loading-container]="loading || !safeUrl" [ngStyle]="{'width': iframeWidth, 'height': iframeHeight}">
2+
<!-- 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. -->
3+
<iframe #iframe *ngIf="safeUrl" [hidden]="loading" class="core-iframe" [ngStyle]="{'width': iframeWidth, 'height': iframeHeight}" [src]="safeUrl" [attr.allowfullscreen]="allowFullscreen ? 'allowfullscreen' : null"></iframe>
4+
35
<span class="core-loading-spinner">
46
<ion-spinner *ngIf="loading"></ion-spinner>
57
</span>

src/components/iframe/iframe.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import {
16-
Component, Input, Output, OnInit, ViewChild, ElementRef, EventEmitter, OnChanges, SimpleChange, Optional
16+
Component, Input, Output, ViewChild, ElementRef, EventEmitter, OnChanges, SimpleChange, Optional
1717
} from '@angular/core';
1818
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
1919
import { NavController, Platform } from 'ionic-angular';
@@ -30,7 +30,7 @@ import { CoreUrl } from '@singletons/url';
3030
selector: 'core-iframe',
3131
templateUrl: 'core-iframe.html'
3232
})
33-
export class CoreIframeComponent implements OnInit, OnChanges {
33+
export class CoreIframeComponent implements OnChanges {
3434

3535
@ViewChild('iframe') iframe: ElementRef;
3636
@Input() src: string;
@@ -43,6 +43,7 @@ export class CoreIframeComponent implements OnInit, OnChanges {
4343

4444
protected logger;
4545
protected IFRAME_TIMEOUT = 15000;
46+
protected initialized = false;
4647

4748
constructor(logger: CoreLoggerProvider,
4849
protected iframeUtils: CoreIframeUtilsProvider,
@@ -59,9 +60,15 @@ export class CoreIframeComponent implements OnInit, OnChanges {
5960
}
6061

6162
/**
62-
* Component being initialized.
63+
* Init the data.
6364
*/
64-
ngOnInit(): void {
65+
protected init(): void {
66+
if (this.initialized) {
67+
return;
68+
}
69+
70+
this.initialized = true;
71+
6572
const iframe: HTMLIFrameElement = this.iframe && this.iframe.nativeElement;
6673

6774
this.iframeWidth = this.domUtils.formatPixelsSize(this.iframeWidth) || '100%';
@@ -116,6 +123,11 @@ export class CoreIframeComponent implements OnInit, OnChanges {
116123
}
117124

118125
this.safeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(CoreFile.instance.convertFileSrc(url));
126+
127+
// Now that the URL has been set, initialize the iframe. Wait for the iframe to the added to the DOM.
128+
setTimeout(() => {
129+
this.init();
130+
});
119131
}
120132
}
121133
}

0 commit comments

Comments
 (0)