More bug fixes

This commit is contained in:
John Lyon-Smith
2018-04-29 14:56:39 -07:00
parent c403c43c1c
commit 7b20b18aeb
4 changed files with 59 additions and 77 deletions

View File

@@ -26,19 +26,6 @@ export const ensurePermissions = (
onSuccess, onSuccess,
onError onError
) => { ) => {
if (Platform.OS === "ios") {
if (onSuccess) {
onSuccess(
permissions.reduce(
(dict, permission) =>
(dict[permission] = PermissionsAndroid.RESULTS.GRANTED),
{}
)
)
}
return
}
PermissionsAndroid.requestMultiple(permissions, rationale) PermissionsAndroid.requestMultiple(permissions, rationale)
.then((results) => { .then((results) => {
if ( if (

View File

@@ -3,5 +3,5 @@ import { Route, Redirect } from "react-router-native"
export const DefaultRoute = () => { export const DefaultRoute = () => {
// NOTE: When working on the app, change this to the page you are working on // NOTE: When working on the app, change this to the page you are working on
return <Route render={() => <Redirect to={"/workItem"} />} /> return <Route render={() => <Redirect to={"/home"} />} />
} }

View File

@@ -43,54 +43,61 @@ export class Home extends React.Component {
sections: [], sections: [],
showWorkItems: true, showWorkItems: true,
region: config.initialRegion, region: config.initialRegion,
positionInfo: null,
haveCameraPermission: false, haveCameraPermission: false,
workItemDistance: -1, workItemDistance: -1,
} }
this.positionInfo = null
this.watchId = null this.watchId = null
ensurePermissions( if (Platform.OS !== "ios") {
[ ensurePermissions(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, [
PermissionsAndroid.PERMISSIONS.CAMERA, PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, PermissionsAndroid.PERMISSIONS.CAMERA,
], PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{ ],
title: versionInfo.title, {
message: title: versionInfo.title,
"This app needs these permissions so that you can " + message:
"find, access and photograph geo located items.", "This app needs these permissions so that you can " +
}, "find, access and photograph geo located items.",
(results) => { },
if ( (results) => {
results[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] === if (
PermissionsAndroid.RESULTS.GRANTED results[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] ===
) { PermissionsAndroid.RESULTS.GRANTED
this.setState({ haveLocationPermission: true }) ) {
navigator.geolocation.getCurrentPosition(this.handlePositionChange) this.setState({ haveLocationPermission: true })
} navigator.geolocation.getCurrentPosition(this.handlePositionChange)
}
if ( if (
results[PermissionsAndroid.PERMISSIONS.CAMERA] === results[PermissionsAndroid.PERMISSIONS.CAMERA] ===
PermissionsAndroid.RESULTS.GRANTED PermissionsAndroid.RESULTS.GRANTED
) { ) {
this.setState({ haveCameraPermission: true }) 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.",
},
})
} }
}, )
() => { } else {
this.setState({ this.state.haveLocationPermission = true
messageModal: { this.state.haveCameraPermission = true
icon: "hand", navigator.geolocation.getCurrentPosition(this.handlePositionChange)
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.",
},
})
}
)
api api
.listTeams() .listTeams()
@@ -140,7 +147,7 @@ export class Home extends React.Component {
@autobind @autobind
handlePositionChange(positionInfo) { handlePositionChange(positionInfo) {
this.setState({ positionInfo }) this.positionInfo = positionInfo
} }
@autobind @autobind
@@ -153,8 +160,8 @@ export class Home extends React.Component {
}) })
} }
if (this.state.positionInfo) { if (this.positionInfo) {
const coords = this.state.positionInfo.coords const coords = this.positionInfo.coords
const workItem = this.state.sections[sectionIndex] const workItem = this.state.sections[sectionIndex]
const { latitude, longitude } = workItem.coordinate const { latitude, longitude } = workItem.coordinate
@@ -172,10 +179,8 @@ export class Home extends React.Component {
@autobind @autobind
handleWorkItemsListPress() { handleWorkItemsListPress() {
const { positionInfo } = this.state if (this.positionInfo) {
const { coords } = this.positionInfo
if (positionInfo) {
const { coords } = positionInfo
this.props.history.push( this.props.history.push(
`/workItemList?latLng=${coords.latitude},${coords.longitude}` `/workItemList?latLng=${coords.latitude},${coords.longitude}`
@@ -213,7 +218,7 @@ export class Home extends React.Component {
const { const {
latitude: latitude1, latitude: latitude1,
longitude: longitude1, longitude: longitude1,
} = this.state.positionInfo.coords } = this.positionInfo.coords
let closestWorkItem = config.alwaysShowWorkItemInAR ? workItems[0] : null let closestWorkItem = config.alwaysShowWorkItemInAR ? workItems[0] : null
let shortestDistance = config.minDistanceToItem let shortestDistance = config.minDistanceToItem
@@ -242,8 +247,8 @@ export class Home extends React.Component {
@autobind @autobind
handleMyLocationPress() { handleMyLocationPress() {
if (this.state.positionInfo) { if (this.positionInfo) {
const coords = this.state.positionInfo.coords const coords = this.positionInfo.coords
this.map.animateToCoordinate({ this.map.animateToCoordinate({
latitude: coords.latitude, latitude: coords.latitude,
@@ -262,7 +267,6 @@ export class Home extends React.Component {
sections, sections,
showWorkItems, showWorkItems,
region, region,
positionInfo,
messageModal, messageModal,
haveCameraPermission, haveCameraPermission,
haveLocationPermission, haveLocationPermission,
@@ -288,14 +292,7 @@ export class Home extends React.Component {
title="Work Item Map" title="Work Item Map"
leftButton={{ icon: "logout", onPress: this.handleLogoutPress }} leftButton={{ icon: "logout", onPress: this.handleLogoutPress }}
rightButton={{ icon: "glasses", onPress: this.handleGlassesPress }} rightButton={{ icon: "glasses", onPress: this.handleGlassesPress }}
disabled={ disabled={!haveCameraPermission || !haveLocationPermission}
!(
positionInfo &&
positionInfo.coords.accuracy <= config.minGPSAccuracy
) ||
!haveCameraPermission ||
!haveLocationPermission
}
/> />
<MapView <MapView
ref={(ref) => { ref={(ref) => {
@@ -484,9 +481,7 @@ export class Home extends React.Component {
backgroundColor: "#F4F4F4", backgroundColor: "#F4F4F4",
...ifIphoneX({ marginBottom: 22 }, {}), ...ifIphoneX({ marginBottom: 22 }, {}),
}}> }}>
<TouchableOpacity <TouchableOpacity onPress={this.handleMyLocationPress}>
disabled={!positionInfo}
onPress={this.handleMyLocationPress}>
<Icon <Icon
name="center" name="center"
size={24} size={24}

View File

@@ -217,7 +217,7 @@ export class WorkItem extends React.Component {
if (this.addressInput) { if (this.addressInput) {
this.addressInput.handleChangeText(address) this.addressInput.handleChangeText(address)
} }
this.setState({ region: ref.mapView.region }) this.setState({ region: this.mapView.region })
}) })
.catch(() => { .catch(() => {
if (this.addressInput) { if (this.addressInput) {