Skip to content

Commit

Permalink
fix: Inline code to find the webview's scrollView
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dpogue committed Aug 16, 2024
1 parent 6132b44 commit 3e72921
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ios/CDVStatusBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ - (void)pluginInitialize

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
Expand Down Expand Up @@ -462,6 +462,17 @@ - (void) dealloc
[[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

Expand Down

0 comments on commit 3e72921

Please sign in to comment.