Skip to content

Commit d4a168e

Browse files
authored
Merge pull request #391 from Countly/fw_rework_basic
Fw rework basic
2 parents a769739 + ee77e4e commit d4a168e

File tree

7 files changed

+188
-146
lines changed

7 files changed

+188
-146
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## XX.XX.XX
2+
* The feedback widgets now have fullscreen and transparent backgrounds for a cleaner look.
23
* Added a config method to disable server config in the initialization "disableSDKBehaviorSettings()".
34

45
## 25.4.1

CountlyCommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ void CountlyPrint(NSString *stringToPrint);
123123
- (BOOL)hasStarted_;
124124

125125
- (NSURLSession *)URLSession;
126+
127+
- (CGSize)getWindowSize;
126128
@end
127129

128130

CountlyCommon.m

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,47 @@ - (NSURLSession *)URLSession
329329
}
330330
}
331331

332+
- (CGSize)getWindowSize {
333+
#if (TARGET_OS_IOS)
334+
UIWindow *window = nil;
335+
336+
if (@available(iOS 13.0, *)) {
337+
for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
338+
if ([scene isKindOfClass:[UIWindowScene class]]) {
339+
window = ((UIWindowScene *)scene).windows.firstObject;
340+
break;
341+
}
342+
}
343+
} else {
344+
window = [[UIApplication sharedApplication].delegate window];
345+
}
346+
347+
if (!window) return CGSizeZero;
348+
349+
UIEdgeInsets safeArea = UIEdgeInsetsZero;
350+
CGFloat screenScale = [UIScreen mainScreen].scale;
351+
if (@available(iOS 11.0, *)) {
352+
safeArea = window.safeAreaInsets;
353+
safeArea.left /= screenScale;
354+
safeArea.bottom /= screenScale;
355+
safeArea.right /= screenScale;
356+
}
357+
358+
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
359+
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
360+
361+
CGSize size = CGSizeMake(window.bounds.size.width, window.bounds.size.height);
362+
363+
if(!isLandscape){
364+
size.width -= safeArea.left + safeArea.right;
365+
size.height -= safeArea.top + safeArea.bottom;
366+
}
367+
368+
return size;
369+
#endif
370+
return CGSizeZero;
371+
}
372+
332373
@end
333374

334375

CountlyContentBuilderInternal.m

Lines changed: 38 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -191,47 +191,9 @@ - (NSURLRequest *)fetchContentsRequest
191191
return request;
192192
}
193193

194-
- (CGSize)getWindowSize {
195-
UIWindow *window = nil;
196-
197-
if (@available(iOS 13.0, *)) {
198-
for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
199-
if ([scene isKindOfClass:[UIWindowScene class]]) {
200-
window = ((UIWindowScene *)scene).windows.firstObject;
201-
break;
202-
}
203-
}
204-
} else {
205-
window = [[UIApplication sharedApplication].delegate window];
206-
}
207-
208-
if (!window) return CGSizeZero;
209-
210-
UIEdgeInsets safeArea = UIEdgeInsetsZero;
211-
CGFloat screenScale = [UIScreen mainScreen].scale;
212-
if (@available(iOS 11.0, *)) {
213-
safeArea = window.safeAreaInsets;
214-
safeArea.left /= screenScale;
215-
safeArea.bottom /= screenScale;
216-
safeArea.right /= screenScale;
217-
}
218-
219-
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
220-
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
221-
222-
CGSize size = CGSizeMake(window.bounds.size.width, window.bounds.size.height);
223-
224-
if(!isLandscape){
225-
size.width -= safeArea.left + safeArea.right;
226-
size.height -= safeArea.top + safeArea.bottom;
227-
}
228-
229-
return size;
230-
}
231-
232194
- (NSString *)resolutionJson {
233195
//TODO: check why area is not clickable and safearea things
234-
CGSize size = [self getWindowSize];
196+
CGSize size = [CountlyCommon.sharedInstance getWindowSize];
235197

236198
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
237199
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
@@ -261,45 +223,44 @@ - (void)showContentWithHtmlPath:(NSString *)urlString placementCoordinates:(NSDi
261223

262224

263225
dispatch_async(dispatch_get_main_queue(), ^ {
264-
// Detect screen orientation
265-
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
266-
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
226+
// Detect screen orientation
227+
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
228+
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
229+
230+
// Get the appropriate coordinates based on the orientation
231+
NSDictionary *coordinates = isLandscape ? placementCoordinates[@"l"] : placementCoordinates[@"p"];
267232

268-
269-
// Get the appropriate coordinates based on the orientation
270-
NSDictionary *coordinates = isLandscape ? placementCoordinates[@"l"] : placementCoordinates[@"p"];
271-
272-
CGFloat x = [coordinates[@"x"] floatValue];
273-
CGFloat y = [coordinates[@"y"] floatValue];
274-
CGFloat width = [coordinates[@"w"] floatValue];
275-
CGFloat height = [coordinates[@"h"] floatValue];
276-
277-
CGRect frame = CGRectMake(x, y, width, height);
278-
279-
// Log the URL and the frame
280-
CLY_LOG_I(@"%s, Showing content from URL: %@", __FUNCTION__, url);
281-
CLY_LOG_I(@"%s, Placement frame: %@", __FUNCTION__, NSStringFromCGRect(frame));
282-
283-
CountlyWebViewManager* webViewManager = CountlyWebViewManager.new;
284-
[webViewManager createWebViewWithURL:url frame:frame appearBlock:^
285-
{
286-
CLY_LOG_I(@"%s, Webview appeared", __FUNCTION__);
287-
self->_isCurrentlyContentShown = YES;
288-
[self clearContentState];
289-
} dismissBlock:^
290-
{
291-
CLY_LOG_I(@"%s, Webview dismissed", __FUNCTION__);
292-
self->_isCurrentlyContentShown = NO;
293-
self->_minuteTimer = [NSTimer scheduledTimerWithTimeInterval:self->_zoneTimerInterval
294-
target:self
295-
selector:@selector(enterContentZone)
296-
userInfo:nil
297-
repeats:NO];
298-
if(self.contentCallback) {
299-
self.contentCallback(CLOSED, NSDictionary.new);
300-
}
301-
}];
233+
CGFloat x = [coordinates[@"x"] floatValue];
234+
CGFloat y = [coordinates[@"y"] floatValue];
235+
CGFloat width = [coordinates[@"w"] floatValue];
236+
CGFloat height = [coordinates[@"h"] floatValue];
237+
238+
CGRect frame = CGRectMake(x, y, width, height);
239+
240+
// Log the URL and the frame
241+
CLY_LOG_I(@"%s, Showing content from URL: %@", __FUNCTION__, url);
242+
CLY_LOG_I(@"%s, Placement frame: %@", __FUNCTION__, NSStringFromCGRect(frame));
243+
244+
CountlyWebViewManager* webViewManager = CountlyWebViewManager.new;
245+
[webViewManager createWebViewWithURL:url frame:frame appearBlock:^
246+
{
247+
CLY_LOG_I(@"%s, Webview appeared", __FUNCTION__);
248+
self->_isCurrentlyContentShown = YES;
249+
[self clearContentState];
250+
} dismissBlock:^
251+
{
252+
CLY_LOG_I(@"%s, Webview dismissed", __FUNCTION__);
253+
self->_isCurrentlyContentShown = NO;
254+
self->_minuteTimer = [NSTimer scheduledTimerWithTimeInterval:self->_zoneTimerInterval
255+
target:self
256+
selector:@selector(enterContentZone)
257+
userInfo:nil
258+
repeats:NO];
259+
if(self.contentCallback) {
260+
self.contentCallback(CLOSED, NSDictionary.new);
261+
}
262+
}];
302263
});
303264
}
304265
#endif
305-
@end
266+
@end

CountlyFeedbackWidget.m

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Please visit www.count.ly for more information.
66

77
#import "CountlyCommon.h"
8+
#import "CountlyWebViewManager.h"
89
#if (TARGET_OS_IOS)
910
#import <WebKit/WebKit.h>
1011
#endif
@@ -24,8 +25,13 @@ @interface CountlyFeedbackWidget ()
2425
@property (nonatomic) CLYFeedbackWidgetType type;
2526
@property (nonatomic) NSString* ID;
2627
@property (nonatomic) NSString* name;
28+
@property (nonatomic) NSString* widgetVersion;
2729
@property (nonatomic) NSArray<NSString*>* tags;
2830
@property (nonatomic) NSDictionary* data;
31+
@property (nonatomic) WidgetCallback widgetCallback;
32+
#if (TARGET_OS_IOS)
33+
@property (nonatomic) CLYInternalViewController* webVC;
34+
#endif
2935
@end
3036

3137

@@ -39,6 +45,7 @@ + (CountlyFeedbackWidget *)createWithDictionary:(NSDictionary *)dictionary
3945
feedback.type = dictionary[@"type"];
4046
feedback.name = dictionary[@"name"];
4147
feedback.tags = dictionary[@"tg"];
48+
feedback.widgetVersion = dictionary[@"wv"];
4249
return feedback;
4350
}
4451

@@ -52,25 +59,64 @@ - (void)present
5259
- (void)presentWithAppearBlock:(void(^ __nullable)(void))appearBlock andDismissBlock:(void(^ __nullable)(void))dismissBlock
5360
{
5461
CLY_LOG_I(@"%s %@ %@", __FUNCTION__, appearBlock, dismissBlock);
55-
[self presentWithCallback:^(WidgetState widgetState) {
62+
id widgetCallback = ^(WidgetState widgetState) {
5663
if(appearBlock && widgetState == WIDGET_APPEARED) {
5764
appearBlock();
5865
}
5966

6067
if(dismissBlock && widgetState == WIDGET_CLOSED) {
6168
dismissBlock();
6269
}
63-
}];
70+
};
71+
72+
[self presentWithCallback:widgetCallback];
73+
}
74+
75+
- (void)presentWidget_new:(WidgetCallback) widgetCallback;
76+
{
77+
CLY_LOG_I(@"%s %@", __FUNCTION__, widgetCallback);
78+
if (!CountlyConsentManager.sharedInstance.consentForFeedback)
79+
return;
80+
81+
CGSize size = [CountlyCommon.sharedInstance getWindowSize];
82+
83+
dispatch_async(dispatch_get_main_queue(), ^ {
84+
CGRect frame = CGRectMake(0.0, 0.0, size.width, size.height);
85+
86+
// Log the URL and the frame
87+
CLY_LOG_I(@"%s, Placement frame: %@", __FUNCTION__, NSStringFromCGRect(frame));
88+
89+
CountlyWebViewManager* webViewManager = CountlyWebViewManager.new;
90+
[webViewManager createWebViewWithURL:[self generateWidgetURL] frame:frame appearBlock:^
91+
{
92+
CLY_LOG_I(@"%s, Webview appeared", __FUNCTION__);
93+
if(widgetCallback)
94+
widgetCallback(WIDGET_APPEARED);
95+
} dismissBlock:^
96+
{
97+
CLY_LOG_I(@"%s, Webview dismissed", __FUNCTION__);
98+
if (widgetCallback)
99+
widgetCallback(WIDGET_CLOSED);
100+
[self recordReservedEventForDismissing];
101+
}];
102+
});
64103
}
65104

66105
- (void)presentWithCallback:(WidgetCallback) widgetCallback;
67106
{
68107
CLY_LOG_I(@"%s %@", __FUNCTION__, widgetCallback);
69108
if (!CountlyConsentManager.sharedInstance.consentForFeedback)
70109
return;
110+
111+
if (self.widgetVersion && ![self.widgetVersion isKindOfClass:[NSNull class]]) {
112+
[self presentWidget_new:widgetCallback];
113+
return;
114+
}
115+
71116
__block CLYInternalViewController* webVC = CLYInternalViewController.new;
72117
webVC.view.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.4];
73118
webVC.modalPresentationStyle = UIModalPresentationCustom;
119+
74120
// Configure WKWebView with non-persistent data store
75121
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
76122
configuration.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
@@ -79,11 +125,13 @@ - (void)presentWithCallback:(WidgetCallback) widgetCallback;
79125
webView.layer.shadowOpacity = 0.5;
80126
webView.layer.shadowOffset = CGSizeMake(0.0f, 5.0f);
81127
webView.layer.masksToBounds = NO;
128+
82129
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
83130
[webVC.view addSubview:webView];
84131
webVC.webView = webView;
85-
NSURLRequest* request = [self displayRequest];
132+
NSURLRequest* request = [NSURLRequest requestWithURL:[self generateWidgetURL]];
86133
[webView loadRequest:request];
134+
87135
CLYButton* dismissButton = [CLYButton dismissAlertButton];
88136
dismissButton.onClick = ^(id sender)
89137
{
@@ -193,7 +241,7 @@ - (NSURLRequest *)dataRequest
193241
}
194242
}
195243

196-
- (NSURLRequest *)displayRequest {
244+
- (NSURL *)generateWidgetURL {
197245
// Create the base URL with endpoint and feedback type
198246
NSMutableString *URL = [NSMutableString stringWithFormat:@"%@%@/%@",
199247
CountlyConnectionManager.sharedInstance.host,
@@ -227,7 +275,12 @@ - (NSURLRequest *)displayRequest {
227275
[URL appendFormat:@"?%@", queryString];
228276

229277
// Create custom parameters
230-
NSDictionary *customParams = @{@"tc": @"1"};
278+
NSMutableDictionary *customParams = [@{@"tc": @"1"} mutableCopy];
279+
280+
if (self.widgetVersion && ![self.widgetVersion isKindOfClass:[NSNull class]]) {
281+
customParams[@"rw"] = @"1";
282+
customParams[@"xb"] = @"1";
283+
}
231284

232285
// Create JSON data from custom parameters
233286
NSError *error;
@@ -241,8 +294,7 @@ - (NSURLRequest *)displayRequest {
241294
[URL appendFormat:@"&custom=%@", customString.cly_URLEscaped];
242295
}
243296

244-
// Create and return the NSURLRequest
245-
return [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
297+
return [NSURL URLWithString:URL];
246298
}
247299

248300

0 commit comments

Comments
 (0)