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

Layer ownership refactor - #6904

Merged
fabian-guerra merged 5 commits into
release-ios-v3.4.0from
fabian-guerra-layer-ownership-refactor
Nov 4, 2016
Merged

fabian-guerra merged 5 commits into
release-ios-v3.4.0from
fabian-guerra-layer-ownership-refactor

Conversation

@fabian-guerra

Copy link
Copy Markdown
Contributor

Fixes #6254

cc @boundsj @1ec5

@fabian-guerra fabian-guerra added iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold release blocker Blocks the next final release runtime styling labels Nov 3, 2016
@fabian-guerra fabian-guerra added this to the ios-v3.4.0 milestone Nov 3, 2016
@mention-bot

Copy link
Copy Markdown

@fabian-guerra, thanks for your PR! By analyzing the history of the files in this pull request, we identified @boundsj, @1ec5 and @incanus to be potential reviewers.

Comment thread platform/ios/app/Main.storyboard Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't meant to merge this storyboard.

@fabian-guerra
fabian-guerra force-pushed the fabian-guerra-layer-ownership-refactor branch from 3970310 to 4903b19 Compare November 3, 2016 23:47
Comment thread platform/darwin/src/MGLFillStyleLayer.h Outdated
@property (nonatomic, null_resettable) MGLStyleValue<NSString *> *fillPattern;


- (void)addToMapView:(MGLMapView *)mapView;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method needs to be private. We want developers to continue to call -[MGLStyle addLayer:] or -[MGLStyle insertLayer:belowLayer:] as appropriate. To avoid having to create a separate private header for each layer subclass, declare it in the private header for MGLStyle.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Er, I meant the private header for MGLStyleLayer, MGLStyleLayer_Private.h.

// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`.

#import "MGLSource.h"
#import "MGLMapView_Private.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These changes will eventually need to happen in all the style layer subclasses. We have a script (mentioned above) that automatically generates these headers. So when you're ready, update the templates that the script uses (the .ejs files in this directory) and run make style-code-darwin. Don't do that until you've updated the templates with your changes, though!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have updated the script to import MGLMapView_Private.h

@fabian-guerra

Copy link
Copy Markdown
Contributor Author

Yesterday when I was profiling I noticed a small memory leak, with the changes we have implemented we no longer have leaks in StyleLayer classes.

nomemoryleaks

@boundsj boundsj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@fabian-guerra I think this is looking good! Adding a few suggestions here but nothing major.

{
if (self = [super initWithIdentifier:identifier source:source]) {
_layer = new mbgl::style::<%- camelize(type) %>Layer(identifier.UTF8String, source.identifier.UTF8String);
[self commonInit:identifier source:source];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not a big deal but the commonInit pattern is typically used when there is some shared logic that needs to be called by several different initializers and/or something that happens in init also happens latter on. In this case it might be clearer to just do the work in initWithIdentifier:source: itself.

@interface MGLStyleLayer (Private)

@property (nonatomic, readwrite, copy) NSString *identifier;
@property (nonatomic) mbgl::style::Layer *layer;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For future reference, I think we should add documentation for this property like we did in MGLSource_Private.h for the rawSource property. When coming back to this code (or looking at it for the first time) it is not immediately obvious that this is a raw pointer that is useable even after layer ownership is transferred in addToMapView:. Also, for consistency, it might be worth considering renaming this to rawLayer (or naming [MGLSource rawSource] to [MGLSource source] (again)).

@boundsj boundsj removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Nov 4, 2016
@fabian-guerra
fabian-guerra merged commit 373904e into release-ios-v3.4.0 Nov 4, 2016
@boundsj
boundsj deleted the fabian-guerra-layer-ownership-refactor branch November 4, 2016 22:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

iOS Mapbox Maps SDK for iOS macOS Mapbox Maps SDK for macOS release blocker Blocks the next final release runtime styling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants