最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Add Local HTML and JS file using React Native Webview - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

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. 1.First move all your html/js code to the following directory: your_project/android/app/src/main/assets/. If the assets folder does not exist already, create it.
  2. Now paste all your html/css/js code in the assets folder you have created
  3. close your terminal/cmd/bash or whatever you use to run react-native run-android mand.
  4. Run the following mand now. react-native run-android.
  5. Now paste the above code in your .js file. Set uri to the path to your html file such as uri:"file:///android_asset/YOUR_HTML_FILE" and your baseUrl:"file:///android_asset/YOUR_MAIN_FOLDER/"

发布评论

评论列表(0)

  1. 暂无评论