From 7b20b18aebeb644a36255842ca5f7051e6d2bd79 Mon Sep 17 00:00:00 2001 From: John Lyon-Smith Date: Sun, 29 Apr 2018 14:56:39 -0700 Subject: [PATCH] More bug fixes --- mobile/src/App.js | 13 ---- mobile/src/Auth/DefaultRoute.js | 2 +- mobile/src/Home/Home.js | 119 +++++++++++++++----------------- mobile/src/WorkItem/WorkItem.js | 2 +- 4 files changed, 59 insertions(+), 77 deletions(-) diff --git a/mobile/src/App.js b/mobile/src/App.js index 39fbde5..44a1066 100644 --- a/mobile/src/App.js +++ b/mobile/src/App.js @@ -26,19 +26,6 @@ export const ensurePermissions = ( onSuccess, onError ) => { - if (Platform.OS === "ios") { - if (onSuccess) { - onSuccess( - permissions.reduce( - (dict, permission) => - (dict[permission] = PermissionsAndroid.RESULTS.GRANTED), - {} - ) - ) - } - return - } - PermissionsAndroid.requestMultiple(permissions, rationale) .then((results) => { if ( diff --git a/mobile/src/Auth/DefaultRoute.js b/mobile/src/Auth/DefaultRoute.js index 6735acf..43027b5 100644 --- a/mobile/src/Auth/DefaultRoute.js +++ b/mobile/src/Auth/DefaultRoute.js @@ -3,5 +3,5 @@ import { Route, Redirect } from "react-router-native" export const DefaultRoute = () => { // NOTE: When working on the app, change this to the page you are working on - return } /> + return } /> } diff --git a/mobile/src/Home/Home.js b/mobile/src/Home/Home.js index c713a1f..aa5643f 100644 --- a/mobile/src/Home/Home.js +++ b/mobile/src/Home/Home.js @@ -43,54 +43,61 @@ export class Home extends React.Component { sections: [], showWorkItems: true, region: config.initialRegion, - positionInfo: null, haveCameraPermission: false, workItemDistance: -1, } + this.positionInfo = null this.watchId = null - ensurePermissions( - [ - PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, - PermissionsAndroid.PERMISSIONS.CAMERA, - PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, - ], - { - title: versionInfo.title, - message: - "This app needs these permissions so that you can " + - "find, access and photograph geo located items.", - }, - (results) => { - if ( - results[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] === - PermissionsAndroid.RESULTS.GRANTED - ) { - this.setState({ haveLocationPermission: true }) - navigator.geolocation.getCurrentPosition(this.handlePositionChange) - } + if (Platform.OS !== "ios") { + ensurePermissions( + [ + PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, + PermissionsAndroid.PERMISSIONS.CAMERA, + PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, + ], + { + title: versionInfo.title, + message: + "This app needs these permissions so that you can " + + "find, access and photograph geo located items.", + }, + (results) => { + if ( + results[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] === + PermissionsAndroid.RESULTS.GRANTED + ) { + this.setState({ haveLocationPermission: true }) + navigator.geolocation.getCurrentPosition(this.handlePositionChange) + } - if ( - results[PermissionsAndroid.PERMISSIONS.CAMERA] === - PermissionsAndroid.RESULTS.GRANTED - ) { - this.setState({ haveCameraPermission: true }) + if ( + results[PermissionsAndroid.PERMISSIONS.CAMERA] === + PermissionsAndroid.RESULTS.GRANTED + ) { + this.setState({ haveCameraPermission: true }) + } + }, + () => { + this.setState({ + messageModal: { + icon: "hand", + message: + "You have denied the app access to phone features it needs to function. " + + "Some parts of the app are disabled.", + detail: + "To enable these features in future " + + "please go to Settings.", + }, + }) } - }, - () => { - this.setState({ - messageModal: { - icon: "hand", - message: - "You have denied the app access to phone features it needs to function. " + - "Some parts of the app are disabled.", - detail: - "To enable these features in future " + "please go to Settings.", - }, - }) - } - ) + ) + } else { + this.state.haveLocationPermission = true + this.state.haveCameraPermission = true + navigator.geolocation.getCurrentPosition(this.handlePositionChange) + } api .listTeams() @@ -140,7 +147,7 @@ export class Home extends React.Component { @autobind handlePositionChange(positionInfo) { - this.setState({ positionInfo }) + this.positionInfo = positionInfo } @autobind @@ -153,8 +160,8 @@ export class Home extends React.Component { }) } - if (this.state.positionInfo) { - const coords = this.state.positionInfo.coords + if (this.positionInfo) { + const coords = this.positionInfo.coords const workItem = this.state.sections[sectionIndex] const { latitude, longitude } = workItem.coordinate @@ -172,10 +179,8 @@ export class Home extends React.Component { @autobind handleWorkItemsListPress() { - const { positionInfo } = this.state - - if (positionInfo) { - const { coords } = positionInfo + if (this.positionInfo) { + const { coords } = this.positionInfo this.props.history.push( `/workItemList?latLng=${coords.latitude},${coords.longitude}` @@ -213,7 +218,7 @@ export class Home extends React.Component { const { latitude: latitude1, longitude: longitude1, - } = this.state.positionInfo.coords + } = this.positionInfo.coords let closestWorkItem = config.alwaysShowWorkItemInAR ? workItems[0] : null let shortestDistance = config.minDistanceToItem @@ -242,8 +247,8 @@ export class Home extends React.Component { @autobind handleMyLocationPress() { - if (this.state.positionInfo) { - const coords = this.state.positionInfo.coords + if (this.positionInfo) { + const coords = this.positionInfo.coords this.map.animateToCoordinate({ latitude: coords.latitude, @@ -262,7 +267,6 @@ export class Home extends React.Component { sections, showWorkItems, region, - positionInfo, messageModal, haveCameraPermission, haveLocationPermission, @@ -288,14 +292,7 @@ export class Home extends React.Component { title="Work Item Map" leftButton={{ icon: "logout", onPress: this.handleLogoutPress }} rightButton={{ icon: "glasses", onPress: this.handleGlassesPress }} - disabled={ - !( - positionInfo && - positionInfo.coords.accuracy <= config.minGPSAccuracy - ) || - !haveCameraPermission || - !haveLocationPermission - } + disabled={!haveCameraPermission || !haveLocationPermission} /> { @@ -484,9 +481,7 @@ export class Home extends React.Component { backgroundColor: "#F4F4F4", ...ifIphoneX({ marginBottom: 22 }, {}), }}> - + { if (this.addressInput) {