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

[examples] Add SwiftUI example #78

Merged
merged 12 commits into from
Feb 15, 2021
Merged

[examples] Add SwiftUI example #78

merged 12 commits into from
Feb 15, 2021

Conversation

captainbarbosa
Copy link
Contributor

PRs must be submitted under the terms of our Contributor License Agreement CLA.

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Apply changelog label ('breaking change', 'bug 🪲', 'build', 'docs', 'feature 🍏', 'performance ⚡', 'testing 💯') or use the label 'skip changelog'
  • Add an entry inside this element for inclusion in the mapbox-maps-ios changelog: <changelog>Added SwiftUI example.</changelog>.

Summary of changes

Adds a new example that illustrates how to wrap a MapView inside a SwiftUI view.

cc @mapbox/maps-ios

@CLAassistant
Copy link

CLAassistant commented Feb 6, 2021

CLA assistant check
All committers have signed the CLA.

@macdrevx
Copy link
Contributor

macdrevx commented Feb 6, 2021

I pushed a commit with some updates that I worked on today and went over with @captainbarbosa. I need to add some additional explanatory comments to the example before this is merged.

My commit also removes the annotations aspect of the example. I'd like to review that part with @julianrex and @nishant-karajgikar to see if we can come up with something a bit more declarative.

public enum StyleURL {
public enum StyleURL: Hashable {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a minor SDK modification which made the example easier to write.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

@macdrevx
Copy link
Contributor

@julianrex @ZiZasaurus this is ready for re-review. Please read the documentation I added to make sure it is clear. Let me know if you'd like to chat about it.

Examples/Examples/All Examples/SwiftUIExample.swift Outdated Show resolved Hide resolved
Examples/Examples/All Examples/SwiftUIExample.swift Outdated Show resolved Hide resolved
Comment on lines +222 to +228
/// We configure the slider to bind to the camera's zoom. Adjusting the slider with
/// change the zoom on the map, and changing the zoom by interacting with the map
/// will change the slider. Here's the data flow:
///
/// Slider to Map:
/// - User interacts with the slider
/// - Slider updates the camera binding's zoom value
Copy link
Contributor

Choose a reason for hiding this comment

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

Did something happen with indents here?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is how Xcode likes it. The comments are aligned to the indentation of the next line of code.

Comment on lines +226 to +236
/// Slider to Map:
/// - User interacts with the slider
/// - Slider updates the camera binding's zoom value
/// - SwiftUI invokes `updateUIView(_:context:)` on `SwiftUIMapView`
/// - `SwiftUIMapView` reads the updated camera zoom value and sets it on the underlying `MapView`
///
/// Map to Slider:
/// - User interacts with the map, adjusting the zoom
/// - Map sends the `.cameraDidChange` event, which is observed by the coordinator
/// - The coordinator updates the value of the zoom on the `camera` binding
/// - SwiftUI updates the Slider accordingly
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for clarifying the flow here - definitely helps

Examples/Examples/Models/Examples.swift Outdated Show resolved Hide resolved
public enum StyleURL {
public enum StyleURL: Hashable {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

@macdrevx macdrevx enabled auto-merge (squash) February 15, 2021 17:07
@macdrevx macdrevx merged commit 26c1445 into main Feb 15, 2021
@macdrevx macdrevx deleted the nb/swiftui-example branch February 15, 2021 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants