I am trying to show a simple webview in my react native application.
This is the code I'm trying:
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {WebView} from 'react-native-webview';
export default function App() {
return (
<View style={{flex: 1}}>
<WebView
source={{uri: 'https://logrocket.com/'}}
style={{marginTop: 20}}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
When I run this code I get a single red pixel on the screen. I don't know why I get this and I don't know how to debug it, because I don't see any errors.
I am using the latest version of React Native.
This is what the output of the code looks like on my end:
Try this... will work
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native-webview';
export default function App() {
return (
<WebView
source={{ uri: 'https://logrocket.com/' }}
style={{ marginTop: 20}}
/>
);
}
import React from 'react';
import {View, Image} from 'react-native';
import {WebView} from 'react-native-webview';
const Test= () => {
return (
<View style={{flex: 1}}>
<WebView
originWhitelist={['*']}
source={{html: a}}
style={{width:"100%", height: 300}}
/>
<View></View>
</View>
);
};
export default Test;
const a = `
<body>
</body>
`
This is my working code
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.