Center new work item on user
This commit is contained in:
@@ -30,6 +30,7 @@ import { api } from "../API"
|
|||||||
import { formatLatLng } from "../util"
|
import { formatLatLng } from "../util"
|
||||||
import moment from "moment"
|
import moment from "moment"
|
||||||
import "url-search-params-polyfill"
|
import "url-search-params-polyfill"
|
||||||
|
import { config } from "../config"
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
@@ -91,6 +92,7 @@ export class Activity extends React.Component {
|
|||||||
messageModal: null,
|
messageModal: null,
|
||||||
progressModal: null,
|
progressModal: null,
|
||||||
uploadPercent: 0,
|
uploadPercent: 0,
|
||||||
|
region: config.initialRegion,
|
||||||
}
|
}
|
||||||
|
|
||||||
const { search } = this.props.location
|
const { search } = this.props.location
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
Header,
|
Header,
|
||||||
BoundOptionStrip,
|
BoundOptionStrip,
|
||||||
BoundPhotoPanel,
|
BoundPhotoPanel,
|
||||||
|
Geolocation,
|
||||||
} from "../ui"
|
} from "../ui"
|
||||||
import { MessageModal, ProgressModal, WaitModal } from "../Modal"
|
import { MessageModal, ProgressModal, WaitModal } from "../Modal"
|
||||||
import autobind from "autobind-decorator"
|
import autobind from "autobind-decorator"
|
||||||
@@ -98,6 +99,7 @@ export class WorkItem extends React.Component {
|
|||||||
messageModal: null,
|
messageModal: null,
|
||||||
waitModal: null,
|
waitModal: null,
|
||||||
progressModal: null,
|
progressModal: null,
|
||||||
|
region: config.initialRegion,
|
||||||
}
|
}
|
||||||
|
|
||||||
const { search } = this.props.location
|
const { search } = this.props.location
|
||||||
@@ -287,6 +289,20 @@ export class WorkItem extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
handlePositionUpdate(position) {
|
||||||
|
const { coords } = position
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
region: {
|
||||||
|
latitude: coords.latitude,
|
||||||
|
longitude: coords.longitude,
|
||||||
|
latitudeDelta: 0.02,
|
||||||
|
longitudeDelta: 0.02,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
binder,
|
binder,
|
||||||
@@ -294,6 +310,7 @@ export class WorkItem extends React.Component {
|
|||||||
waitModal,
|
waitModal,
|
||||||
progressModal,
|
progressModal,
|
||||||
uploadPercent,
|
uploadPercent,
|
||||||
|
region,
|
||||||
} = this.state
|
} = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -344,7 +361,7 @@ export class WorkItem extends React.Component {
|
|||||||
showsBuildings={false}
|
showsBuildings={false}
|
||||||
showsTraffic={false}
|
showsTraffic={false}
|
||||||
showsIndoors={false}
|
showsIndoors={false}
|
||||||
initialRegion={config.initialRegion}
|
region={region}
|
||||||
onRegionChange={this.handleRegionChange}
|
onRegionChange={this.handleRegionChange}
|
||||||
onMapReady={this.handleOnMapReady}
|
onMapReady={this.handleOnMapReady}
|
||||||
/>
|
/>
|
||||||
@@ -393,6 +410,7 @@ export class WorkItem extends React.Component {
|
|||||||
)}
|
)}
|
||||||
{isIphoneX ? <View style={{ height: 30, width: "100%" }} /> : null}
|
{isIphoneX ? <View style={{ height: 30, width: "100%" }} /> : null}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
<Geolocation onUpdate={this.handlePositionUpdate} watch={false} />
|
||||||
<ProgressModal
|
<ProgressModal
|
||||||
open={!!progressModal}
|
open={!!progressModal}
|
||||||
message={progressModal ? progressModal.message : ""}
|
message={progressModal ? progressModal.message : ""}
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ import autobind from "autobind-decorator"
|
|||||||
export class Geolocation extends Component {
|
export class Geolocation extends Component {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
onUpdate: PropTypes.func.isRequired,
|
onUpdate: PropTypes.func.isRequired,
|
||||||
|
watch: PropTypes.bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
watch: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -16,9 +21,12 @@ export class Geolocation extends Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
navigator.geolocation.getCurrentPosition((position) => {
|
navigator.geolocation.getCurrentPosition((position) => {
|
||||||
this.props.onUpdate(position)
|
this.props.onUpdate(position)
|
||||||
|
|
||||||
|
if (this.props.watch) {
|
||||||
this.watchId = navigator.geolocation.watchPosition((position) =>
|
this.watchId = navigator.geolocation.watchPosition((position) =>
|
||||||
this.props.onUpdate(position)
|
this.props.onUpdate(position)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user