mirror of
https://github.com/status-im/react-native.git
synced 2025-01-13 19:15:05 +00:00
iOS: Expose fontScale to JavaScript
Summary: A related Android PR is #11008. Font scale was exposed through: - The `getContentSizeMultiplier` method - The `didUpdateContentSizeMultiplier` event These are now deprecated. The reason is that there was already an API that exposed font scale. However, it was Android only. We now expose font scale through that API on iOS as well. Specifically: - Font scale is now available as `PixelRatio.getFontScale()`. - The `change` event on the `Dimensions` object now fires when font scale changes. This change also adds support for `Dimensions.get('screen')` on iOS. Previously, only `Dimensions.get('window')` was available on iOS. The motivation is that, [according to this comment](https://github.com/facebook/react-native/pull/11008#issuecomment-275123609), we'd like to deprecate `window` dimensions in favor of `screen` dimensions in the future. **Test plan (required)** Verified that `PixelRatio.getFontScale()` and the `change` event work properly in a test app. Adam Comella Microsoft Corp. Closes https://github.com/facebook/react-native/pull/12268 Differential Revision: D4673642 Pulled By: mkonicek fbshipit-source-id: 2602204da6998a96216e06f5321f28f6603e4972
This commit is contained in:
parent
36f09dc252
commit
22b3faf1ad
@ -236,8 +236,13 @@ RCT_EXPORT_MODULE()
|
||||
- (void)didReceiveNewContentSizeMultiplier
|
||||
{
|
||||
// Report the event across the bridge.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions"
|
||||
body:RCTExportedDimensions(_bridge)];
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateContentSizeMultiplier"
|
||||
body:@([_bridge.accessibilityManager multiplier])];
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
dispatch_async(RCTGetUIManagerQueue(), ^{
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification
|
||||
@ -260,7 +265,7 @@ RCT_EXPORT_MODULE()
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions"
|
||||
body:RCTExportedDimensions()];
|
||||
body:RCTExportedDimensions(_bridge)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
@ -1541,23 +1546,26 @@ RCT_EXPORT_METHOD(clearJSResponder)
|
||||
|
||||
constants[@"customBubblingEventTypes"] = bubblingEvents;
|
||||
constants[@"customDirectEventTypes"] = directEvents;
|
||||
constants[@"Dimensions"] = RCTExportedDimensions();
|
||||
constants[@"Dimensions"] = RCTExportedDimensions(_bridge);
|
||||
|
||||
return constants;
|
||||
}
|
||||
|
||||
static NSDictionary *RCTExportedDimensions()
|
||||
static NSDictionary *RCTExportedDimensions(RCTBridge *bridge)
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
|
||||
// Don't use RCTScreenSize since it the interface orientation doesn't apply to it
|
||||
CGRect screenSize = [[UIScreen mainScreen] bounds];
|
||||
NSDictionary *dims = @{
|
||||
@"width": @(screenSize.size.width),
|
||||
@"height": @(screenSize.size.height),
|
||||
@"scale": @(RCTScreenScale()),
|
||||
@"fontScale": @(bridge.accessibilityManager.multiplier)
|
||||
};
|
||||
return @{
|
||||
@"window": @{
|
||||
@"width": @(screenSize.size.width),
|
||||
@"height": @(screenSize.size.height),
|
||||
@"scale": @(RCTScreenScale()),
|
||||
},
|
||||
@"window": dims,
|
||||
@"screen": dims
|
||||
};
|
||||
}
|
||||
|
||||
@ -1580,11 +1588,6 @@ RCT_EXPORT_METHOD(configureNextLayoutAnimation:(NSDictionary *)config
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getContentSizeMultiplier:(nonnull RCTResponseSenderBlock)callback)
|
||||
{
|
||||
callback(@[@(_bridge.accessibilityManager.multiplier)]);
|
||||
}
|
||||
|
||||
- (void)rootViewForReactTag:(NSNumber *)reactTag withCompletion:(void (^)(UIView *view))completion
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
@ -1656,6 +1659,12 @@ static UIView *_jsResponder;
|
||||
[self setSize:frame.size forView:view];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getContentSizeMultiplier:(nonnull RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCTLogWarn(@"`getContentSizeMultiplier` is deprecated. Instead, use `PixelRatio.getFontScale()` and listen to the `didUpdateDimensions` event.");
|
||||
callback(@[@(_bridge.accessibilityManager.multiplier)]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTBridge (RCTUIManager)
|
||||
|
Loading…
x
Reference in New Issue
Block a user