Skip to content

Commit

Permalink
fix(webview/ios): initial meta viewport is overrided
Browse files Browse the repository at this point in the history
  • Loading branch information
mxth committed Mar 20, 2018
1 parent 7506905 commit d7ae105
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tns-core-modules/ui/web-view/web-view.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export class WebView extends WebViewBase {
const configuration = WKWebViewConfiguration.new();
this._delegate = WKNavigationDelegateImpl.initWithOwner(new WeakRef(this));
const jScript = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'initial-scale=1.0'); document.getElementsByTagName('head')[0].appendChild(meta);";
const wkUScript = WKUserScript.alloc().initWithSourceInjectionTimeForMainFrameOnly(jScript,WKUserScriptInjectionTime.AtDocumentEnd,true);
const jScriptWithMetaCheck = `if (!document.querySelector('meta[name="viewport"]')) { ${jScript} }`;
const wkUScript = WKUserScript.alloc().initWithSourceInjectionTimeForMainFrameOnly(jScriptWithMetaCheck,WKUserScriptInjectionTime.AtDocumentEnd,true);
const wkUController = WKUserContentController.new();
wkUController.addUserScript(wkUScript);
configuration.userContentController = wkUController;
Expand Down Expand Up @@ -156,4 +157,4 @@ export class WebView extends WebViewBase {
public reload() {
this._ios.reload();
}
}
}

0 comments on commit d7ae105

Please sign in to comment.