react native webview starting uri code example
Example 1: react native webview
import React from 'react'
import { StyleSheet, SafeView, WebView, View, Text } from 'react-native'
const App = () => (
<SafeView>
<View style={styles.container}>
<WebView
source={{
uri: 'https://reactjs.org/',
headers: {
'Access-Control-Allow-Methods': '*',
'Access-Control-Allow-Origin': '*'
}
}}
renderLoading={() => <Text style={styles.loading}>Loading...</Text>}
startInLoadingState
domStorageEnabled
geolocationEnabled
allowUniversalAccessFromFileURLs
allowFileAccess
/>
</View>
</SafeView>
)
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 0,
margin: 0
},
loading: {
fontSize: 24,
fontWeight: 'bold'
}
})
export default App
Example 2: how to reload webview in react native
You can set a key to the webview
key={this.state.key}
and then you can reload it by updating the state
this.setState({ key: this.state.key + 1 });