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

Add support for non-HTML attribution #1163

Merged
merged 10 commits into from
Mar 8, 2022
Merged

Conversation

evil159
Copy link
Contributor

@evil159 evil159 commented Mar 2, 2022

Currently there is no attribution in case the provided source attribution is in form of plain text({attribution: "OpenStreetMap contributors, CC-BY-SA"}. This PR adds support for plain text attributions.

Before v1 v2

Initially I went with the same approach as on Android mapbox/mapbox-maps-android#1087 to disable alert's actions without URLs(see v1 image above), but it does not look good on iOS due to platform differences. Since there can only be a single plain text attribution I decided put it into alert's message instead(v2).

Fixes #1164

Pull request checklist:

  • Write tests for all new functionality. If tests were not written, please explain why.
  • Describe the changes in this PR, especially public API changes.
  • Add a changelog entry to to bottom of the relevant section (typically the ## main heading near the top).
  • Review and agree to the Contributor License Agreement (CLA).

@evil159 evil159 requested review from macdrevx and OdNairy March 2, 2022 00:34
Copy link
Contributor

@macdrevx macdrevx left a comment

Choose a reason for hiding this comment

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

I like the UI! Nice job.

What changes do we need to make to add really good tests for this part of the SDK? Let's incorporate refactoring for testability into every change we make unless there's a really good reason not to.

evil159 and others added 2 commits March 2, 2022 12:13
Co-authored-by: Andrew Hershberger <andrew.hershberger@mapbox.com>
@@ -7,7 +7,10 @@ extension MapView: AttributionDialogManagerDelegate {
}

func attributionDialogManager(_ attributionDialogManager: AttributionDialogManager, didTriggerActionFor attribution: Attribution) {
let url: URL = attribution.isFeedbackURL ? mapboxFeedbackURL() : attribution.url
guard let url: URL = attribution.isFeedbackURL ? mapboxFeedbackURL() : attribution.url else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need an explicit URL type in this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need, indeed. It went away after a refactoring related to #1163 (comment)

@evil159
Copy link
Contributor Author

evil159 commented Mar 2, 2022

What changes do we need to make to add really good tests for this part of the SDK? Let's incorporate refactoring for testability into every change we make unless there's a really good reason not to.

Thanks for calling me out on this 😅 With the changes to Attribution I added tests covering almost all of it.

A bit trickier with AttributionDialogManager as it has the logic to generate correct attribution dialog intertwined with UIAlertController. An option I considered was to mirror UIAlertController/UIAlertAction infrastructure with our own data classes/builders to make it easier to test the logic separately. But, it turned out that UIAlertController fares reasonably well in unit tests. I think it provides a good effort/result balance.

Comment on lines 31 to 32
window.makeKeyAndVisible()
window.rootViewController = viewController
Copy link
Contributor

Choose a reason for hiding this comment

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

If this ordering results in a warning logged to the console, you may want to try setting rootViewController before calling makeKeyAndVisible

Comment on lines 10 to 18
override func setUp() {
super.setUp()
Bundle.mapboxMapsMetadata.version = "AttributionTests"
}

override func tearDown() {
super.tearDown()
Bundle.mapboxMapsMetadata.version = sdkVersion
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I was surprised that mapboxMapsMetadata was settable. That looks like a bug in my opinion. Could you avoid setting it here and use string interpolation to create the expected value below?

Copy link
Contributor

@macdrevx macdrevx left a comment

Choose a reason for hiding this comment

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

Just a couple additional suggestions. Approving!

@evil159 evil159 enabled auto-merge (squash) March 8, 2022 21:49
@evil159 evil159 merged commit 0ed23b8 into main Mar 8, 2022
@evil159 evil159 deleted the rol-plain-text-attribution-support branch March 8, 2022 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attribution parser doesn't show source attributions
3 participants