2017-07-21 105 views
0

我是React Native中的新成員,我嘗試在WebView中加載本地.html文件,但不幸的是應用程序崩潰時沒有任何登錄控制檯。從文件加載本地HTML

我的代碼是非常簡單的:

import React, { Component } from 'react'; 
import { AppRegistry, View, Text, Dimensions, WebView} from 'react-native'; 

class HTMLLoader extends Component { 
    render() { 
    const PolicyHTML = require('./text.html'); 

    var {height, width} = Dimensions.get('window'); 

    return (
     <WebView 
      source={{html: PolicyHTML}} 
      style={{width: width, height: height}} 
     /> 
    ); 
    } 
} 

export default class IScrolledDownAndWhatHappenedNextShockedMe extends Component { 
    render() { 
     return (
      <HTMLLoader/> 
    ); 
    } 
} 

// skip these lines if using Create React Native App 
AppRegistry.registerComponent(
    'AwesomeProject', 
() => IScrolledDownAndWhatHappenedNextShockedMe); 

這就是.html文件的內容:

<!DOCTYPE html> 
<html> 
<body> 

<h1>My First Heading</h1> 
<p>My first paragraph.</p> 

</body> 
</html> 

任何暗示會受到歡迎。由於

回答

0

我已經找到答案了我的問題,更新return已經公佈如下:

return (
    <WebView 
     source={PolicyHTML} // object should be assigned directly to the WebView source property 
     style={{width: width, height: height}} 
    /> 
);