summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2018-11-20 23:20:20 -0500
committerJulian Rex <julian.rex@mapbox.com>2018-11-20 23:21:05 -0500
commit1b5dead0dc0710f28a424935adc9bd0c74f666d4 (patch)
treec6c5218ebc2b570475e65c0f7c5ed268909a2d03
parent6aaf5e8e02f92453c20019f2a47924743fca8d1b (diff)
downloadqtlocation-mapboxgl-upstream/jrex/13155-MGLCollisionBehaviorPre4_0.tar.gz
Moved perSourceCollision logic to init. Added support for `NSString` values in plist.upstream/jrex/13155-MGLCollisionBehaviorPre4_0
-rw-r--r--platform/darwin/src/MGLRendererConfiguration.mm42
-rw-r--r--platform/darwin/test/MGLRendererConfigurationTests.mm32
2 files changed, 50 insertions, 24 deletions
diff --git a/platform/darwin/src/MGLRendererConfiguration.mm b/platform/darwin/src/MGLRendererConfiguration.mm
index b2c8a8216b..90778ea86d 100644
--- a/platform/darwin/src/MGLRendererConfiguration.mm
+++ b/platform/darwin/src/MGLRendererConfiguration.mm
@@ -10,6 +10,11 @@
static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPre4_0";
+@interface MGLRendererConfiguration ()
+@property (nonatomic, readwrite) BOOL perSourceCollisions;
+@end
+
+
@implementation MGLRendererConfiguration
+ (instancetype)currentConfiguration {
@@ -20,21 +25,32 @@ static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPr
return [self initWithPropertyDictionary:[[NSBundle mainBundle] infoDictionary]];
}
-- (instancetype)initWithPropertyDictionary:(NSDictionary *)properties {
+- (instancetype)initWithPropertyDictionary:(nonnull NSDictionary *)properties {
+ self = [super init];
if (self) {
-
- // Set the collision behaviour
-
+ // Set the collision behaviour. A value set in `NSUserDefaults.standardUserDefaults`
+ // should override anything in the application's info.plist
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- // Only use the behavior from the application's info.plist, if we don't already
- // have the behavior specified in `NSUserDefaults.standardUserDefaults`
- if (![defaults objectForKey:MGLCollisionBehaviorPre4_0Key]) {
- NSNumber *bundleNumber = MGL_OBJC_DYNAMIC_CAST(properties[MGLCollisionBehaviorPre4_0Key], NSNumber);
-
- // Set or clear
- [defaults setObject:bundleNumber forKey:MGLCollisionBehaviorPre4_0Key];
+ if ([defaults objectForKey:MGLCollisionBehaviorPre4_0Key]) {
+ _perSourceCollisions = [defaults boolForKey:MGLCollisionBehaviorPre4_0Key];
+ }
+ else {
+ id collisionBehaviourValue = properties[MGLCollisionBehaviorPre4_0Key];
+
+ NSNumber *collisionBehaviourNumber = MGL_OBJC_DYNAMIC_CAST(collisionBehaviourValue, NSNumber);
+
+ if (collisionBehaviourNumber) {
+ _perSourceCollisions = collisionBehaviourNumber.boolValue;
+ } else {
+ // Also support NSString to correspond with the behavior of `-[NSUserDefaults boolForKey:]`
+ NSString *collisionBehaviourString = MGL_OBJC_DYNAMIC_CAST(collisionBehaviourValue, NSString);
+
+ if (collisionBehaviourString) {
+ _perSourceCollisions = collisionBehaviourString.boolValue;
+ }
+ }
}
}
@@ -67,8 +83,4 @@ static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPr
return fontFamilyName ? std::string([fontFamilyName UTF8String]) : mbgl::optional<std::string>();
}
-- (BOOL)perSourceCollisions {
- return [[NSUserDefaults standardUserDefaults] boolForKey:MGLCollisionBehaviorPre4_0Key];
-}
-
@end
diff --git a/platform/darwin/test/MGLRendererConfigurationTests.mm b/platform/darwin/test/MGLRendererConfigurationTests.mm
index 683ef34ca4..a0c630ebb5 100644
--- a/platform/darwin/test/MGLRendererConfigurationTests.mm
+++ b/platform/darwin/test/MGLRendererConfigurationTests.mm
@@ -5,7 +5,7 @@
static NSString * const MGLRendererConfigurationTests_collisionBehaviorKey = @"MGLCollisionBehaviorPre4_0";
@interface MGLRendererConfiguration (Tests)
-- (instancetype)initWithPropertyDictionary:(NSDictionary*)bundle;
+- (instancetype)initWithPropertyDictionary:(nonnull NSDictionary*)bundle;
@end
@@ -25,40 +25,54 @@ static NSString * const MGLRendererConfigurationTests_collisionBehaviorKey = @"M
- (void)testSettingMGLCollisionBehaviorPre40WithEmptyDictionary
{
MGLRendererConfiguration *config = [[MGLRendererConfiguration alloc] initWithPropertyDictionary:@{}];
- XCTAssertFalse([config perSourceCollisions]);
+ XCTAssertFalse(config.perSourceCollisions);
}
- (void)testSettingMGLCollisionBehaviorPre40WithYESDictionary
{
MGLRendererConfiguration *config = [[MGLRendererConfiguration alloc] initWithPropertyDictionary:@{MGLRendererConfigurationTests_collisionBehaviorKey:@(NO)}];
- XCTAssertFalse([config perSourceCollisions]);
+ XCTAssertFalse(config.perSourceCollisions);
}
- (void)testSettingMGLCollisionBehaviorPre40WithNODictionary
{
MGLRendererConfiguration *config = [[MGLRendererConfiguration alloc] initWithPropertyDictionary:@{MGLRendererConfigurationTests_collisionBehaviorKey:@(YES)}];
- XCTAssert([config perSourceCollisions]);
+ XCTAssert(config.perSourceCollisions);
}
- (void)testSettingMGLCollisionBehaviorPre40InNSUserDefaults {
{
XCTAssertNil([[NSUserDefaults standardUserDefaults] objectForKey:MGLRendererConfigurationTests_collisionBehaviorKey]);
MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration];
- XCTAssertFalse([config perSourceCollisions]);
+ XCTAssertFalse(config.perSourceCollisions);
}
[[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:MGLRendererConfigurationTests_collisionBehaviorKey];
{
XCTAssertNotNil([[NSUserDefaults standardUserDefaults] objectForKey:MGLRendererConfigurationTests_collisionBehaviorKey]);
MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration];
- XCTAssertFalse([config perSourceCollisions]);
+ XCTAssertFalse(config.perSourceCollisions);
}
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:MGLRendererConfigurationTests_collisionBehaviorKey];
{
XCTAssertNotNil([[NSUserDefaults standardUserDefaults] objectForKey:MGLRendererConfigurationTests_collisionBehaviorKey]);
MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration];
- XCTAssert([config perSourceCollisions]);
+ XCTAssert(config.perSourceCollisions);
+ }
+}
+
+- (void)testSettingMGLCollisionBehaviorPre40PListValueUsingString {
+ // Dictionary = "NO"
+ {
+ MGLRendererConfiguration *config = [[MGLRendererConfiguration alloc] initWithPropertyDictionary:@{MGLRendererConfigurationTests_collisionBehaviorKey:@"NO"}];
+ XCTAssertFalse(config.perSourceCollisions);
+ }
+
+ // Dictionary = "YES"
+ {
+ MGLRendererConfiguration *config = [[MGLRendererConfiguration alloc] initWithPropertyDictionary:@{MGLRendererConfigurationTests_collisionBehaviorKey:@"YES"}];
+ XCTAssert(config.perSourceCollisions);
}
}
@@ -68,14 +82,14 @@ static NSString * const MGLRendererConfigurationTests_collisionBehaviorKey = @"M
{
[[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:MGLRendererConfigurationTests_collisionBehaviorKey];
MGLRendererConfiguration *config = [[MGLRendererConfiguration alloc] initWithPropertyDictionary:@{MGLRendererConfigurationTests_collisionBehaviorKey:@(NO)}];
- XCTAssert([config perSourceCollisions]);
+ XCTAssert(config.perSourceCollisions);
}
// Dictionary = YES, NSUserDefaults = NO
{
[[NSUserDefaults standardUserDefaults] setObject:@(NO) forKey:MGLRendererConfigurationTests_collisionBehaviorKey];
MGLRendererConfiguration *config = [[MGLRendererConfiguration alloc] initWithPropertyDictionary:@{MGLRendererConfigurationTests_collisionBehaviorKey:@(YES)}];
- XCTAssertFalse([config perSourceCollisions]);
+ XCTAssertFalse(config.perSourceCollisions);
}
}