From a4de620727d4e7d294ced1d1e1c956c0be8c0cd2 Mon Sep 17 00:00:00 2001 From: ivanshen Date: Thu, 28 Mar 2019 13:22:37 -0400 Subject: feat 28: get location when user selects use current location --- mobile/components/GreetingPage.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/mobile/components/GreetingPage.js b/mobile/components/GreetingPage.js index 9301fbc..84c20e7 100644 --- a/mobile/components/GreetingPage.js +++ b/mobile/components/GreetingPage.js @@ -14,10 +14,10 @@ export default class GreetingPage extends Component { // runs as soon as page is loaded componentDidMount() { // immediately attempt to get the location - this._getLocationAsync(); + // this._getLocationAsync(); } - _getLocationAsync = async () => { + moveToFormPage = async () => { // ask location services to allow location access to THIS app. // Note: location services itself must still be enabled for this! const {status} = await Permissions.askAsync(Permissions.LOCATION); @@ -27,6 +27,12 @@ export default class GreetingPage extends Component { this.setState({locationResult: position.coords}); // since we are guaranteed to have the location here, its safe to load the full view this.setState({isLoading: false}); + // move to form page + this.props.navigation.navigate('FormPage', + {coordinates : [ + this.state.locationResult.longitude, + this.state.locationResult.latitude] + }); }).catch((e) => { alert(e + ' Please make sure your location (GPS) is turned on.'); }); @@ -37,14 +43,6 @@ export default class GreetingPage extends Component { } }; - moveToFormPage = () => { - this.props.navigation.navigate('FormPage', - {coordinates : [ - this.state.locationResult.longitude, - this.state.locationResult.latitude] - }); - }; - render() { // acts like the way
does in JavaScript @@ -77,7 +75,7 @@ export default class GreetingPage extends Component { { this.moveToFormPage() }}> + onPress={() => { this.moveToFormPage(); }}> -- cgit v1.2.3