Skip to content

Commit 538fe8e

Browse files
authored
fix(catalyst): Fix content behind titlebar (#1517)
Closes GH-1491.
1 parent c1004fe commit 538fe8e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

CordovaLib/Classes/Public/CDVPlugin.m

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@ Licensed to the Apache Software Foundation (ASF) under one
2121
#import <Cordova/CDVPlugin+Resources.h>
2222
#import "CDVPlugin+Private.h"
2323
#import <Cordova/CDVViewController.h>
24-
#include <objc/message.h>
2524

2625
@implementation UIView (org_apache_cordova_UIView_Extension)
2726

2827
@dynamic scrollView;
2928

3029
- (UIScrollView*)scrollView
3130
{
32-
SEL scrollViewSelector = NSSelectorFromString(@"scrollView");
33-
34-
if ([self respondsToSelector:scrollViewSelector]) {
35-
return ((id (*)(id, SEL))objc_msgSend)(self, scrollViewSelector);
31+
if ([self respondsToSelector:@selector(scrollView)]) {
32+
return [self performSelector:@selector(scrollView)];
3633
}
37-
3834
return nil;
3935
}
4036

CordovaLib/Classes/Public/CDVViewController.m

+25-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ Licensed to the Apache Software Foundation (ASF) under one
1717
under the License.
1818
*/
1919

20+
#import <TargetConditionals.h>
2021
#import <AVFoundation/AVFoundation.h>
2122
#import <Foundation/Foundation.h>
2223
#import <WebKit/WebKit.h>
23-
#import <objc/message.h>
2424

2525
#import <Cordova/CDVAppDelegate.h>
2626
#import <Cordova/CDVPlugin.h>
@@ -373,6 +373,30 @@ -(void)viewWillAppear:(BOOL)animated
373373
-(void)viewDidAppear:(BOOL)animated
374374
{
375375
[super viewDidAppear:animated];
376+
377+
#if TARGET_OS_MACCATALYST
378+
BOOL hideTitlebar = [self.settings cordovaBoolSettingForKey:@"HideDesktopTitlebar" defaultValue:NO];
379+
if (hideTitlebar) {
380+
UIWindowScene *scene = self.view.window.windowScene;
381+
if (scene) {
382+
scene.titlebar.titleVisibility = UITitlebarTitleVisibilityHidden;
383+
scene.titlebar.toolbar = nil;
384+
}
385+
} else {
386+
// We need to fix the web content going behind the title bar
387+
self.webView.translatesAutoresizingMaskIntoConstraints = NO;
388+
[self.webView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES;
389+
[self.webView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
390+
[self.webView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES;
391+
[self.webView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
392+
393+
if ([self.webView respondsToSelector:@selector(scrollView)]) {
394+
UIScrollView *scrollView = [self.webView performSelector:@selector(scrollView)];
395+
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
396+
}
397+
}
398+
#endif
399+
376400
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewDidAppearNotification object:nil]];
377401
}
378402

0 commit comments

Comments
 (0)