Skip to content

Commit 5492147

Browse files
authored
fix(iOS): Inline code to find the webview's scrollView (#272)
Currently this works because of a category extension that adds a `scrollView` method to every UIView instance, but that causes issues for SwiftUI so we want to remove that extension from cordova-ios. Since we do need to be able to look up the scrollView in this plugin, we can just define a private local method that does the same thing in a way that doesn't pollute global UIKit classes. Ref: apache/cordova-ios#1400
1 parent 6132b44 commit 5492147

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: src/ios/CDVStatusBar.m

+14-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one
2525

2626
#import "CDVStatusBar.h"
2727
#import <objc/runtime.h>
28+
#import <objc/message.h>
2829
#import <Cordova/CDVViewController.h>
2930

3031
static const void *kHideStatusBar = &kHideStatusBar;
@@ -143,9 +144,9 @@ - (void)pluginInitialize
143144

144145
setting = @"StatusBarDefaultScrollToTop";
145146
if ([self settingForKey:setting]) {
146-
self.webView.scrollView.scrollsToTop = [(NSNumber*)[self settingForKey:setting] boolValue];
147+
[self webViewScrollView].scrollsToTop = [(NSNumber*)[self settingForKey:setting] boolValue];
147148
} else {
148-
self.webView.scrollView.scrollsToTop = NO;
149+
[self webViewScrollView].scrollsToTop = NO;
149150
}
150151

151152
// blank scroll view to intercept status bar taps
@@ -462,6 +463,17 @@ - (void) dealloc
462463
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
463464
}
464465

466+
- (UIScrollView *)webViewScrollView
467+
{
468+
SEL scrollViewSelector = NSSelectorFromString(@"scrollView");
469+
470+
if ([self.webView respondsToSelector:scrollViewSelector]) {
471+
return ((id (*)(id, SEL))objc_msgSend)(self.webView, scrollViewSelector);
472+
}
473+
474+
return nil;
475+
}
476+
465477

466478
#pragma mark - UIScrollViewDelegate
467479

0 commit comments

Comments
 (0)