Skip to content

Commit b8a3d38

Browse files
committed
fix(iOS): Inline code to find the webview's scrollView
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 b8a3d38

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Diff for: src/ios/CDVStatusBar.m

+13-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ - (void)pluginInitialize
143143

144144
setting = @"StatusBarDefaultScrollToTop";
145145
if ([self settingForKey:setting]) {
146-
self.webView.scrollView.scrollsToTop = [(NSNumber*)[self settingForKey:setting] boolValue];
146+
[self webViewScrollView].scrollsToTop = [(NSNumber*)[self settingForKey:setting] boolValue];
147147
} else {
148-
self.webView.scrollView.scrollsToTop = NO;
148+
[self webViewScrollView].scrollsToTop = NO;
149149
}
150150

151151
// blank scroll view to intercept status bar taps
@@ -462,6 +462,17 @@ - (void) dealloc
462462
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
463463
}
464464

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

466477
#pragma mark - UIScrollViewDelegate
467478

0 commit comments

Comments
 (0)