I’ve started a week ago expo to publish my site to App with webview.
And I made my App with the code below. But,
problem is…
When I press back-button of android, my app turns off.
I want to make that, when I click back-button of android, my webview go back the page that I read just before.
Can I get some help? Thanks. (My English is a little poor. Sorry.)
import React, { Component } from 'react';
import { StyleSheet, Text, View,WebView } from 'react-native';
import { Button } from 'react-native';
export default class App extends Component {
onNavigationStateChange = navState => {
if (navState.url.indexOf('https://www.google.com') === 0) {
const regex = /#access_token=(.+)/;
let accessToken = navState.url.match(regex)[1];
console.log(accessToken);
}
};
render() {
const url = 'https://nandallinda.com';
return (
<View style={{marginTop: 24, flex:1, backgroundColor: '#fff'}}>
<WebView
source={{
uri: url,
}}
startInLoadingState
scalesPageToFit
javaScriptEnabled
style={{ flex: 1 }}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center'
},
});
.