From 5492147ab72034e98a8b683ebdac26c7ea6a6fda Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 20 Aug 2024 00:25:39 -0700 Subject: [PATCH] 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: https://github.com/apache/cordova-ios/pull/1400 --- src/ios/CDVStatusBar.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m index 3e788b8..eb21d15 100644 --- a/src/ios/CDVStatusBar.m +++ b/src/ios/CDVStatusBar.m @@ -25,6 +25,7 @@ #import "CDVStatusBar.h" #import +#import #import static const void *kHideStatusBar = &kHideStatusBar; @@ -143,9 +144,9 @@ static const void *kStatusBarStyle = &kStatusBarStyle; setting = @"StatusBarDefaultScrollToTop"; if ([self settingForKey:setting]) { - self.webView.scrollView.scrollsToTop = [(NSNumber*)[self settingForKey:setting] boolValue]; + [self webViewScrollView].scrollsToTop = [(NSNumber*)[self settingForKey:setting] boolValue]; } else { - self.webView.scrollView.scrollsToTop = NO; + [self webViewScrollView].scrollsToTop = NO; } // blank scroll view to intercept status bar taps @@ -462,6 +463,17 @@ static const void *kStatusBarStyle = &kStatusBarStyle; [[NSNotificationCenter defaultCenter]removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; } +- (UIScrollView *)webViewScrollView +{ + SEL scrollViewSelector = NSSelectorFromString(@"scrollView"); + + if ([self.webView respondsToSelector:scrollViewSelector]) { + return ((id (*)(id, SEL))objc_msgSend)(self.webView, scrollViewSelector); + } + + return nil; +} + #pragma mark - UIScrollViewDelegate