Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
Fix for iOS11 initial scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Sep 20, 2017
1 parent bc47a8c commit 1cb767d
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/ios/CDVWKWebViewEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,60 @@ Licensed to the Apache Software Foundation (ASF) under one
#define CDV_IONIC_STOP_SCROLL @"stopScroll"


@implementation UIScrollView (BugIOS11)

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000

+ (void)load {
if (@available(iOS 11.0, *)) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(init);
SEL swizzledSelector = @selector(xxx_init);

Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));

if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
}

#endif

#pragma mark - Method Swizzling

- (id)xxx_init {
id a = [self xxx_init];
if (@available(iOS 11.0, *)) {
NSArray *stack = [NSThread callStackSymbols];
for(NSString *trace in stack) {
if([trace containsString:@"WebKit"]) {
[a setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
break;
}
}
}
return a;
}

@end


@interface CDVWKWeakScriptMessageHandler : NSObject <WKScriptMessageHandler>

@property (nonatomic, weak, readonly) id<WKScriptMessageHandler>scriptMessageHandler;
Expand Down

4 comments on commit 1cb767d

@kesozjura
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks build with Xcode 8.3.2. Any suggestion how to solve this?
screenshot at sep 21 10-12-10

@manucorporat
Copy link
Author

@manucorporat manucorporat commented on 1cb767d Sep 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kesozjura ok! thanks for the report! working in a fix... it probably needs Xcode 9, but I can fix it, hold on

@manucorporat
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kesozjura it should be fixed now: a76bbc9

@kesozjura
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for extremly quick response. We have shared environment with remote build so I can not upgrade Xcode easily.

Please sign in to comment.