Additional tweaks for permission checks

This commit is contained in:
John Lyon-Smith
2018-04-15 17:50:07 -07:00
parent a4a81cf6ca
commit 6d568efbee
7 changed files with 40 additions and 8 deletions

View File

@@ -2,7 +2,7 @@ import EventEmitter from "eventemitter3"
import io from "socket.io-client"
import { AsyncStorage } from "react-native"
import autobind from "autobind-decorator"
import { localIPAddr } from "./development"
import { localIPAddr } from "./config"
const authTokenKeyName = "AuthToken"
const backendKeyName = "Backend"

View File

@@ -137,6 +137,11 @@ class WorkItemSceneAR extends React.Component {
})
}
@autobind
handleClick(position, source) {
// this.props.history.replace("/activity")
}
render() {
const { position, scale, rotation, shouldBillboard } = this.state
@@ -166,6 +171,7 @@ class WorkItemSceneAR extends React.Component {
resources={shapes["hardhat"].materials}
type="OBJ"
onLoadEnd={this.handleLoadEnd}
onClick={this.handleClick}
/>
<ViroSurface
rotation={[-90, 0, 0]}
@@ -187,7 +193,7 @@ export class ARViewer extends React.Component {
}
@autobind
_handlePress() {
handleBackPress() {
this.props.history.replace("/")
}
@@ -203,7 +209,7 @@ export class ARViewer extends React.Component {
<View style={{ position: "absolute", left: 30, right: 0, top: 50 }}>
<TouchableHighlight
style={styles.buttons}
onPress={this._handlePress}
onPress={this.handleBackPress}
underlayColor={"#00000000"}>
<Image source={backImage} />
</TouchableHighlight>

View File

@@ -4,6 +4,7 @@ import {
StyleSheet,
AsyncStorage,
PermissionsAndroid,
Platform,
} from "react-native"
import { NativeRouter, Route, Link, Switch } from "react-router-native"
import MapView from "react-native-maps"
@@ -26,6 +27,13 @@ export const ensurePermission = (
onSuccess,
onError
) => {
if (Platform.OS === "ios") {
if (onSuccess) {
onSuccess()
}
return
}
PermissionsAndroid.check(permission)
.then((flag) => {
if (flag) {

View File

@@ -19,7 +19,7 @@ import KeyboardSpacer from "react-native-keyboard-spacer"
import { versionInfo } from "../version"
import autobind from "autobind-decorator"
import { isIphoneX } from "react-native-iphone-x-helper"
import { defaultUser } from "../development"
import { defaultUser } from "../config"
export class Login extends React.Component {
static bindings = {

View File

@@ -19,10 +19,11 @@ import { ifIphoneX } from "react-native-iphone-x-helper"
import { workItemTypeText, pad, regionContainingPoints } from "../util"
import { ensurePermission } from "../App"
import { versionInfo } from "../version"
import { minGPSAccuracy } from "../config"
import pinImage from "./images/pin.png"
const minGPSAccuracy = 20
const neverAskForLocationPermissionKeyName = "NeverAskForLocationPermission"
const neverAskForCameraKeyName = "NeverAskForCameraPermission"
export class Home extends React.Component {
constructor(props) {
@@ -37,6 +38,7 @@ export class Home extends React.Component {
longitudeDelta: 0.0922,
},
positionInfo: null,
allowCameraAccess: false,
}
ensurePermission(
@@ -57,6 +59,20 @@ export class Home extends React.Component {
}
)
ensurePermission(
PermissionsAndroid.PERMISSIONS.CAMERA,
neverAskForCameraKeyName,
{
title: versionInfo.title,
message:
"This app needs access to your camera so that " +
"you can view AR items.",
},
() => {
this.setState({ allowCameraAccess: true })
}
)
api
.listWorkItemActivities()
.then((list) => {

5
mobile/src/config.js Normal file
View File

@@ -0,0 +1,5 @@
export const localIPAddr = "192.168.1.175"
export const defaultUser = "john@lyon-smith.org"
//export const defaultUser = ""
// export const minGPSAccuracy = 20
export const minGPSAccuracy = 100

View File

@@ -1,3 +0,0 @@
export const localIPAddr = "192.168.1.175"
//export const defaultUser = "john@lyon-smith.org"
export const defaultUser = ""