1

I need to use/import a JavaScript plugin in React-native. Plugin file contains functions, written in javascript and not in es6 format. I need to use those in react-native either by Webview or can be other way.

I already tried WebView, But html code is not even loading JS plugin file (<script type="text/javascript" src="./testjs.js">) Because when I give it a wrong path It should give me some file missing error, While Simple alert on same place is working. here below is render on RN screen :-

render () {
    var HTML = `<html> <head> <script type="text/javascript" src="./testjs.js"></script> </head> <body> <div id="workbookControl"></div> <div id="tableeditor" style="font-size : 50px;">I am written inside source HTML</div> </body> </html>`
    var jsCode = ` true;`
    return (
        <WebView
            originWhitelist={['*']}
            source={{ html: HTML }}
            injectedJavaScript={jsCode}
            onMessage={() => {}}
            javaScriptEnabledAndroid={true}
            javaScriptEnabled={true}
        />
    )
}

And here is code of testjs.js

(function hello(ddd) { alert("heiii"); return "Hello"; })(); true;

I want to call this hello() from testjs.js, How can I do that ?

1 Answers1

0

If you want to use html in the app you have to use react native webview. Check the source prop of the library

https://github.com/react-native-webview/react-native-webview/blob/74872a1f02c43e425f19739b1b25f5fbe614ba1f/docs/Reference.md#source

If you want to use javascript functions from that file you can simply import it for ES6 or use require statement