Skip to content

Commit

Permalink
fix(catalyst): Fix content behind titlebar (#1517)
Browse files Browse the repository at this point in the history
Closes GH-1491.
  • Loading branch information
dpogue authored Dec 25, 2024
1 parent c1004fe commit 538fe8e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 2 additions & 6 deletions CordovaLib/Classes/Public/CDVPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ Licensed to the Apache Software Foundation (ASF) under one
#import <Cordova/CDVPlugin+Resources.h>
#import "CDVPlugin+Private.h"
#import <Cordova/CDVViewController.h>
#include <objc/message.h>

@implementation UIView (org_apache_cordova_UIView_Extension)

@dynamic scrollView;

- (UIScrollView*)scrollView
{
SEL scrollViewSelector = NSSelectorFromString(@"scrollView");

if ([self respondsToSelector:scrollViewSelector]) {
return ((id (*)(id, SEL))objc_msgSend)(self, scrollViewSelector);
if ([self respondsToSelector:@selector(scrollView)]) {
return [self performSelector:@selector(scrollView)];
}

return nil;
}

Expand Down
26 changes: 25 additions & 1 deletion CordovaLib/Classes/Public/CDVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Licensed to the Apache Software Foundation (ASF) under one
under the License.
*/

#import <TargetConditionals.h>
#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
#import <objc/message.h>

#import <Cordova/CDVAppDelegate.h>
#import <Cordova/CDVPlugin.h>
Expand Down Expand Up @@ -373,6 +373,30 @@ -(void)viewWillAppear:(BOOL)animated
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

#if TARGET_OS_MACCATALYST
BOOL hideTitlebar = [self.settings cordovaBoolSettingForKey:@"HideDesktopTitlebar" defaultValue:NO];
if (hideTitlebar) {
UIWindowScene *scene = self.view.window.windowScene;
if (scene) {
scene.titlebar.titleVisibility = UITitlebarTitleVisibilityHidden;
scene.titlebar.toolbar = nil;
}
} else {
// We need to fix the web content going behind the title bar
self.webView.translatesAutoresizingMaskIntoConstraints = NO;
[self.webView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES;
[self.webView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
[self.webView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES;
[self.webView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;

if ([self.webView respondsToSelector:@selector(scrollView)]) {
UIScrollView *scrollView = [self.webView performSelector:@selector(scrollView)];
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
#endif

[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVViewDidAppearNotification object:nil]];
}

Expand Down

0 comments on commit 538fe8e

Please sign in to comment.