Skip to content

Commit 2b3cafa

Browse files
authored
Merge pull request #325 from Countly/content_resize
feat: content resize iOS and Android RC
2 parents 582de4f + 6381bc2 commit 2b3cafa

File tree

7 files changed

+123
-53
lines changed

7 files changed

+123
-53
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ android {
3838
}
3939

4040
dependencies {
41-
implementation 'ly.count.android:sdk:24.7.7'
41+
implementation 'ly.count.android:sdk:24.7.9-RC1'
4242
implementation 'com.google.firebase:firebase-messaging:24.0.3'
4343
}

example/ios/Flutter/Flutter.podspec

Lines changed: 0 additions & 18 deletions
This file was deleted.

ios/Classes/CountlyiOS/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## XX.XX.XX
2+
* Added dynamic resizing functionality for the content zone
3+
* Improved management of content zone size for better responsiveness
4+
5+
* Fixed an issue where the build UUID and executable name were missing from crash reports
6+
17
## 24.7.9
28
* Improved view tracking capabilities
39

ios/Classes/CountlyiOS/CountlyContentBuilderInternal.m

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,49 @@ - (NSURLRequest *)fetchContentsRequest
151151
return request;
152152
}
153153

154-
- (NSString *)resolutionJson {
155-
//TODO: check why area is not clickable and safearea things
156-
CGRect screenBounds = [UIScreen mainScreen].bounds;
157-
if (@available(iOS 11.0, *)) {
158-
CGFloat top = UIApplication.sharedApplication.keyWindow.safeAreaInsets.top;
159-
160-
if (top) {
161-
screenBounds.origin.y += top + 5;
162-
screenBounds.size.height -= top + 5;
163-
} else {
164-
screenBounds.origin.y += 20.0;
165-
screenBounds.size.height -= 20.0;
154+
- (CGSize)getWindowSize {
155+
CGSize size = CGSizeZero;
156+
157+
// Attempt to retrieve the size from the connected scenes (for modern apps)
158+
if (@available(iOS 13.0, *)) {
159+
NSSet<UIScene *> *scenes = [[UIApplication sharedApplication] connectedScenes];
160+
for (UIScene *scene in scenes) {
161+
if ([scene isKindOfClass:[UIWindowScene class]]) {
162+
UIWindowScene *windowScene = (UIWindowScene *)scene;
163+
UIWindow *window = windowScene.windows.firstObject;
164+
if (window) {
165+
size = window.bounds.size;
166+
return size; // Return immediately if we find a valid size
167+
}
168+
}
169+
}
170+
}
171+
172+
// Fallback for legacy apps using AppDelegate
173+
id<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
174+
if ([appDelegate respondsToSelector:@selector(window)]) {
175+
UIWindow *legacyWindow = [appDelegate performSelector:@selector(window)];
176+
if (legacyWindow) {
177+
size = legacyWindow.bounds.size;
166178
}
167-
} else {
168-
screenBounds.origin.y += 20.0;
169-
screenBounds.size.height -= 20.0;
170179
}
180+
181+
return size;
182+
}
183+
184+
- (NSString *)resolutionJson {
185+
//TODO: check why area is not clickable and safearea things
186+
CGSize size = [self getWindowSize];
171187

172-
CGFloat width = screenBounds.size.width;
173-
CGFloat height = screenBounds.size.height;
188+
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
189+
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
190+
191+
CGFloat lHpW = isLandscape ? size.height : size.width;
192+
CGFloat lWpH = isLandscape ? size.width : size.height;
174193

175194
NSDictionary *resolutionDict = @{
176-
@"portrait": @{@"height": @(height), @"width": @(width)},
177-
@"landscape": @{@"height": @(width), @"width": @(height)}
195+
@"portrait": @{@"height": @(lWpH), @"width": @(lHpW)},
196+
@"landscape": @{@"height": @(lHpW), @"width": @(lWpH)}
178197
};
179198

180199
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:resolutionDict options:0 error:nil];

ios/Classes/CountlyiOS/CountlyCrashReporter.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ void CountlyExceptionHandler(NSException *exception, bool isFatal, bool isAutoDe
288288
NSMutableDictionary* crashReport = [crashData.crashMetrics mutableCopy];
289289
crashReport[kCountlyCRKeyError] = crashData.stackTrace;
290290
crashReport[kCountlyCRKeyBinaryImages] = [CountlyCrashReporter.sharedInstance binaryImagesForStackTrace:stackTrace];
291+
crashReport[kCountlyCRKeyBuildUUID] = CountlyCrashReporter.sharedInstance.buildUUID ?: @"";
292+
crashReport[kCountlyCRKeyExecutableName] = CountlyCrashReporter.sharedInstance.executableName ?: @"";
291293
crashReport[kCountlyCRKeyName] = crashData.crashDescription;
292294
crashReport[kCountlyCRKeyType] = crashData.name;
293295
crashReport[kCountlyCRKeyNonfatal] = @(!crashData.fatal);
@@ -498,8 +500,6 @@ - (NSMutableDictionary*)getCrashMetrics
498500
crashReport[kCountlyCRKeyResolution] = CountlyDeviceInfo.resolution;
499501
crashReport[kCountlyCRKeyAppVersion] = CountlyDeviceInfo.appVersion;
500502
crashReport[kCountlyCRKeyAppBuild] = CountlyDeviceInfo.appBuild;
501-
crashReport[kCountlyCRKeyBuildUUID] = CountlyCrashReporter.sharedInstance.buildUUID ?: @"";
502-
crashReport[kCountlyCRKeyExecutableName] = CountlyCrashReporter.sharedInstance.executableName ?: @"";
503503

504504
crashReport[kCountlyCRKeyRAMCurrent] = @((CountlyDeviceInfo.totalRAM - CountlyDeviceInfo.freeRAM) / kCLYMebibit);
505505
crashReport[kCountlyCRKeyRAMTotal] = @(CountlyDeviceInfo.totalRAM / kCLYMebibit);

ios/Classes/CountlyiOS/CountlyWebViewManager.m

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ - (void)createWebViewWithURL:(NSURL *)url
2121
UIViewController *rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
2222
CGRect backgroundFrame = rootViewController.view.bounds;
2323

24-
if (@available(iOS 11.0, *)) {
25-
CGFloat top = UIApplication.sharedApplication.keyWindow.safeAreaInsets.top;
26-
backgroundFrame.origin.y += top ? top + 5 : 20.0;
27-
backgroundFrame.size.height -= top ? top + 5 : 20.0;
28-
} else {
29-
backgroundFrame.origin.y += 20.0;
30-
backgroundFrame.size.height -= 20.0;
31-
}
32-
3324
self.backgroundView = [[PassThroughBackgroundView alloc] initWithFrame:backgroundFrame];
3425
self.backgroundView.backgroundColor = [UIColor clearColor];
3526
[rootViewController.view addSubview:self.backgroundView];
@@ -297,8 +288,6 @@ - (void)resizeWebViewWithJSONString:(NSString *)jsonString {
297288
}];
298289
}
299290

300-
301-
302291
- (void)closeWebView {
303292
dispatch_async(dispatch_get_main_queue(), ^{
304293
if (self.dismissBlock) {

ios/Classes/CountlyiOS/PassThroughBackgroundView.m

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ @implementation PassThroughBackgroundView
1414
- (instancetype)initWithFrame:(CGRect)frame {
1515

1616
self = [super initWithFrame:frame];
17-
if (self) {
18-
}
17+
#if (TARGET_OS_IOS)
18+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleScreenChange) name:UIDeviceOrientationDidChangeNotification object:nil];
19+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleScreenChange) name:UIScreenModeDidChangeNotification object:nil];
20+
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleScreenChange) name:UIApplicationDidBecomeActiveNotification object:nil];
21+
#endif
1922
return self;
2023
}
2124

@@ -31,6 +34,77 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
3134
return NO;
3235
}
3336

37+
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
38+
[super traitCollectionDidChange:previousTraitCollection];
39+
40+
if (self.traitCollection.horizontalSizeClass != previousTraitCollection.horizontalSizeClass) {
41+
[self adjustWebViewForTraitCollection:self.traitCollection];
42+
}
43+
}
44+
45+
- (void)adjustWebViewForTraitCollection:(UITraitCollection *)traitCollection {
46+
if (traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
47+
[self handleScreenChange];
48+
}
49+
}
50+
51+
CGSize getWindowSize(void) {
52+
CGSize size = CGSizeZero;
53+
54+
// Attempt to retrieve the size from the connected scenes (for modern apps)
55+
if (@available(iOS 13.0, *)) {
56+
NSSet<UIScene *> *scenes = [[UIApplication sharedApplication] connectedScenes];
57+
for (UIScene *scene in scenes) {
58+
if ([scene isKindOfClass:[UIWindowScene class]]) {
59+
UIWindowScene *windowScene = (UIWindowScene *)scene;
60+
UIWindow *window = windowScene.windows.firstObject;
61+
if (window) {
62+
size = window.bounds.size;
63+
return size; // Return immediately if we find a valid size
64+
}
65+
}
66+
}
67+
}
68+
69+
// Fallback for legacy apps using AppDelegate
70+
id<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
71+
if ([appDelegate respondsToSelector:@selector(window)]) {
72+
UIWindow *legacyWindow = [appDelegate performSelector:@selector(window)];
73+
if (legacyWindow) {
74+
size = legacyWindow.bounds.size;
75+
}
76+
}
77+
78+
return size;
79+
}
80+
81+
- (void)handleScreenChange {
82+
// Execute after a short delay to ensure properties are updated
83+
dispatch_async(dispatch_get_main_queue(), ^{
84+
[self updateWindowSize];
85+
});
86+
}
87+
88+
- (void)updateWindowSize {
89+
CGSize size = getWindowSize();
90+
CGFloat width = size.width;
91+
CGFloat height = size.height;
92+
93+
NSString *postMessage = [NSString stringWithFormat:
94+
@"javascript:window.postMessage({type: 'resize', width: %f, height: %f}, '*');",
95+
width,
96+
height];
97+
[self.webView evaluateJavaScript:postMessage completionHandler:^(id result, NSError *err) {
98+
if (err != nil) {
99+
CLY_LOG_E(@"[PassThroughBackgroundView] updateWindowSize, %@", err);
100+
}
101+
}];
102+
}
103+
104+
// Always remove observers when the view is deallocated
105+
- (void)dealloc {
106+
[[NSNotificationCenter defaultCenter] removeObserver:self];
107+
}
34108

35109
@end
36110
#endif

0 commit comments

Comments
 (0)