From 6a0c4e0142ef44d7c9f3f05e9a7ddfed985809ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 10 Apr 2017 14:56:25 -0700 Subject: [PATCH] [macos] Remove link attribute from attribution text Fixed an issue causing the attribution button text to appear blue instead of black. On macOS 10.12 and above, hyperlinks in attributed strings are blue regardless of any color attributes applied to the same run of text. --- platform/darwin/src/MGLAttributionInfo.mm | 7 ++++++- platform/darwin/test/MGLAttributionInfoTests.m | 2 +- platform/macos/CHANGELOG.md | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/platform/darwin/src/MGLAttributionInfo.mm b/platform/darwin/src/MGLAttributionInfo.mm index fa2ae787a..758324449 100644 --- a/platform/darwin/src/MGLAttributionInfo.mm +++ b/platform/darwin/src/MGLAttributionInfo.mm @@ -93,7 +93,12 @@ return; } - MGLAttributionInfo *info = [[MGLAttributionInfo alloc] initWithTitle:title URL:value]; + // Remove the link, because it forces the text to be blue on macOS 10.12 + // and above. + NSMutableAttributedString *unlinkedTitle = [title mutableCopy]; + [unlinkedTitle removeAttribute:NSLinkAttributeName range:unlinkedTitle.mgl_wholeRange]; + + MGLAttributionInfo *info = [[MGLAttributionInfo alloc] initWithTitle:unlinkedTitle URL:value]; info.feedbackLink = isFeedbackLink; [infos addObject:info]; }]; diff --git a/platform/darwin/test/MGLAttributionInfoTests.m b/platform/darwin/test/MGLAttributionInfoTests.m index 74859bda8..e258671c0 100644 --- a/platform/darwin/test/MGLAttributionInfoTests.m +++ b/platform/darwin/test/MGLAttributionInfoTests.m @@ -68,7 +68,7 @@ XCTAssertEqual(infos.count, 1); XCTAssertEqualObjects(infos[0].title.string, @"Mapbox"); - XCTAssertEqualObjects([infos[0].title attribute:NSLinkAttributeName atIndex:0 effectiveRange:nil], [NSURL URLWithString:@"https://www.mapbox.com/"]); + XCTAssertNil([infos[0].title attribute:NSLinkAttributeName atIndex:0 effectiveRange:nil]); XCTAssertEqualObjects([infos[0].title attribute:NSUnderlineStyleAttributeName atIndex:0 effectiveRange:nil], @(NSUnderlineStyleSingle)); #if TARGET_OS_IPHONE diff --git a/platform/macos/CHANGELOG.md b/platform/macos/CHANGELOG.md index 152fdc382..dab02592a 100644 --- a/platform/macos/CHANGELOG.md +++ b/platform/macos/CHANGELOG.md @@ -2,6 +2,7 @@ ## master +* Fixed an issue causing attribution button text to appear blue instead of black. ([#8701](https://github.com/mapbox/mapbox-gl-native/pull/8701)) * The error passed into `-[MGLMapViewDelegate mapViewDidFailLoadingMap:withError:]` now includes a more specific description and failure reason. ([#8418](https://github.com/mapbox/mapbox-gl-native/pull/8418)) ## 0.4.0