(React Native) Load local HTML file into WebView

后端 未结 4 523
滥情空心
滥情空心 2020-12-09 15:25

I try to load the local .html file into WebView in React Native:

// load lo         


        
相关标签:
4条回答
  • try it:

    const PolicyHTML = require('./Policy.html');
    
    <WebView
      source={PolicyHTML}
      style={{flex: 1}}
     />
    
    0 讨论(0)
  • 2020-12-09 15:56

    Try this :

    • Add your .html file in your project.
    • Write such lines of code in the file where you want to use WebView Component

      const OurStoryHTML = require ('./OurStory.html')

    • <WebView source={OurStoryHTML} style={{flex: 1, marginTop : 44}} />

    It may help you.

    0 讨论(0)
  • 2020-12-09 16:02
    <View style={{flex: 1}}>
        <WebView
          style={{flex: 1}}
          source={require("./resources/index.html")}
        />
    </View>
    

    To make WebView, the parent has to has a dimension or flex:1. We could set the WebView to flex: 1 too so that it fills up the parent.

    0 讨论(0)
  • 2020-12-09 16:16

    I come across this post searching for loading static html.
    If your html code is retrieved using, for example, an API, you can render WebView in this way:

    <WebView
        originWhitelist={['*']}
        source={{ html: html, baseUrl: '' }}
    />
    

    Notice that originWhitelistis required as explained in the documentation:

    Note that static html will require setting of originWhitelist for example to ["*"].

    0 讨论(0)
提交回复
热议问题