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

Enable custom configuration for iOS maps #2396

Merged
merged 1 commit into from
Sep 7, 2018

Conversation

wbyoung
Copy link
Contributor

@wbyoung wbyoung commented Jul 25, 2018

This allows setting up the library to work with Google Maps on iOS via react-native link instead of only via CocoaPods.

Because Google-Maps-iOS-Utils is not distributed as a binary (at this time), it disables functionality that depends on this library and raises an exception that points to the reason why there's a problem.

Additionally:

  • A missing file has been added back into the AirMaps.xcodeproj project.
  • The use of Google-Maps-iOS-Utils is now based on conditional configuration as well.

Does any other open PR do the same thing?

Yes, in a sense. #2310 is related, and I believe it should be closed in favor of this request.

What issue is this PR fixing?

#2159, #2270, #2289, #2066 (for users who are upgrading from an older version & perhaps others).

How did you test this PR?

I tried using it with and without the included script being run to ensure that it compiles and links properly. I did not, however, test it with CocoaPods and will request that someone who has that configured ensure that everything still works as expected with Google Maps enabled (and without) when using CocoaPods.

@thanhdevapp
Copy link

Can you give me like step by step using gmap on ios

@rborn
Copy link
Collaborator

rborn commented Aug 13, 2018

@wbyoung what about an update form an older version of the module? Did you test this?

@alvelig I like this PR and I'll try to play with it but I need another pair of eyes 🐽

@rborn
Copy link
Collaborator

rborn commented Aug 13, 2018

@wbyoung also what if we don't want google maps, does this PR handles the react-native link correctly? and how?
🤗

@wbyoung
Copy link
Contributor Author

wbyoung commented Aug 15, 2018

@rborn I haven't used an older version of this module, but based on the comments in #2310, I would think that this a <insert word for whatever the opposite of breaking change is here> since it actually intends to improve the upgrade experience for prior users (in the same spirit as #2310). From what I can tell (and I haven't used the project except for the current version), the following is true:

  • Google maps used to be an optional dependency of this project requiring the addition of a specific set of source files or a specific .xcodeproj (and perhaps linker flags and/or build steps to go with it).
  • At some point, the library moved to Cocoapods specific instructions for setup and more or less removed both the ability to react-native link as well as (perhaps unintentionally) the need for or use of the Xcode projects that would be used by react-native link since all of the Cocoapods config files simply point to raw sources.
  • Made the Google Maps optional setup work via Cocoapods configs that point to which source files to compile (ignore Google Maps specific files or not) and not the .xcodeproj.
  • Broke the upgrade path for existing react-native link users who did not use Google Maps since some files and/or code was added to the now presumably unused (but actually included for prior users) .xcodeproj file.

So the long answer, is that I considered this when making the changes, but the short answer is: no, I did not test this (mainly because I didn't use this library before now).

The gist of what's happening here is that we're setting up for conditional compilation of all of the Google Maps files where the static library will still be compiled, but it won't actually contain anything pertaining to Google. This is the default case — do not include Google Maps functionality for iOS builds that have not opted in. Then if you configure it to do so, the package.json script (instructions included in the changes to the README) will append to the User.xcconfig inside of node_modules file so that the flag to compile those files will be set (HAVE_GOOGLE_MAPS=1). If you haven't included the required frameworks from Google, you'll get linker errors, but if you have, then everything will work as expected.

This strategy is somewhat similar to what react-native-camera does with the postinstall script, but they actually swap out one .xcodeproj for another. Maintaining two separate projects seems a bit erorr prone to me.

This works for everything except the code that's for Google-Maps-iOS-Utils since there's no pre-built binary for that. Of course one could pre-compile it or clone the source themselves and then overwrite or append to the User.xcconfig inside of node_modules to have HAVE_GOOGLE_MAPS_UTILS=1 as well as HAVE_GOOGLE_MAPS=1.

The conditional #ifdef compilation strategy (if new to you) is pretty standard in ./configure based open source packages that I've worked with before, and bringing it to Xcode projects is a little annoying since they have weird special setup with their .xcconfig files and definitely starts to get into "advanced" use cases for Xcode — the docs (at least in the past) were somewhat lacking here as it doesn't seem to be the norm for people to use this setup, but it's pretty easy & fits nicely with React Native since everything tends to be hidden behind command line flags. It is what it is, I guess.

Let me know if I can help explain any better.

@rborn
Copy link
Collaborator

rborn commented Aug 15, 2018

@christopherdro @alvelig I could use some help here, maybe we can push this forward as it seems a great improvement 🐽

@alvelig
Copy link
Contributor

alvelig commented Aug 16, 2018

So we can have react-native link as a standard method with no hustle?

"name": "your-app",
"scripts": {
"postinstall": "./node_modules/react-native-maps/enable-google-maps REPLACE_ME_RELATIVE_PATH_TO_GOOGLE_MAPS_INSTALL"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we may add this to lib if we define a standard method of installation @rborn

Copy link
Collaborator

Choose a reason for hiding this comment

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

@alvelig @wbyoung I think we need to educate the user how to install the google maps sdk (I have no idea for example right now at 1:45 AM and some 🍻)

Choose a reason for hiding this comment

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

@wbyoung can you help a bit with @rborn suggestion, I wasn't able to do it myself in my own project (only inside a clean repo) so I'm not sure am I doing it right

Choose a reason for hiding this comment

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

I don't understand how to get REPLACE_ME_RELATIVE_PATH_TO_GOOGLE_MAPS_INSTALL. Does someone have more info about this? Is it to our ios folder?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@annelorraineuy I have the google maps sdk downloaded to /Work/sdks/GoogleMaps-2.7.0/ so you need to put that path instead of the REPLACE_ME_RELATIVE_PATH_TO_GOOGLE_MAPS_INSTALL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@annelorraineuy if you got it working & have documentation improvements, please send a PR. I followed the style of various documentation sources that I've used over time to try to make it clear and succinct, but it's always good to try to improve for everyone!

@wbyoung
Copy link
Contributor Author

wbyoung commented Aug 16, 2018

@alvelig

So we can have react-native link as a standard method with no hustle?

Yup!

we may add this to lib if we define a standard method of installation

Not sure what you mean here, but if you mean adding it to the install scripts for the library, that would kind of defeat the purpose as the goal is to make Google Maps usage opt in (and for non Cocoapods users, to make it clear that there’s extra work that must be done following an exact procedure to get things working for Google Maps) while keeping it as pain free as possible and allowing a friction free upgrade path.

@rborn
Copy link
Collaborator

rborn commented Aug 17, 2018

@wbyoung I think I need some more instructions from you on how to actually install it :(
I tried to add your PR with yarn, used the pod files we already have in instruction, run pod install, run your post script manually with some path I downloaded the sdk manually https://developers.google.com/maps/documentation/ios-sdk/start but for some reason the app still shows the apple map. 🤗

Brand new project.

@wbyoung
Copy link
Contributor Author

wbyoung commented Aug 17, 2018

@rborn if not installed correctly, you should get compiler errors as the script will enable code that uses those headers and requires the symbols from those frameworks in order to link the binary. So you likely got it right.

Installing the framework should literally be downloading it and placing it in a folder, but giving instructions may be difficult since Goolgle’s instructions are more comprehensive, so linking out means also saying “ignore all the stuff here”. So maybe the best course of action is to explain that you just need the files, X, Y, and Z from Google which you can download “here” while ignoring all other install instructions.

That being said, I had the same issue at some point because I didn’t quite understand that enabling google maps didn’t change the default map and that you needed to use a specific provider. Perhaps making this type of change should be done as a separate PR as it’s a bit outside the scope? This may or may not be your issue, but it certainly slowed me down getting things set up.

@alvelig
Copy link
Contributor

alvelig commented Aug 17, 2018

@wbyoung I agree. This should be kind of Facebook SDK installation. Like place GoogleSDK folder in ~/Documents and add header search path...

@rborn
Copy link
Collaborator

rborn commented Aug 17, 2018

I set the provider="google" and got a black screen.

@wbyoung
Copy link
Contributor Author

wbyoung commented Aug 19, 2018

@rborn can you push what you currently have to GitHub and post a link here? I can take a look and see what differs from what I have working. It could also double as an example of how to get up and running this way & we can include a link in the docs (if you guys want to continue to maintain that example).

@rborn
Copy link
Collaborator

rborn commented Aug 20, 2018

@wbyoung I'll try on a clean project, maybe I messed up something.

@rborn
Copy link
Collaborator

rborn commented Aug 22, 2018

@wbyoung I was wrong, all works fine, it was me 😆

@alvelig @christopherdro I think we should merge this one, create a new release with possible breaking warning for people updating from an older version who added libs manually.
What do you say?

@alvelig
Copy link
Contributor

alvelig commented Aug 23, 2018

@rborn I concur.

@chrise86
Copy link

chrise86 commented Aug 23, 2018

@wbyoung I tried this and it all compiles and runs fine, but when trying to use a marker it produces the following error:

Invariant Violation: Invariant Violation: requireNativeComponent:"AIRMapMarker" was not found in the UIManager.

We don't need Google maps to use markers, right?

@rborn
Copy link
Collaborator

rborn commented Aug 23, 2018

@wbyoung I didn't use any marker yet, I'll let you know soon.
@chrise86 - no, we don't need googlemaps for that

@chrise86
Copy link

@wbyoung I just created a pull request against your branch to fix the issue above. There were #ifdef HAVE_GOOGLE_MAPS checks missing in AIRGoogleMapOverlay.h and AIRGoogleMapOverlay.m.

@wbyoung
Copy link
Contributor Author

wbyoung commented Aug 24, 2018

@chrise86 I added your changes to this PR just now.

@rborn
Copy link
Collaborator

rborn commented Aug 24, 2018

@wbyoung can you have a look at #2455 and let us know what you think? maybe we can make a mix of both?

cc @alvelig

@wbyoung
Copy link
Contributor Author

wbyoung commented Aug 24, 2018

@rborn commented over there.

/cc @alvelig

@cayasso
Copy link

cayasso commented Aug 28, 2018

Hi guys! any update on merging this wonderful PR ?

This allows setting up the library to work with Google Maps on iOS via
`react-native link` instead of only via CocoaPods.

Because Google-Maps-iOS-Utils is not distributed as a binary (at this
time), it disables functionality that depends on this library and raises
an exception that points to the reason why there's a problem.

Additionally:

- A missing file has been added back into the AirMaps.xcodeproj project.
@mikemorris
Copy link
Contributor

mikemorris commented Sep 1, 2018

This appears to be working for me, thanks for your work on this @wbyoung! Closing #2310 in favor of this instead.

@jamesone
Copy link

jamesone commented Sep 5, 2018

Any idea when this PR will be merged?

@rborn
Copy link
Collaborator

rborn commented Sep 7, 2018

@christopherdro @alvelig I intend to merge this, would be good if you could have a look 🤗

@alvelig
Copy link
Contributor

alvelig commented Sep 7, 2018

LGTM. Actually a killer feature we'd need. So let's merge.

@abarisic86
Copy link

abarisic86 commented Sep 12, 2018

For Google Maps on iOS option:

@rborn
Copy link
Collaborator

rborn commented Sep 13, 2018

@abarisic86 fancy a PR? 😊

@abarisic86
Copy link

abarisic86 commented Sep 13, 2018

@rborn yes, I would like to contribute but I wasn't able to get it working (react native link with google maps). As if some part of the installation process is skipped in the documentation.

EDIT: Two things I changed that maybe made it work:

  • "@import GoogleMaps;" instead of loading just header file
  • after installing GM framework by using this tutorial post-install script reference to "ios/" not "/ios/" or "/ios/GoogleMaps"

image

@wbyoung
Copy link
Contributor Author

wbyoung commented Nov 26, 2018

@abarisic86 I tried to make the docs clear, but there is certainly some language that can be confusing (especially for those who haven't developed for iOS). I went back and reviewed the docs, but I can't really find anywhere to make things more clear. An example project could make it more clear, but I don't have the time to create or maintain one that keeps up to date with this project.

Specifically, the issues you had:

  • The @import GoogleMaps should not make any difference. It should work as it's documented.
  • The docs state that you should use a relative path to the installed location, so the use of ios/ is exactly as the docs are suggesting. Is there a way that you'd word that to make it more clear?

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.

10 participants