-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Make MGLMapView IB_DESIGNABLE (for iOS XIBs) #929
Comments
👍 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). |
Interesting Android has something similar for the UI editor: #650 |
Also, we should have the box draw a little reminder when the inspectable access token isn’t filled in. |
@1ec5 great idea! |
As a user: this would be very useful! |
@1ec5 What's the expected inspectable key path? ( |
|
Very nice. 🤘 |
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.
Developers who use XIBs or storyboards will find it more awkward to use
MGLMapView
thanMKMapView
because custom views such asMGLMapView
are rendered as plain white squares by default:Left:
MGLMapView
. Right:MKMapView
.MGLMapView
should be markedIB_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 theMKMapView
’s translucent “blue box” would be easier to work with.The text was updated successfully, but these errors were encountered: