问题描述
我正在创建一个 webview,当单击 backHandler 时返回上一页,但我希望当您处于初始状态并单击返回关闭应用程序时,有人可以帮助我!!!
const [canGoBack,setCanGoBack] = useState(false)
const [currentUrl,setCurrentUrl] = useState('')
const webviewRef = useRef(null)
useEffect(() => {
const backAction = () => {
if(webviewRef.current) webviewRef.current.goBack()
return true;
};
const backHandler = BackHandler.addEventListener(
"hardwareBackPress",backAction,);
return () => {
backHandler.remove();
};
},[]);
< WebView
onLoadStart={() => (showSpinner())}
onLoadEnd={() => hideSpinner()}
source = { { uri : 'https://treinamento.viashopmoda.com.br/?origem=app' } }
ref={webviewRef}
onNavigationStateChange={navstate => {
setCanGoBack(navstate.canGoBack)
setCurrentUrl(navstate.url)
}}
renderError={() =>
<View style={styles.loadingOrErrorView}>
<View style={styles.container}>
<Text style={{fontSize:25,marginBottom:25,color:'#BEBEBE',textAlign:'center'}}>Não foi possível conectar-se a internet</Text>
<TouchableOpacity style={styles.botao} onPress={()=>recarregar()}>
<Text style={{color:'#BEBEBE',fontSize:18,textAlign:'center'}}>Repetir</Text>
</TouchableOpacity>
</View>
</View>
}
/>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)