onNavigationStateChange is not working on Android in Expo App
See original GitHub issueHey, in the current Version “react-native-webview”: “8.1.1” the onNavigationStateChange event is not triggered in any Android device. On iOS it works perfectly. It is no normal # tag url change, it is a real change from /home to /dashboard.
import React, {
useEffect,
useState,
useRef,
useCallback,
StyleSheet,
useContext,
} from "react";
import {
RefreshControl,
ActivityIndicator,
View,
ScrollView,
Alert,
} from "react-native";
import { WebView } from "react-native-webview";
const WebViewComponent = (props) => {
const [refreshing, setRefreshing] = useState(false);
const [loaded, isLoaded] = useState(false);
const [urlReal, setUrl] = useState((props?.url != undefined
? props.url
: "httsp://google.com)
);
const webViewRef = useRef();
const onRefresh = useCallback(async () => {
setRefreshing(true);
webViewRef.current.reload();
setRefreshing(false);
}, [refreshing]);
const _onNavigationStateChange = (webViewState) => {
console.log(webViewState.url);
// no action on android
};
return (
<View>
<ScrollView
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
}
>
<WebView
ref={(ref) => (webViewRef.current = ref)}
onLoadStart={(e) => {
console.log("onLoadStart");
}}
onLoad={(e) => {
console.log("onLoad");
}}
onLoadEnd={(e) => {
console.log("onLoadEnd");
}}
renderError={(e) => {
console.log("renderError");
}}
source={{
uri: urlReal,
}}
startInLoadingState={true}
domStorageEnabled={true}
javaScriptEnabled={true}
onNavigationStateChange={(e) => _onNavigationStateChange(e)}
thirdPartyCookiesEnabled={true}
/>
</ScrollView>
</View>
);
};
Environment:
- OS: Andriod
- expo version: 37.0.3
- react-native-webview version: 8.1.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:18
Top Results From Across the Web
onNavigationStateChange not working in Android React Native
Based on your comment I understand that you want to have a WebView in your react native app and inside there to load...
Read more >onNavigationStateChange is not working on Android in Expo ...
Hey, in the current Version "react-native-webview": "8.1.1" the onNavigationStateChange event is not triggered in any Android device.
Read more >onNavigationStateChange of WebView on android get url with ...
Changing source to uri from url was my fix. This was only happening to me on Android, onNavigationStateChange was returning url "about:blank". Cheers:...
Read more >Monitor your React Native application
With our React Native agent, your team can monitor the performance of its hybrid apps and identify code errors. Our agent collects crash...
Read more >react-native-webview - npm
React Native WebView component for iOS, Android, macOS, and Windows. ... Start using react-native-webview in your project by running `npm i ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This issue still exists. I’m seeing it on React Native 0.61.0 and react-native-webview 10.9.1
That was for an internal fix.
Check below link for an idea. You could find some way to send route change in the SPA to the react native application.
https://stackoverflow.com/questions/53297300/how-to-communcation-between-web-inside-webview-back-to-react-native-apps