Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Make MGLMapView IB_DESIGNABLE (for iOS XIBs) #929

Closed
1ec5 opened this issue Feb 28, 2015 · 9 comments · Fixed by #1184
Closed

Make MGLMapView IB_DESIGNABLE (for iOS XIBs) #929

1ec5 opened this issue Feb 28, 2015 · 9 comments · Fixed by #1184
Assignees
Labels
iOS Mapbox Maps SDK for iOS
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented Feb 28, 2015

Developers who use XIBs or storyboards will find it more awkward to use MGLMapView than MKMapView because custom views such as MGLMapView are rendered as plain white squares by default:

ib
Left: MGLMapView. Right: MKMapView.

MGLMapView should be marked IB_DESIGNABLE and draw something recognizable inside Interface Builder. It would be impractical to load actual map content synchronously within the short timeout, but even something mimicking the MKMapView’s translucent “blue box” would be easier to work with.

@1ec5 1ec5 added the iOS Mapbox Maps SDK for iOS label Feb 28, 2015
@incanus
Copy link
Contributor

incanus commented Feb 28, 2015

👍

I started playing around in this direction a few weeks back but only got as far as https://gist.github.com/incanus/867e487146bb9695065a. I got blocked there by GL project restructuring and the loss of a dynamic framework that would work in Swift (#828).

https://twitter.com/incanus77/statuses/563748947043164160

@ljbade
Copy link
Contributor

ljbade commented Mar 2, 2015

Interesting Android has something similar for the UI editor: #650

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 2, 2015

Also, we should have the box draw a little reminder when the inspectable access token isn’t filled in.

@ljbade
Copy link
Contributor

ljbade commented Mar 3, 2015

@1ec5 great idea!

@DavidChouinard
Copy link

As a user: this would be very useful!

@DavidChouinard
Copy link

@1ec5 What's the expected inspectable key path? (accessToken does not seem to work)

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 23, 2015

accessToken doesn’t appear to be KVO-compliant at the moment. Additionally, if accessToken is unset, setting it should make the map use the default bundled style, just as -initWithFrame:styleJSON:accessToken: calls -setStyleJSON: with nil when there’s a token is specified.

@1ec5 1ec5 added this to the iOS Beta 2 milestone Apr 1, 2015
@1ec5
Copy link
Contributor Author

1ec5 commented Apr 1, 2015

untokenized
tokenized
default

@friedbunny
Copy link
Contributor

Very nice. 🤘

@incanus incanus modified the milestones: iOS Beta 1, iOS Beta 2 Apr 2, 2015
1ec5 added a commit that referenced this issue Apr 3, 2015
When an access token is set in the Attributes inspector (or as a user-defined runtime attribute), we draw some lovely Mapbox branding so the view shows up. (Manipulating invisible rectangles is a frustrating exercise, I’m told.) In the absence of an access token, the view displays a helpful message with directions for obtaining and setting the access token.

Along the way, completely opt out of `MGLMapboxEvents` when targeting Interface Builder, because touching Core Location throws an exception in that environment and it doesn’t make sense to record any metrics when designing on the Interface Builder canvas. Also, don’t start `mbgl::Map` at all (and don’t update it) because none of the runtime drawing code should ever be run in the designable. Normally these chunks of code would be excluded in IB using the TARGET_INTERFACE_BUILDER preprocessor macro. However, Mapbox GL is being packaged as a static library, so the macro is only evaluated when the library is prebuilt, even if the library eventually makes its way into the CocoaPods-generated framework. Instead, we detect that we’re being run by the IBDesignablesAgentCocoaTouch process.

Overrode `-[MGLMapView initWithFrame:]` to call `-commonInit`. We’ve marked this initializer unavailable in the header, but IB still calls it regardless.

Fixes #929.
1ec5 added a commit that referenced this issue Apr 3, 2015
Declared these IB-specific inspectables in a separate category that developers are not expected to import. Currently these inspectables are order-dependent due to #1181.

Ref #929
@1ec5 1ec5 closed this as completed in #1184 Apr 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants