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

Encapsulate MapboxCoreMaps protocol conformances #265

Merged
merged 4 commits into from
Apr 15, 2021

Conversation

macdrevx
Copy link
Contributor

@macdrevx macdrevx commented Apr 14, 2021

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Write tests for all new functionality. If tests were not written, please explain why.
  • Document any changes to public APIs.
  • Apply changelog label ('breaking change', 'bug 🪲', 'build', 'docs', 'feature 🍏', 'performance ⚡', 'testing 💯') or use the label 'skip changelog'
  • Update changelog

Summary of changes

Implement Core interfaces via delegation

  • [breaking] 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.
  • [breaking] 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
  • Adds test xib to Xcode project

- 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
@macdrevx macdrevx added the breaking change ⚠️ If your pull request introduces a breaking change and updates are required when version is published label Apr 14, 2021
@macdrevx macdrevx marked this pull request as ready for review April 14, 2021 20:14
Comment on lines +392 to +400
extension BaseMapView: DelegatingObserverDelegate {
/// Notify correct handler
internal func notify(for event: MapboxCoreMaps.Event) {
let handlers = eventHandlers[event.type]
handlers?.forEach { (handler) in
handler(event)
}
}
}
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Comment on lines +402 to +432
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
}
}
Copy link
Contributor

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

@macdrevx macdrevx merged commit 3cd94b4 into main Apr 15, 2021
@macdrevx macdrevx deleted the ah/remove-conformances branch April 15, 2021 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change ⚠️ If your pull request introduces a breaking change and updates are required when version is published
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants