Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[ios, macos] Adapt Mapbox Streets–sourced layers for Dynamic Type. #9734

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions platform/darwin/src/MGLStyle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,32 @@ - (void)setLocalizesLabels:(BOOL)localizesLabels

self.localizedLayersByIdentifier = [NSMutableDictionary dictionary];
}
[self setPreferredContentSize:nil];
}

- (void)setPreferredContentSize:(UIContentSizeCategory)preferredContentSize
{
for (MGLSymbolStyleLayer *layer in self.layers) {
if (![layer isKindOfClass:[MGLSymbolStyleLayer class]]) {
continue;
}

MGLVectorSource *source = (MGLVectorSource *)[self sourceWithIdentifier:layer.sourceIdentifier];
if (![source isKindOfClass:[MGLVectorSource class]] || !source.mapboxStreets) {
continue;
}

if ([layer.textFontSize isKindOfClass:[MGLConstantStyleValue class]]) {
NSNumber *textFontSize = [(MGLConstantStyleValue<NSNumber *> *)layer.textFontSize rawValue];
textFontSize = [NSNumber numberWithFloat:(textFontSize.floatValue * [self sizeForContentSizeCategory:preferredContentSize])];
Copy link
Contributor

Choose a reason for hiding this comment

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

We could genericize the expression transformation in #11651 so that it could also be used to scale fonts according to the style layer’s content size category.

layer.textFontSize = [MGLStyleValue<NSNumber *> valueWithRawValue:textFontSize];
}
}
}

- (CGFloat)sizeForContentSizeCategory:(UIContentSizeCategory)preferredContentSize
{
return 1.3;
}

@end
3 changes: 3 additions & 0 deletions platform/darwin/src/MGLStyle_Private.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "MGLStyle.h"
#import <UIKit/UIContentSizeCategory.h>

#import "MGLStyleLayer.h"
#import "MGLFillStyleLayer.h"
Expand All @@ -21,6 +22,8 @@ NS_ASSUME_NONNULL_BEGIN

- (void)setStyleClasses:(NS_ARRAY_OF(NSString *) *)appliedClasses transitionDuration:(NSTimeInterval)transitionDuration;

- (void)setPreferredContentSize:(UIContentSizeCategory)preferredContentSize;

@end

NS_ASSUME_NONNULL_END
7 changes: 7 additions & 0 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ - (void)commonInit
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wakeGL:) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preferredContentSizeChanged:) name:UIContentSizeCategoryDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

// set initial position
Expand Down Expand Up @@ -2456,6 +2457,12 @@ - (void)accessibilityScaleBy:(double)scaleFactor
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, self.accessibilityValue);
}

- (void)preferredContentSizeChanged:(NSNotification *)notification {
UIContentSizeCategory preferredContentSize = [notification.userInfo objectForKey:UIContentSizeCategoryNewValueKey];
[self.style setPreferredContentSize:preferredContentSize];

}

#pragma mark - Geography -

+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingCenterCoordinate
Expand Down