cancel
Showing results for 
Search instead for 
Did you mean: 

Full page WebView in Mobile Development Kit- MDK

gpic-ahmed-96
Explorer
0 Kudos

Hi Experts,

We are in a need to render webview inside our MDK App.

And we have successfully done that using the code below.

But it's only working in a Section page (the webview is part of the page).

Where we need it to cover a full page using it as Extension page.

If anyone know the needed changes to make it cover the full page working in an extension page would be great.

import * as app from "@nativescript/core/application";import { IControl } from "mdk-core/controls/IControl";import { BaseObservable } from "mdk-core/observables/BaseObservable";import { EventHandler } from "mdk-core/EventHandler";import { Dialogs } from "@nativescript/core";import { StackLayout } from "@nativescript/core/ui/layouts/stack-layout";import { GridLayout } from "@nativescript/core/ui/layouts/grid-layout";import { ScrollView } from "@nativescript/core/ui/scroll-view";
export class webView extends IControl { private _observable: BaseObservable; private _StackLayout: any; private _GridLayout: any; private _ScrollView: any;
private _webView: any;
public initialize(props: any): any { super.initialize(props);
var webHtml = ` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Welcome</title> <style> * { box-sizing: border-box; } body { margin: 0; font-family: Arial, Helvetica, sans-serif; background-color: #f8f8f8; } </style> </head> <body id="body"> <h1>Hi</h1> </body> </html> `;
if (app.android) { this._webView = new android.webkit.WebView(app.android.context);
this._webView.setLayoutParams( new android.view.ViewGroup.LayoutParams(-1, -2) );
let webSettings = this._webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setPluginsEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowFileAccessFromFileURLs(true);
this._webView.setWebChromeClient(new android.webkit.WebChromeClient());
this._webView.getSettings().setLoadsImagesAutomatically(true);
this._webView.getSettings().setDomStorageEnabled(true); this._webView.getSettings().setAppCacheMaxSize(1024 * 8);
this._webView.getSettings().setAppCacheEnabled(true);
this._webView.loadDataWithBaseURL( "", webHtml, "text/html", "utf-8", null );
this._layout = new android.widget.LinearLayout(app.android.context);
this._layout.setLayoutParams( new android.view.ViewGroup.LayoutParams(-1, -2) );
this._layout.addView(this._webView);
return this._layout; }
if (app.ios) { this._webView = null;
try { var configuration = WKWebViewConfiguration.new(); var pref = WKWebpagePreferences.new(); pref.allowsContentJavaScript = true; configuration.defaultWebpagePreferences = pref;
this._webView = new WKWebView({ frame: CGRectZero, configuration: configuration, });
this._webView.loadHTMLStringBaseURL(webHtml, null); } catch (error) {} } }
public view() { console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ view called"); return this._webView; // Return View }
public viewIsNative() { return true; }
public observable() { if (!this._observable) { this._observable = new BaseObservable( this, this.definition(), this.page() ); } return this._observable; }
public setContainer(container: IControl) { // do nothing }
public setValue( value: any, notify: boolean, isTextValue?: boolean 😞 Promise<any> { // do nothing return Promise.resolve(); }}

Thank You

Accepted Solutions (0)

Answers (0)