Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a map for virtual beacons #340

Closed
wants to merge 3 commits into from
Closed

Conversation

gmarty
Copy link
Contributor

@gmarty gmarty commented Nov 17, 2016

No description provided.

@gmarty gmarty force-pushed the map branch 2 times, most recently from de41e5d to af888a9 Compare November 17, 2016 16:22
@@ -148,6 +148,7 @@ android {
dependencies {
compile project(':react-native-linear-gradient')
compile project(':magnet-scanner-android')
compile project(':reactnativemapboxgl')
Copy link
Collaborator

@wilsonpage wilsonpage Nov 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why we don't use default react-native MapView?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default map component is iOS only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I tried the react-native-maps by Airbnb that the React Native team recommends, but it ended up being a massive mess to set up and configure and it isn't even compatible with our Google Play Service version. So falling back to mapbox was the best solution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, do you have any more info on the google-play-services issue?

@@ -30,6 +32,7 @@
android:name=".notifications.NotificationService"
android:enabled="true"
android:exported="false"/>
<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's for mapbox telemetry. This is part of the settings process. I'm not sure if deactivating it can have side effects.
From a purely user standpoint the telemetry can be deactivated through the map interface.
Do you want me to enquire it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do, I'm afraid of what legal reasons we will need to add in our side in order to use this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update?

return {
type: 'LOCATION_CHANGED',
pos,
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look spot on, nice one!

};

module.exports = (state, action) => {
if (!state) return initialState;
module.exports = (state = initialState, action) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -39,6 +42,9 @@ module.exports = (state, action) => {
case 'SUBSCRIBED': return subscribed(state, action);
case 'UNSUBSCRIBED': return unsubscribed(state, action);
case 'SUBSCRIPTION_UPDATED': return subscriptionUpdated(state, action);
case 'LOCATION_UPDATE_STARTED': return startLocationUpdates(state);
case 'LOCATION_UPDATE_STOPPED': return stopLocationUpdates(state);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: UPDATES

@@ -18,21 +21,34 @@ const {
Linking,
} = ReactNative;

const accessToken = 'pk.eyJ1IjoiZ21hcnR5IiwiYSI6ImNpdm1lanB1azAwNm8yb3A0OXZ6bmUxM2oifQ.i2HycDMBdPoatAB-ONR6FQ';
Mapbox.setAccessToken(accessToken);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the rate limits for mapbox? We may need to flip to google-maps if we start entering paid usage tiers.


// Distance in km
return R * c;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you shove this in utils/compute-distance.js?

},

distanceImage: {
width: 20,
height: 20,
marginRight: 5,
},

distanceLabel: {
fontFamily: 'FiraSans-Book',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use config.theme constants.

@wilsonpage
Copy link
Collaborator

Looks good @gmarty!

I haven't been able to test on device yet. Just some questions about the choice of map vendor and some code nits.

@arcturus
Copy link
Member

Why is this close? Fat fingers? ;)

@wilsonpage
Copy link
Collaborator

Shit I always hit the wrong button!

@@ -18,21 +21,34 @@ const {
Linking,
} = ReactNative;

const accessToken = 'pk.eyJ1IjoiZ21hcnR5IiwiYSI6ImNpdm1lanB1azAwNm8yb3A0OXZ6bmUxM2oifQ.i2HycDMBdPoatAB-ONR6FQ';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this in the config.js file. Maybe ask @samgiles or @arcturus about how we can protect keys. Prob not important right now though as this particular key doesn't hold much value.

Copy link
Contributor

@samgiles samgiles Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, this key is fine - it wouldn't be so much if we paid for it - but still not the end of the world. Because we ship this key to the client, we can never really secure it, it's just not best practice to keep keys in the tree.

Will need to think about this, maybe we can use ci.tengam.org to store secrets required during builds, or use Travis's secrets mechanism.

Not sure what the best thing would be, let's figure that out at a later date.

@@ -92,8 +108,29 @@ class ItemScene extends React.Component {
Linking.openURL(url);
}

renderDistance(distance = 0) {
renderDistance() {
let distance = this.state.distance;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we touching this.state? Is it meant to mean this.props?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a mistake.

@wilsonpage
Copy link
Collaborator

I'm getting this upon loading the ItemScene:

screen shot 2016-11-18 at 14 01 01


Not sure why we're touching this.state, perhaps it's a typo.

typeof this.props.item.longitude === 'number') {
distance = this.computeDistance(this.props.location.pos.coords);
}

distance = Math.round(distance);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all this distance logic should be packaged up into a dedicated .getDistance() (pure) function. Takes required inputs and spits out a distance result.

return (dispatch) => {
dispatch(locationUpdateStarted());
watchID = navigator.geolocation.watchPosition((pos) => {
dispatch(locationChanged(pos));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be explicit and only pass lat/lon as that's all we're using right now. If we need other properties at a later date, we can expose them.

if (typeof distance !== 'number' &&
typeof this.props.item.latitude === 'number' &&
typeof this.props.item.longitude === 'number') {
distance = this.computeDistance(this.props.location.pos.coords);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2016-11-18 at 14 14 59

I don't think my device has got a location callback yet, so this is throwing.

location: {
pos: null,
isWatching: false,
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pattern I'm introducing with my pending redux patch is async values having status and value properties. The value property varies depending on the status.

{
  location: {
    status: 'STARTED' | 'STOPPED' | 'ERROR'?
    value: null | { latitude: ..., longitude: ... }
  }
}

Although I guess this is slightly different as the status doesn't directly map to a corresponding value. For example 'STARTED' doesn't mean that we have a value yet.

@wilsonpage
Copy link
Collaborator

@gmarty I'm having some difficulty running this patch, not sure what the differences are in our envs, but I'm not able to render the item-scene. I think in some cases we need to protect against the device not having a location value yet in render() function.

@@ -30,6 +30,7 @@ module.exports = {
'privacy': 'https://trymagnet.org/privacy/',
'feedback': 'https://trymagnet.org/#contact',
},
mapboxAccessToken: 'pk.eyJ1IjoiZ21hcnR5IiwiYSI6ImNpdm1lanB1azAwNm8yb3A0OXZ6bmUxM2oifQ.i2HycDMBdPoatAB-ONR6FQ',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to remove this key and add it during build time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmarty sorry this isn't clear: settings is a namespace reserved for the SettingsScene. Please move your key up to the next parent.

@@ -181,12 +185,60 @@ class ItemDetail extends Component {
<View style={styles.distance}>
<Image
style={styles.distanceImage}
source={require('../../images/item-scene-room.png')}/>
source={{
uri: 'ic_place_black_24dp',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to indicate the dp?

Or can we just use 'ic_place_black' for devices with different dp, also does this work in ios?

@arcturus
Copy link
Member

Looking gorgeous in ios, but unfortunately we still need to cover in this PR the ios integration.

@gmarty gmarty force-pushed the map branch 2 times, most recently from 7c80bd8 to 80358ce Compare November 22, 2016 15:03
@wilsonpage
Copy link
Collaborator

Looking gorgeous in ios, but unfortunately we still need to cover in this PR the ios integration.

@arcturus do you mean android?

@arcturus
Copy link
Member

@arcturus do you mean android?

Right :)

@@ -180,12 +184,60 @@ class ItemDetail extends Component {
<View style={styles.distance}>
<Image
style={styles.distanceImage}
source={require('../../images/item-scene-room.png')}/>
source={{
uri: 'ic_place',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this image is not loaded using the regular require() mechanism?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not implemented in Mapbox yet. Plus I found working with image assets is really smooth both on iOS and Android. Using Material Design icons, I just had to slide the folders in relevant places.
And of course this support multi screen densities which is good.

id: 'marker1',
annotationImage: {
source: {
uri: 'ic_place',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again can we use require() to keep all our front-end image assets in one place?

@@ -1,342 +0,0 @@
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this file, does this PR need a rebase?

@wilsonpage
Copy link
Collaborator

@gmarty I really don't want to put the emulator out of action on Android. This is because the emulator makes it possible to test the app across several android versions and mock locations when devs (me) aren't in London.

If the problem is related to the mapbox-native-gl version being out of date we have two options:

  • A. Override the transient com.mapbox.mapboxsdk:mapbox-android-sdk gradle dependency in our magnet-client's build.gradle so that we pull in the latest version.

  • B. Fork react-native-mapbox-gl and update the dependency. We can reference this fork in out package.json and submit a pull-request to the original. When the original fixes we can flip back.

@@ -28,7 +30,9 @@ protected boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new GoogleAnalyticsBridgePackage(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funky rebase issues?

@@ -29,7 +29,8 @@
"about": "https://trymagnet.org",
"privacy": "https://trymagnet.org/privacy/",
"feedback": "https://trymagnet.org/#contact"
}
},
"mapboxAccessToken": "pk.eyJ1IjoiZ21hcnR5IiwiYSI6ImNpdm1lanB1azAwNm8yb3A0OXZ6bmUxM2oifQ.i2HycDMBdPoatAB-ONR6FQ"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this out of settings.

},
{
"idiom" : "universal",
"filename" : "ic_place_2x.png",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the convention [email protected]?

@wilsonpage
Copy link
Collaborator

I don't really like how our front-end image assets are now spread across three directories instead of one. I understand this is a limitation of mapbox API if you want to have custom marker images.

@wilsonpage
Copy link
Collaborator

wilsonpage commented Nov 23, 2016

Regarding android image assets:

All our android image assets currently have 12 different resolutions automatically generated by Android Studio.

res/drawable-hdpi
res/drawable-hdpi-v9
res/drawable-hdpi-v11
res/drawable-mdpi
res/drawable-mdpi-v9
res/drawable-mdpi-v11
res/drawable-xhdpi
res/drawable-xhdpi-v9
res/drawable-xhdpi-v11
res/drawable-xxhdpi
res/drawable-xxhdpi-v9
res/drawable-xxhdpi-v11

Your latest icon only has three different variations. For consistency I think all our icons should be available in the same variations.

@wilsonpage
Copy link
Collaborator

Happy for this to land once all comments addressed, most importantly the Android emulator issue. Nice work on this, it looks mega good!

@wilsonpage
Copy link
Collaborator

@gmarty please use this fix and keep all our front-end image assets in the lib/images/ directory. Merci! :)

@wilsonpage
Copy link
Collaborator

Closing this to continue work at #385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants