Skip to content

Commit

Permalink
fix(livereload): images not loading (#161)
Browse files Browse the repository at this point in the history
* fix(wkwebview): Images not loading in Ionic WKWebView

* fix(livereload): Images not loading

When running in an emulator or in a device with the flag --livereload images were not showing.

* lint(livereload): Updated for ihadeed comments
  • Loading branch information
eduardoRoth authored and ihadeed committed Jun 29, 2018
1 parent a15309f commit ead3918
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/providers/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class ImageLoader {
private get isIonicWKWebView(): boolean {
return this.isWKWebView && (location.host === 'localhost:8080' || (<any>window).LiveReload);
}

private get isDevServer() : boolean {
return (window['IonicDevServer'] != undefined);
}

constructor(
private config: ImageLoaderConfig,
Expand Down Expand Up @@ -464,6 +468,11 @@ export class ImageLoader {
if (!this.isCacheReady) {
return reject();
}

// if we're running with livereload, ignore cache and call the resource from it's URL
if(this.isDevServer){
return reject();
}

// get file name
const fileName = this.createFileName(url);
Expand Down Expand Up @@ -496,10 +505,8 @@ export class ImageLoader {
// in this case only the tempDirectory is accessible,
// therefore the file needs to be copied into that directory first!
if (this.isIonicWKWebView) {

// Use Ionic normalizeUrl to generate the right URL for Ionic WKWebView
resolve(normalizeURL(fileEntry.nativeURL));

} else if (this.isWKWebView) {

// check if file already exists in temp directory
Expand Down

0 comments on commit ead3918

Please sign in to comment.