react native webview load from device local file system

后端 未结 5 1172
萌比男神i
萌比男神i 2020-12-07 21:08

I\'m trying to load .html, .js, .css files from device\'s local file system into React Native WebView component. I was able to get the

5条回答
  •  一生所求
    2020-12-07 21:55

    Place this script in any file of ReactNative or your code, recomended to first or top index file. And it will fix problem, tested on RN0.39

    import { Platform } from 'react-native';
    import { setCustomSourceTransformer } from 'react-native/Libraries/Image/resolveAssetSource';
    
    setCustomSourceTransformer(function (resolver) {
    
      if (Platform.OS === 'android'
        && !resolver.serverUrl
        && !resolver.bundlePath
        && resolver.asset.type === 'html') {
        resolver.bundlePath = '/android_asset/';
      }
    
      return resolver.defaultAsset();
    });
    

提交回复
热议问题