-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathDisplayDeviceUtil.m
52 lines (40 loc) · 1.7 KB
/
DisplayDeviceUtil.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#import "DisplayDeviceUtil.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
#import "RCTUtils.h"
@implementation DisplayDeviceUtil
RCT_EXPORT_MODULE();
@synthesize bridge = _bridge;
- (instancetype)init {
if ((self = [super init])) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(displayOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)displayOrientationDidChange:(NSNotification*)note {
CGSize frameSize = [UIScreen mainScreen].applicationFrame.size;
/* For Non-Orientation Dependant Versions */
if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1)
&& UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
frameSize = CGSizeMake(frameSize.height, frameSize.width);
}
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
NSDictionary *dimensions = @{ @"width": @(frameSize.width), @"height": @(frameSize.height), @"orientation": @(deviceOrientation) };
NSLog(@"%@", dimensions);
[_bridge.eventDispatcher sendDeviceEventWithName:@"orientationDidChange" body:dimensions];
}
- (NSDictionary *)constantsToExport {
BOOL isPhone = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone;
BOOL isTablet = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
return @{
@"isPhone" : @(isPhone),
@"isTablet" : @(isTablet)
};
}
@end