Skip to content

Commit

Permalink
fix: Prevent recursion in scrollView monkeypatch
Browse files Browse the repository at this point in the history
If you call scrollView on a UIView that does not have its own scrollView
method, this hijack method will keep recursively calling itself until
you run out of stack space. Try to guard against that by making sure
that it's not getting called on the same instance multiple times.

TODO: Think about thread safety, but in theory because this is
view-related stuff it's only safe to run on the main thread.
  • Loading branch information
dpogue committed Jan 28, 2025
1 parent 5cf4d94 commit 8ffc72e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions CordovaLib/Classes/Public/CDVPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ @implementation UIView (org_apache_cordova_UIView_Extension)

- (UIScrollView*)scrollView
{
if ([self respondsToSelector:@selector(scrollView)]) {
return [self performSelector:@selector(scrollView)];
static UIView *caller = nil;

if (caller != self && [self respondsToSelector:@selector(scrollView)]) {
caller = self;
UIScrollView *sv = [self performSelector:@selector(scrollView)];
caller = nil;
return sv;
}
caller = nil;
return nil;
}

Expand Down

0 comments on commit 8ffc72e

Please sign in to comment.