0

I know that I can expose a "jsBridge" object to javascript in webview by

Control.AddJavascriptInterface(new JsBridge(), 'jsBridge');

It seems inside the "JsBridge" class, we can only expose methods like


        [JavascriptInterface]
        [Export("myMethodName")]
        public void MyMethod(string message)
        {
           //some logic
        }

But I need some way to expose some objects or properties like bellow:

public ApiModule1 Module1 => _module1;
public ApiModule2 Module2 => _module2;

seems the "ExportAttribute" can only be applied to methods.

I am doing this because I need a way to expose only one single namespace at the JavaScript side, and still keep things organized by not stuffing everything into one object, that is;

jsBridge.Module1.someMethod(); 
jsBridge.Module2.someMethod(); 

Did I misunderstood some concepts here or is there are any other way to achieve this kind of feature?

Thank you very much.

2
  • According to stackoverflow.com/a/32491597/987000 , seem that android dose NOT support exporting anything but functions. Commented Jan 13, 2022 at 2:49
  • maybe you can expose a property as a pair of get/set methods? Commented Jan 13, 2022 at 5:37

1 Answer 1

0

You cannot expose properties directly. If you want to export any object create a getter for same in the interface you are exposing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.