Support namedOrientationDidChange on iOS
Reviewed By: fkgozali Differential Revision: D5364059 fbshipit-source-id: 63cb91ac0f366f13ea0cff071352e994115cbab9
This commit is contained in:
parent
26764d4179
commit
fbaedfda34
|
@ -77,22 +77,6 @@ NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotif
|
|||
|
||||
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 @@ RCT_EXPORT_MODULE()
|
|||
- (void)setBridge:(RCTBridge *)bridge
|
||||
{
|
||||
RCTAssert(_bridge == nil, @"Should not re-use same UIIManager instance");
|
||||
|
||||
_bridge = bridge;
|
||||
|
||||
_shadowViewRegistry = [NSMutableDictionary new];
|
||||
|
@ -169,9 +152,77 @@ RCT_EXPORT_MODULE()
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue