Rename file
This commit is contained in:
100
mobile/src/App.js
Normal file
100
mobile/src/App.js
Normal file
@@ -0,0 +1,100 @@
|
||||
import React from "react"
|
||||
import {
|
||||
View,
|
||||
StyleSheet,
|
||||
AsyncStorage,
|
||||
PermissionsAndroid,
|
||||
} from "react-native"
|
||||
import { NativeRouter, Route, Link, Switch } from "react-router-native"
|
||||
import MapView from "react-native-maps"
|
||||
import { WorkItem, WorkItemList } from "./WorkItem"
|
||||
import { Activity } from "./Activity"
|
||||
import { Home } from "./Home"
|
||||
import { ARViewer } from "./ARViewer"
|
||||
import { Login, Logout, ProtectedRoute, DefaultRoute } from "./Auth"
|
||||
|
||||
console.ignoredYellowBox = [
|
||||
// See https://github.com/facebook/react-native/issues/12981
|
||||
"Setting a timer",
|
||||
"<ViroSurface>",
|
||||
]
|
||||
|
||||
export const ensurePermission = (
|
||||
permission,
|
||||
neverAskKeyName,
|
||||
rationale,
|
||||
onSuccess,
|
||||
onError
|
||||
) => {
|
||||
PermissionsAndroid.check(permission)
|
||||
.then((flag) => {
|
||||
if (flag) {
|
||||
if (onSuccess) {
|
||||
onSuccess()
|
||||
}
|
||||
return
|
||||
}
|
||||
return AsyncStorage.getItem(neverAskKeyName)
|
||||
})
|
||||
.then((value) => {
|
||||
if (value === "YES") {
|
||||
return
|
||||
} else {
|
||||
return PermissionsAndroid.request(permission, rationale)
|
||||
}
|
||||
})
|
||||
.then((result) => {
|
||||
if (result === PermissionsAndroid.RESULTS.GRANTED) {
|
||||
if (onSuccess) {
|
||||
onSuccess()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (result === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) {
|
||||
AsyncStorage.setItem(neverAskKeyName, "YES")
|
||||
}
|
||||
|
||||
if (onError) {
|
||||
onError()
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if (onError) {
|
||||
onError()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default class App extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<NativeRouter>
|
||||
<View style={{ width: "100%", height: "100%" }}>
|
||||
<Switch>
|
||||
<Route exact path="/login" component={Login} />
|
||||
<Route exact path="/logout" component={Logout} />
|
||||
<ProtectedRoute exact path="/home" component={Home} />
|
||||
<ProtectedRoute exact path="/arviewer" component={ARViewer} />
|
||||
<ProtectedRoute exact path="/activity" component={Activity} />
|
||||
<ProtectedRoute exact admin path="/workitem" component={WorkItem} />
|
||||
<ProtectedRoute
|
||||
exact
|
||||
admin
|
||||
path="/workitemlist"
|
||||
component={WorkItemList}
|
||||
/>
|
||||
<DefaultRoute />
|
||||
</Switch>
|
||||
</View>
|
||||
</NativeRouter>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user