Skip to content

Commit

Permalink
fix(iOS): Inline code to find the webview's scrollView (#272)
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 authored Aug 20, 2024
1 parent 6132b44 commit 5492147
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/ios/CDVStatusBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one

#import "CDVStatusBar.h"
#import <objc/runtime.h>
#import <objc/message.h>
#import <Cordova/CDVViewController.h>

static const void *kHideStatusBar = &kHideStatusBar;
Expand Down Expand Up @@ -143,9 +144,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 +463,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 5492147

Please sign in to comment.