I try to display a text when webview is loaded but ActivityIndicator doesn't dissapear.
I've tried to create a hook with a boolean variable which changes when webview is loaded, then it would should show the text "Hello, I am your cat." in the first condition.
import React,{useState} from 'react';
import { Text, StyleSheet, View, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview';
const Cat = () => {
return (
<Cat />
);
}
const Cafe = () => {
const [ok, setOk] = useState(false);
return (
ok ?
<Text>Hello, I am your cat!</Text>
:
<View style={styles.container}>
<View style={{height: 0, width: 0}}>
<WebView
source={{uri: "https://www.google.com/"}}
onLoad={() => {
setOk(true)
console.log(ok);
}}
/>
</View>
<ActivityIndicator size="large" color="#E60081"/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#000',
alignItems: 'center',
justifyContent: 'center',
},
});
export default Cafe;
You were passing a reference to your onLoad
function. Try below code.
<WebView
source={{uri: "https://www.google.com/"}}
onLoad={setOk(true)}
/>
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.