Marshalling help


#1

Hello,

I am trying to implement this library: https://github.com/delight-im/Android-AdvancedWebView to NativeScript. I was able to view it but can’t marshalling following method: https://github.com/delight-im/Android-AdvancedWebView/blob/90d03ba2762101fb0f33bbb19917dde14d5c1a9f/Source/sample/src/main/java/im/delight/android/examples/webview/MainActivity.java#L31

I tried like this:

this.nativeView.setWebViewClient(new android.webkit.WebViewClient({
            onPageFinished: function (view, url) {
                console.log("url" + url);
            }
        }));

But got this error:

System.err: com.tns.NativeScriptException:
System.err: Calling js method onCreateView failed
System.err:
System.err: Error: Cannot marshal JavaScript argument [object Object] at index 0 to Java type.
System.err: File: "file:///data/data/org.nativescript.demo/files/app/tns_modules/nativescript-advancewebview/advancewebview.js, line: 51, column: 41
System.err:

I tried to create a class extending android.webkit.WebViewClient like this:

export class MyWebViewClient extends android.webkit.WebViewClient{

    public onPageFinished(view, url) {
        console.log(url);
    }
}

But getting this error:

System.err: com.tns.NativeScriptException:
System.err: Calling js method onCreateView failed
System.err:
System.err: Error: Cannot convert object to Landroid/webkit/WebViewClient; at index 0
System.err: File: "file:///data/data/org.nativescript.demo/files/app/tns_modules/nativescript-advancewebview/advancewebview.js, line: 51, column: 24

Anyone can help me this? Thanks in advance.


#2

Ok, I did it. The extend class will be like this:

export class MyWebViewClient extends android.webkit.WebViewClient {

    constructor() {
        super();
        return global.__native(this);
    }
    public onPageFinished(view, url) {
        console.log("onPageFinished" + url);
    }
}