-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathPassThroughBackgroundView.m
More file actions
79 lines (64 loc) · 2.57 KB
/
PassThroughBackgroundView.m
File metadata and controls
79 lines (64 loc) · 2.57 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// PassThroughBackgroundView.m
//
// This code is provided under the MIT License.
//
// Please visit www.count.ly for more information.
#import "PassThroughBackgroundView.h"
#if (TARGET_OS_IOS)
@implementation PassThroughBackgroundView
@synthesize webView;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
#if (TARGET_OS_IOS)
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleScreenChange) name:UIDeviceOrientationDidChangeNotification object:nil];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleScreenChange) name:UIScreenModeDidChangeNotification object:nil];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleScreenChange) name:UIApplicationDidBecomeActiveNotification object:nil];
#endif
return self;
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
if (self.webView && CGRectContainsPoint(self.webView.frame, point)) {
return YES;
}
if (self.dismissButton && CGRectContainsPoint(self.dismissButton.frame, point)) {
return YES;
}
return NO;
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
if (self.traitCollection.horizontalSizeClass != previousTraitCollection.horizontalSizeClass) {
[self adjustWebViewForTraitCollection:self.traitCollection];
}
}
- (void)adjustWebViewForTraitCollection:(UITraitCollection *)traitCollection {
if (traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
[self handleScreenChange];
}
}
- (void)handleScreenChange {
// Execute after a short delay to ensure properties are updated
dispatch_async(dispatch_get_main_queue(), ^{
[self updateWindowSize];
});
}
- (void)updateWindowSize {
CGSize size = [CountlyCommon.sharedInstance getWindowSize];
CGFloat width = size.width;
CGFloat height = size.height;
NSString *postMessage = [NSString stringWithFormat:
@"javascript:window.postMessage({type: 'resize', width: %f, height: %f}, '*');",
width,
height];
[self.webView evaluateJavaScript:postMessage completionHandler:^(id result, NSError *err) {
if (err != nil) {
CLY_LOG_E(@"%s updateWindowSize, %@", __FUNCTION__, err);
}
}];
}
// Always remove observers when the view is deallocated
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
#endif