Skip to content

Commit

Permalink
Add code to remove keyboard input accessory view that was causing lay…
Browse files Browse the repository at this point in the history
…out errors
  • Loading branch information
bizz84 committed Jun 11, 2019
1 parent 8495514 commit 4411f54
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions ios/Classes/FlutterWebviewPlugin.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#import "FlutterWebviewPlugin.h"
#import <objc/runtime.h>

static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";

@interface _NoInputAccessoryView : NSObject

@end

@implementation _NoInputAccessoryView

- (id)inputAccessoryView {
return nil;
}

@end

// UIWebViewDelegate
@interface FlutterWebviewPlugin() <WKNavigationDelegate, UIScrollViewDelegate, WKUIDelegate> {
BOOL _enableAppScheme;
Expand Down Expand Up @@ -114,6 +127,7 @@ - (void)initWebview:(FlutterMethodCall*)call {
self.webview.hidden = [hidden boolValue];
self.webview.scrollView.showsHorizontalScrollIndicator = [scrollBar boolValue];
self.webview.scrollView.showsVerticalScrollIndicator = [scrollBar boolValue];
[self removeInputAccessoryViewFromWKWebView:self.webview];

[self.webview addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:NULL];

Expand Down Expand Up @@ -345,4 +359,37 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
}
}

#pragma mark - remove input accessory view
- (void)removeInputAccessoryViewFromWKWebView:(WKWebView *)webView {
UIView *targetView;

for (UIView *view in webView.scrollView.subviews) {
if([[view.class description] hasPrefix:@"WKContent"]) {
targetView = view;
}
}

if (!targetView) {
return;
}

NSString *noInputAccessoryViewClassName = [NSString stringWithFormat:@"%@_NoInputAccessoryView", targetView.class.superclass];
Class newClass = NSClassFromString(noInputAccessoryViewClassName);

if(newClass == nil) {
newClass = objc_allocateClassPair(targetView.class, [noInputAccessoryViewClassName cStringUsingEncoding:NSASCIIStringEncoding], 0);
if(!newClass) {
return;
}

Method method = class_getInstanceMethod([_NoInputAccessoryView class], @selector(inputAccessoryView));

class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));

objc_registerClassPair(newClass);
}

object_setClass(targetView, newClass);
}

@end

0 comments on commit 4411f54

Please sign in to comment.