mirror of
https://github.com/RamonGebben/getmehigh-native.git
synced 2026-03-10 08:41:24 +00:00
Changed flow
This commit is contained in:
@@ -98,8 +98,8 @@
|
|||||||
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
|
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
|
||||||
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
|
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
|
||||||
<orderEntry type="library" exported="" name="okhttp-2.5.0" level="project" />
|
<orderEntry type="library" exported="" name="okhttp-2.5.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="okhttp-ws-2.5.0" level="project" />
|
|
||||||
<orderEntry type="library" exported="" name="okio-1.6.0" level="project" />
|
<orderEntry type="library" exported="" name="okio-1.6.0" level="project" />
|
||||||
|
<orderEntry type="library" exported="" name="okhttp-ws-2.5.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="fbcore-0.8.1" level="project" />
|
<orderEntry type="library" exported="" name="fbcore-0.8.1" level="project" />
|
||||||
<orderEntry type="library" exported="" name="drawee-0.8.1" level="project" />
|
<orderEntry type="library" exported="" name="drawee-0.8.1" level="project" />
|
||||||
<orderEntry type="library" exported="" name="android-jsc-r174650" level="project" />
|
<orderEntry type="library" exported="" name="android-jsc-r174650" level="project" />
|
||||||
@@ -108,6 +108,7 @@
|
|||||||
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
|
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
|
||||||
<orderEntry type="library" exported="" name="commons-cli-1.2" level="project" />
|
<orderEntry type="library" exported="" name="commons-cli-1.2" level="project" />
|
||||||
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
|
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.1" level="project" />
|
||||||
|
<orderEntry type="module" module-name="RNMaterialKit" exported="" />
|
||||||
<orderEntry type="module" module-name="react-native-gmaps" exported="" />
|
<orderEntry type="module" module-name="react-native-gmaps" exported="" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
130
index.android.js
130
index.android.js
@@ -22,21 +22,30 @@ var {
|
|||||||
Text,
|
Text,
|
||||||
View,
|
View,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
TouchableHighlight
|
TouchableHighlight,
|
||||||
|
BackAndroid
|
||||||
} = React;
|
} = React;
|
||||||
|
|
||||||
MK.setTheme({
|
MK.setTheme({
|
||||||
primaryColor: MKColor.Teal,
|
primaryColor: MKColor.Pink,
|
||||||
accentColor: MKColor.Purple,
|
accentColor: MKColor.Purple,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const SliderWithValue = mdl.Slider.slider()
|
||||||
|
.withMin(5)
|
||||||
|
.withMax(500)
|
||||||
|
.build();
|
||||||
|
|
||||||
var getMeHighMobile = React.createClass({
|
var getMeHighMobile = React.createClass({
|
||||||
|
|
||||||
getInitialState: function(){
|
getInitialState: function(){
|
||||||
return {
|
return {
|
||||||
shops: [],
|
shops: [],
|
||||||
lastPosition: 'unknown',
|
lastPosition: null,
|
||||||
theOne: 'unknown'
|
theOne: 'unknown',
|
||||||
|
searchRadius: 5,
|
||||||
|
withinRadius: [],
|
||||||
|
history: ['start']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
componentDidMount: function(){
|
componentDidMount: function(){
|
||||||
@@ -47,6 +56,9 @@ var getMeHighMobile = React.createClass({
|
|||||||
this.setState({shops: body.shops})
|
this.setState({shops: body.shops})
|
||||||
});
|
});
|
||||||
this._getGeoLocation();
|
this._getGeoLocation();
|
||||||
|
BackAndroid.addEventListener('hardwareBackPress', () => {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
@@ -61,11 +73,20 @@ var getMeHighMobile = React.createClass({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
_getMeHigh: function(){
|
_getMeHigh: function(){
|
||||||
this.findShop((theOne => {
|
if( this.state.lastPosition && this.state.shops.length > 0 ){
|
||||||
this.setState({
|
this.findShops((withinRadius => {
|
||||||
theOne: theOne
|
let newHistory = this.state.history;
|
||||||
});
|
newHistory.pop(); // Remove the loading screen;
|
||||||
}));
|
newHistory.push('map');
|
||||||
|
this.setState({ withinRadius, history: newHistory });
|
||||||
|
}));
|
||||||
|
}else {
|
||||||
|
this.state.history.push('loading');
|
||||||
|
setTimeout(() => {
|
||||||
|
this._getMeHigh();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
getDistance: function(p1, p2) {
|
getDistance: function(p1, p2) {
|
||||||
// http://www.wikiwand.com/en/Haversine_formula
|
// http://www.wikiwand.com/en/Haversine_formula
|
||||||
@@ -89,56 +110,78 @@ var getMeHighMobile = React.createClass({
|
|||||||
});
|
});
|
||||||
if(holaback) holaback(theOne);
|
if(holaback) holaback(theOne);
|
||||||
},
|
},
|
||||||
|
findShops: function(holaback){
|
||||||
|
let withinRadius = this.state.shops.filter(( shop ) => {
|
||||||
|
shop.distance = this.getDistance( this.state.lastPosition, shop.location );
|
||||||
|
let distanceInKilometer = Math.ceil(shop.distance) / 1000;
|
||||||
|
if( distanceInKilometer < this.state.searchRadius ){
|
||||||
|
return shop;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(holaback) holaback(withinRadius);
|
||||||
|
},
|
||||||
onMapChange: function(e){
|
onMapChange: function(e){
|
||||||
console.log(e);
|
console.log(e);
|
||||||
},
|
},
|
||||||
onMapError: function(e){
|
onMapError: function(e){
|
||||||
console.log('map error -->', e);
|
console.log('map error -->', e);
|
||||||
},
|
},
|
||||||
|
onRadiusChange: function(value){
|
||||||
|
this.setState({searchRadius: Math.ceil(value)});
|
||||||
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
let route = this.state.history[this.state.history.length -1];
|
||||||
|
switch (route) {
|
||||||
|
case 'loading':
|
||||||
|
return this._renderLoading();
|
||||||
|
case 'start':
|
||||||
|
return this._renderStart();
|
||||||
|
case 'map':
|
||||||
|
return this._renderMap();
|
||||||
|
|
||||||
if( this.state.theOne !== 'unknown') {
|
}
|
||||||
return this._renderMap();
|
|
||||||
}else {
|
|
||||||
return this._renderStart();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
_renderStart: function(){
|
_renderStart: function(){
|
||||||
var ColoredFlatButton = MKButton.coloredButton()
|
var GetMeHighButton = MKButton.coloredButton()
|
||||||
.withText('Get Me High')
|
.withText('Get Me High')
|
||||||
.withTextStyle(styles.buttonText)
|
.withTextStyle(styles.buttonText)
|
||||||
.withOnPress(this._getMeHigh)
|
.withOnPress(this._getMeHigh)
|
||||||
.build();
|
.build();
|
||||||
if( this.state.lastPosition !== 'unknown' && this.state.shops.length > 1 ){
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<ColoredFlatButton />
|
<Text>{ `Within ${this.state.searchRadius}km range` }</Text>
|
||||||
|
<SliderWithValue ref='sliderWithValue'
|
||||||
|
style={styles.slider}
|
||||||
|
onChange={this.onRadiusChange} />
|
||||||
|
<GetMeHighButton />
|
||||||
</View>);
|
</View>);
|
||||||
}else {
|
},
|
||||||
return(<View style={styles.container}>
|
_renderLoading: function(){
|
||||||
<mdl.Spinner style={styles.spinner}/>
|
return(<View style={styles.container}>
|
||||||
<Text style={styles.text}>Getting your location</Text>
|
<mdl.Spinner style={styles.spinner}/>
|
||||||
</View>);
|
<Text style={styles.text}>Getting your location</Text>
|
||||||
}
|
</View>);
|
||||||
},
|
},
|
||||||
_renderMap: function(){
|
_renderMap: function(){
|
||||||
return (<RNGMap
|
return (<RNGMap
|
||||||
ref={'gmap'}
|
ref={'gmap'}
|
||||||
style={ styles.map }
|
style={ styles.map }
|
||||||
markers={ [
|
markers={ this.state.withinRadius.map(shop => {
|
||||||
{
|
let snippet = `${shop.adress} ${shop.city}`;
|
||||||
coordinates: this.state.theOne.location,
|
return {
|
||||||
title: this.state.theOne.name,
|
coordinates: shop.location,
|
||||||
snippet: "Subtitle",
|
title: shop.name,
|
||||||
id: 0,
|
id: shop.id,
|
||||||
color: 120,
|
snippet: snippet,
|
||||||
}
|
color: 120
|
||||||
] }
|
}
|
||||||
zoomLevel={ 13 }
|
})}
|
||||||
onMapChange={(e) => console.log(e)}
|
zoomLevel={ 12 }
|
||||||
onMapError={(e) => console.log('Map error --> ', e)}
|
onMapChange={this.onMapChange}
|
||||||
center={ this.state.lastPosition }
|
onMapError={this.onMapError}
|
||||||
clickMarker={0} />);
|
center={ this.state.lastPosition }/>);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -159,22 +202,15 @@ var styles = StyleSheet.create({
|
|||||||
map: {
|
map: {
|
||||||
flex: 1
|
flex: 1
|
||||||
},
|
},
|
||||||
button: {
|
|
||||||
padding: 60,
|
|
||||||
margin: 20,
|
|
||||||
width: 300,
|
|
||||||
height: 300,
|
|
||||||
backgroundColor: '#7A1496',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
borderRadius: 300
|
|
||||||
},
|
|
||||||
buttonText: {
|
buttonText: {
|
||||||
fontSize: 30
|
fontSize: 30
|
||||||
},
|
},
|
||||||
scrollView: {
|
scrollView: {
|
||||||
height: 300,
|
height: 300,
|
||||||
},
|
},
|
||||||
|
slider: {
|
||||||
|
width: 300,
|
||||||
|
},
|
||||||
legendLabel: {
|
legendLabel: {
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
color: '#666666',
|
color: '#666666',
|
||||||
|
|||||||
Reference in New Issue
Block a user