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

Load html file from device storage react native - Stack Overflow

programmeradmin2浏览0评论

Hi am trying to load html file in Download folder to render in my React Native application.

   <WebView
      originWhitelist={['*']}
      scrollEnabled={false}
      source={{
              uri: 'file:///storage/emulated/0/Documents/Test.html',
              baseUrl: '',
        }}
      style={{flex: 1}}
      allowFileAccess={true}
      allowUniversalAccessFromFileURLs={true}
      onLoadEnd={updateSource}
      onError={error => console.log('Error', error)}
    />

The above is what I have tried and failed. The above code ends up in showing a white blank page.

Any help is appreciated Thanks

Hi am trying to load html file in Download folder to render in my React Native application.

   <WebView
      originWhitelist={['*']}
      scrollEnabled={false}
      source={{
              uri: 'file:///storage/emulated/0/Documents/Test.html',
              baseUrl: '',
        }}
      style={{flex: 1}}
      allowFileAccess={true}
      allowUniversalAccessFromFileURLs={true}
      onLoadEnd={updateSource}
      onError={error => console.log('Error', error)}
    />

The above is what I have tried and failed. The above code ends up in showing a white blank page.

Any help is appreciated Thanks

Share Improve this question asked Mar 9 at 7:11 sujasuja 1,2882 gold badges14 silver badges33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Please ensure that the path to your file is correct. It is also not completely clear if you have already handled read permissions in your app.

If you haven't, you need to also first grant them e.g., by using PermissionsAndroid.

You have also hardcoded the path to your file, which is probably problematic. A rather simpler way to manage your local file paths (for both iOS and Android) is by using react-native-fs.

发布评论

评论列表(0)

  1. 暂无评论