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,
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 (

View File

@@ -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 <Route render={() => <Redirect to={"/workItem"} />} />
return <Route render={() => <Redirect to={"/home"} />} />
}

View File

@@ -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}
/>
<MapView
ref={(ref) => {
@@ -484,9 +481,7 @@ export class Home extends React.Component {
backgroundColor: "#F4F4F4",
...ifIphoneX({ marginBottom: 22 }, {}),
}}>
<TouchableOpacity
disabled={!positionInfo}
onPress={this.handleMyLocationPress}>
<TouchableOpacity onPress={this.handleMyLocationPress}>
<Icon
name="center"
size={24}

View File

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