Skip to content

Commit

Permalink
Show a message when visibility of attributionLabel or its superview c…
Browse files Browse the repository at this point in the history
…hanges.

Fix an issue where updating the visibility of the attribution could cause crash.
  • Loading branch information
Mr-Alirezaa committed Mar 24, 2020
1 parent 4830dc6 commit 6b45c46
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions MapirMapKit/Source/SHMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ - (void)dealloc
[_attributionLabel removeObserver:self forKeyPath:@"hidden"];
[_attributionLabel removeObserver:self forKeyPath:@"alpha"];

[_attributionContainer removeObserver:self forKeyPath:@"hidden"];
[_attributionContainer removeObserver:self forKeyPath:@"alpha"];

[NSNotificationCenter.defaultCenter removeObserver:self];
}

Expand All @@ -150,17 +153,24 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
change:(NSDictionary *)change
context:(void *)context
{
if ([keyPath isEqualToString:@"hidden"] && object == _attributionLabel)
NSString *message = @"Attribution of Map.ir and OpenStreetMap shouldn't be hidden or unreadable unless noticed in another section of the application.";
if ([keyPath isEqualToString:@"hidden"] && (object == _attributionLabel || object == _attributionContainer))
{
NSNumber *hidden = change[NSKeyValueChangeNewKey];
BOOL newHidden = [hidden boolValue];
[self.attributionContainer setHidden:newHidden];
if (newHidden == true)
{
NSLog(@"%@", message);
}
}
else if ([keyPath isEqualToString:@"alpha"] && object == _attributionLabel)
else if ([keyPath isEqualToString:@"alpha"] && (object == _attributionLabel || object == _attributionContainer))
{
NSNumber *alpha = change[NSKeyValueChangeNewKey];
CGFloat newAlpha = [alpha floatValue];
[self.attributionContainer setAlpha:newAlpha];
if (newAlpha != 1)
{
NSLog(@"%@", message);
}
}
else
{
Expand Down Expand Up @@ -258,8 +268,19 @@ - (void)setupNewAttribution

// Observers

[self.attributionLabel addObserver:self forKeyPath:@"hidden" options:NSKeyValueObservingOptionNew context:nil];
[self.attributionLabel addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:nil];
[self.attributionLabel addObserver:self
forKeyPath:@"hidden"
options:NSKeyValueObservingOptionNew context:nil];
[self.attributionLabel addObserver:self
forKeyPath:@"alpha"
options:NSKeyValueObservingOptionNew context:nil];

[self.attributionContainer addObserver:self
forKeyPath:@"hidden"
options:NSKeyValueObservingOptionNew context:nil];
[self.attributionContainer addObserver:self
forKeyPath:@"alpha"
options:NSKeyValueObservingOptionNew context:nil];
}

// MARK: Logo
Expand Down Expand Up @@ -449,6 +470,7 @@ - (void)setStyleURL:(nullable NSURL *)styleURL
[self updateLogoAndAttributionAndCompassForCurrentStyle];
}

// If user updates the style, auto dark mode turns off.
if (!self.internalStyleUpdateFlag && self.autoDarkMode != SHAutoDarkModeOff)
{
self.autoDarkMode = SHAutoDarkModeOff;
Expand Down Expand Up @@ -486,7 +508,6 @@ - (BOOL)isStyleDark
{
return true;
}

return false;
}

Expand Down

0 comments on commit 6b45c46

Please sign in to comment.