Permalink
Browse files

Support namedOrientationDidChange on iOS

Reviewed By: fkgozali

Differential Revision: D5364059

fbshipit-source-id: 63cb91ac0f366f13ea0cff071352e994115cbab9
  • Loading branch information...
javache authored and facebook-github-bot committed Jul 25, 2017
1 parent 26764d4 commit fbaedfda34b7980c65e7134360d2117832832064
Showing with 68 additions and 17 deletions.
  1. +68 −17 React/Modules/RCTUIManager.m
@@ -77,22 +77,6 @@ @implementation RCTUIManager
RCT_EXPORT_MODULE()
- (void)didReceiveNewContentSizeMultiplier
{
// Report the event across the bridge.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateContentSizeMultiplier"
body:@([_bridge.accessibilityManager multiplier])];
#pragma clang diagnostic pop
dispatch_async(RCTGetUIManagerQueue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification
object:self];
[self setNeedsLayout];
});
}
- (void)invalidate
{
/**
@@ -140,7 +124,6 @@ - (void)invalidate
- (void)setBridge:(RCTBridge *)bridge
{
RCTAssert(_bridge == nil, @"Should not re-use same UIIManager instance");
_bridge = bridge;
_shadowViewRegistry = [NSMutableDictionary new];
@@ -169,9 +152,77 @@ - (void)setBridge:(RCTBridge *)bridge
selector:@selector(didReceiveNewContentSizeMultiplier)
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
object:_bridge.accessibilityManager];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(namedOrientationDidChange)
name:UIDeviceOrientationDidChangeNotification
object:nil];
[RCTLayoutAnimation initializeStatics];
}
#pragma mark - Event emitting
- (void)didReceiveNewContentSizeMultiplier
{
// Report the event across the bridge.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateContentSizeMultiplier"
body:@([_bridge.accessibilityManager multiplier])];
#pragma clang diagnostic pop
dispatch_async(RCTGetUIManagerQueue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification
object:self];
[self setNeedsLayout];
});
}
// Names and coordinate system from html5 spec:
// https://developer.mozilla.org/en-US/docs/Web/API/Screen.orientation
// https://developer.mozilla.org/en-US/docs/Web/API/Screen.lockOrientation
static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
{
NSString *name;
NSNumber *degrees = @0;
BOOL isLandscape = NO;
switch(orientation) {
case UIDeviceOrientationPortrait:
name = @"portrait-primary";
break;
case UIDeviceOrientationPortraitUpsideDown:
name = @"portrait-secondary";
degrees = @180;
break;
case UIDeviceOrientationLandscapeRight:
name = @"landscape-primary";
degrees = @-90;
isLandscape = YES;
break;
case UIDeviceOrientationLandscapeLeft:
name = @"landscape-secondary";
degrees = @90;
isLandscape = YES;
break;
default:
return nil;
}
return @{
@"name": name,
@"rotationDegrees": degrees,
@"isLandscape": @(isLandscape),
};
}
- (void)namedOrientationDidChange
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[_bridge.eventDispatcher sendDeviceEventWithName:@"namedOrientationDidChange"
body:deviceOrientationEventBody(deviceOrientation)];
#pragma clang diagnostic pop
}
dispatch_queue_t RCTGetUIManagerQueue(void)
{
static dispatch_queue_t shadowQueue;

0 comments on commit fbaedfd

Please sign in to comment.