react-native-webview-comlink icon indicating copy to clipboard operation
react-native-webview-comlink copied to clipboard

Question: Is here a way to expose an object on the web side towards native?

Open mattijsf opened this issue 2 years ago • 1 comments

Do I understand correctly that this lib only exposes a native api object inside the webview? Is there a way to also expose an api object from the webview side towards native?

mattijsf avatar Jun 04 '22 19:06 mattijsf

Yes, it's currently designed to only exposes a native api object inside the webview. (native -> web). It support callbacks being passed in the native api, so if it's not a complex funcion that you want to expose to native at web side, it can be implemented by something like:

// native api object allows to register a api from web side
let webAPIMethod;
const apiObject = {
    registerWebAPIMethod(method) {
        webAPIMethod = method;
    }
}
// 
if (webAPIMethod) {
    webAPIMethod('some', 'paramters');
}

rocwind avatar Aug 27 '22 04:08 rocwind