forked from rust-ui/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__DisableContentInsetAdjustment.m
More file actions
38 lines (31 loc) · 1.29 KB
/
__DisableContentInsetAdjustment.m
File metadata and controls
38 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
#import <objc/runtime.h>
// Disable WKWebView scrollView contentInsetAdjustmentBehavior
// This allows viewport-fit=cover to work correctly on iOS
static IMP original_didMoveToWindow = NULL;
static void swizzled_didMoveToWindow(id self, SEL _cmd) {
if (original_didMoveToWindow) {
((void (*)(id, SEL))original_didMoveToWindow)(self, _cmd);
}
if ([self isKindOfClass:[WKWebView class]]) {
WKWebView *webView = (WKWebView *)self;
webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
__attribute__((constructor))
static void DisableContentInsetAdjustment(void) {
Class WKWebViewClass = [WKWebView class];
if (!WKWebViewClass) {
NSLog(@"DisableContentInsetAdjustment: WKWebView class not found");
return;
}
Method originalMethod = class_getInstanceMethod(WKWebViewClass, @selector(didMoveToWindow));
if (!originalMethod) {
NSLog(@"DisableContentInsetAdjustment: didMoveToWindow method not found");
return;
}
original_didMoveToWindow = method_getImplementation(originalMethod);
method_setImplementation(originalMethod, (IMP)swizzled_didMoveToWindow);
NSLog(@"DisableContentInsetAdjustment: Successfully configured");
}