Add in Geolocation component

This commit is contained in:
John Lyon-Smith
2018-05-16 12:11:54 -07:00
parent 07f74fbf7d
commit 23d4a95bd6
5 changed files with 84 additions and 35 deletions

View File

@@ -0,0 +1,36 @@
import React, { Component } from "react"
import { Image, View } from "react-native"
import PropTypes from "prop-types"
import autobind from "autobind-decorator"
export class Geolocation extends Component {
static propTypes = {
onUpdate: PropTypes.func.isRequired,
}
constructor(props) {
super(props)
this.watchId = -1
}
componentDidMount() {
navigator.geolocation.getCurrentPosition((position) => {
this.props.onUpdate(position)
this.watchId = navigator.geolocation.watchPosition((position) =>
this.props.onUpdate(position)
)
})
}
componentWillUnmount() {
if (this.watchId !== -1) {
navigator.geolocation.clearWatch(this.watchId)
navigator.geolocation.stopObserving()
this.watchId = -1
}
}
render() {
return null
}
}

View File

@@ -3,6 +3,7 @@ export { Header } from "./Header"
export { OptionStrip } from "./OptionStrip"
export { BubbleLoader } from "./BubbleLoader"
export { ProgressBar } from "./ProgressBar"
export { Geolocation } from "./Geolocation"
export { BoundSwitch } from "./BoundSwitch"
export { BoundInput } from "./BoundInput"
export { FormStaticInput } from "./FormStaticInput"