-
Notifications
You must be signed in to change notification settings - Fork 161
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
Encapsulate MapboxCoreMaps protocol conformances #265
Conversation
- BaseMapView no longer conforms to MapClient or MBMMetalViewProvider. Instead, it owns and acts as the delegate for a DelegatingMapClient which implements the protocols instead. This allows the required methods to be internal instead of public. - Snapshotter no longer conforms to Observer - ObserverConcrete was refactored into DelegatingObserver and is now used by both BaseMapView and Snapshotter. Misc ACL Changes - BaseMapView setters for __map, metalView, resourceOptions, mapInitOptionsDataSource, and cameraView are now private - BaseMapView properties needsDisplayRefresh, dormant, displayCallback, and styleURI__ are now private - Snapshotter.eventHandlers is now private Other Refactoring - The metal support checks in BaseMapView.commonInit were factored out into a separate helper method to avoid the need for a local variable - In awakeFromNib(), the default styleURI is accessed via StyleURI rather than via a string literal. - PreferredFPS moved to separate file
extension BaseMapView: DelegatingObserverDelegate { | ||
/// Notify correct handler | ||
internal func notify(for event: MapboxCoreMaps.Event) { | ||
let handlers = eventHandlers[event.type] | ||
handlers?.forEach { (handler) in | ||
handler(event) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to a new file called BaseMapView+DelefatingObserverDelegate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but it seems unnecessary to me. What problem would we be solving by moving it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it solves a problem, but if these extensions have the potential to grow in the future, it would be nice to have a bloated 500 + line map view file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If BaseMapView gets that big, the solution is probably to refactor it into multiple components rather than breaking it up into multiple files. I'd be in favor of leaving this as-is for now.
extension BaseMapView: DelegatingMapClientDelegate { | ||
internal func scheduleRepaint() { | ||
needsDisplayRefresh = true | ||
} | ||
|
||
internal func scheduleTask(forTask task: @escaping Task) { | ||
fatalError("scheduleTask is not supported") | ||
} | ||
|
||
internal func getMetalView(for metalDevice: MTLDevice?) -> MTKView? { | ||
let metalView = MTKView(frame: frame, device: metalDevice) | ||
displayCallback = { | ||
metalView.setNeedsDisplay() | ||
} | ||
|
||
metalView.autoresizingMask = [.flexibleHeight, .flexibleWidth] | ||
metalView.autoResizeDrawable = true | ||
metalView.contentScaleFactor = UIScreen.main.scale | ||
metalView.contentMode = .center | ||
metalView.isOpaque = isOpaque | ||
metalView.layer.isOpaque = isOpaque | ||
metalView.isPaused = true | ||
metalView.enableSetNeedsDisplay = true | ||
metalView.presentsWithTransaction = true | ||
|
||
insertSubview(metalView, at: 0) | ||
self.metalView = metalView | ||
|
||
return metalView | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to above, Can we move this to a new file called BaseMapView+DelefatingMapClientDelegate
Pull request checklist:
Summary of changes
Implement Core interfaces via delegation
Instead, it owns and acts as the delegate for a DelegatingMapClient
which implements the protocols instead. This allows the required
methods to be internal instead of public.
used by both BaseMapView and Snapshotter.
Misc ACL Changes
mapInitOptionsDataSource, and cameraView are now private
and styleURI__ are now private
Other Refactoring
into a separate helper method to avoid the need for a local variable
rather than via a string literal.