I want to load a local HTML file that imports a local javascript library using tag in react-native-webview.
I have tried many solutions but notihng worked on React native 0.60.5
.
- I have tried this approach, but I get Domain Not Found -1100 error on iOS.
- Tried this solution, but it did not work. (And the instructions were not clear for importing js file)
I am using :
"react": "16.8.6",
"react-native": "0.60.5"
PS: I am trying to implement highcharts.js charting library in webView.
I want to load a local HTML file that imports a local javascript library using tag in react-native-webview.
I have tried many solutions but notihng worked on React native 0.60.5
.
- I have tried this approach, but I get Domain Not Found -1100 error on iOS.
- Tried this solution, but it did not work. (And the instructions were not clear for importing js file)
I am using :
"react": "16.8.6",
"react-native": "0.60.5"
PS: I am trying to implement highcharts.js charting library in webView.
Share Improve this question edited Aug 30, 2019 at 12:54 mukesh.kumar asked Aug 30, 2019 at 12:10 mukesh.kumarmukesh.kumar 1,16017 silver badges30 bronze badges 2- 1 You can try to use also our official wrapper for react-native. github./highcharts/highcharts-react-native – Sebastian Bochan Commented Sep 2, 2019 at 8:38
- Thanks, @SebastianBochan I tried using the wrapper, but currently, there is this issue that is preventing me from using it. – mukesh.kumar Commented Sep 3, 2019 at 6:35
1 Answer
Reset to default 8<View
style={{
flex:1
}}
>
<WebView
scalesPageToFit
originWhitelist={["*"]}
source={{ uri:"file:///android_asset/highcharts/index.htm",baseUrl:"file:///android_asset/highcharts/"
}}/>
</View>
Here is a working example of highchart in react-native-webview
.
- 1.First move all your
html/js
code to the following directory:your_project/android/app/src/main/assets/
. If theassets
folder does not exist already, create it. - Now paste all your
html/css/js
code in theassets
folder you have created - close your terminal/cmd/bash or whatever you use to run
react-native run-android
mand. - Run the following mand now.
react-native run-android
. Now paste the above code in your
.js
file. Seturi
to the path to your html file such asuri:"file:///android_asset/YOUR_HTML_FILE"
and yourbaseUrl:"file:///android_asset/YOUR_MAIN_FOLDER/"