【问题标题】:Blank screen on Loading document fom uri in Expo's webview在 Expo webview 中从 uri 加载文档时出现空白屏幕
【发布时间】:2020-07-12 09:00:44
【问题描述】:

我正在使用 Expo 。 import { WebView } from "react-native-webview"; 并像上面一样导入 webview 我正在尝试从一些 https url 加载文档文件,它工作正常并在 IOS 中加载 xls 文件,但在 android 中它给出了一个空白屏幕。

 <WebView
  originWhitelist={["*"]}
  source={{ uri: 'https://download.microsoft.com/download/1/4/E/14EDED28-6C58-4055-A65C-23B4DA81C4DE/Financial%20Sample.xlsx' }}
  onLoadEnd={() =>  console.log('end' +Platform.OS)}
  javaScriptEnabled={true}
  domStorageEnabled={true}
  useWebKit={true}
  style={styles.WebViewStyle}
  startInLoadingState={true}
/>

const styles = {  
  WebViewStyle: {
    flex: 1,
    marginLeft: 6,
    height: "50%",
    width: "97%"
  }
}

onLoadEnd 的console.log 不适用于 android,但适用于 IOS。

【问题讨论】:

    标签: android react-native webview expo react-native-webview


    【解决方案1】:

    您可以尝试使用 Linking,因为 WebView 是在您的应用程序中显示网页的视图。

    import * as Linking from 'expo-linking';
    
    Linking.openURL('https://download.microsoft.com/download/1/4/E/14EDED28-6C58-4055-A65C-23B4DA81C4DE/Financial%20Sample.xlsx');
    

    【讨论】:

    • 是的,我可以这样做,但这并不能解决我的目的。我想在新屏幕上打开我的应用程序中的文档。我的方法在 IOS 上运行良好,但我不知道为什么不能在 android 上运行。
    • 你提到过这些道具吗? myinitialurl.com.br/arquivos" }} style={{}} startInLoadingState={true} allowUniversalAccessFromFileURLs={true} javaScriptEnabled={true} mixedContentMode={'always'} onNavigationStateChange={(result) = > this.handleUrlWithZip(result)} />
    • activityIndi​​catorLoadingView} startInLoadingState={true} /> 是的,但我没有使用 onNavigationStateChange没用过
    • 感谢您抽出宝贵时间帮助我。我为您创建了一个蛇形链接,以便您了解实际发生的情况。当您运行它时,您会发现它在 IOS 中运行良好,但在 android 中却不行:snack.expo.io/@gd_11/874548 请查看并帮助。
    猜你喜欢
    • 1970-01-01
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    • 2014-04-19
    相关资源
    最近更新 更多