mirror of
https://github.com/status-im/react-native-webview.git
synced 2025-02-22 08:48:39 +00:00
fix(WKWebView): Fix the message handle bug. (#143)
* fix webview always recreate * fix webview always recreate * code format * Update RNCWKWebView.m * @bugfix fix the message handle problem
This commit is contained in:
parent
692961bfca
commit
2b9292ed1c
@ -40,12 +40,7 @@ static NSString *const MessageHanderName = @"ReactNative";
|
||||
BOOL _savedHideKeyboardAccessoryView;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
if(_webView){
|
||||
[_webView removeObserver:self forKeyPath:@"estimatedProgress"];
|
||||
}
|
||||
}
|
||||
- (void)dealloc{}
|
||||
|
||||
/**
|
||||
* See https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/WebKitAvail.html.
|
||||
@ -131,22 +126,34 @@ static NSString *const MessageHanderName = @"ReactNative";
|
||||
[self addSubview:_webView];
|
||||
[self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
|
||||
[self visitSource];
|
||||
} else {
|
||||
[_webView.configuration.userContentController removeScriptMessageHandlerForName:MessageHanderName];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeFromSuperview
|
||||
{
|
||||
if (_webView) {
|
||||
[_webView.configuration.userContentController removeScriptMessageHandlerForName:MessageHanderName];
|
||||
[_webView removeObserver:self forKeyPath:@"estimatedProgress"];
|
||||
[_webView removeFromSuperview];
|
||||
_webView = nil;
|
||||
}
|
||||
|
||||
[super removeFromSuperview];
|
||||
}
|
||||
|
||||
-(void)keyboardWillHide
|
||||
{
|
||||
keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];
|
||||
[[NSRunLoop mainRunLoop] addTimer:keyboardTimer forMode:NSRunLoopCommonModes];
|
||||
}
|
||||
|
||||
-(void)keyboardWillShow
|
||||
{
|
||||
if (keyboardTimer != nil) {
|
||||
[keyboardTimer invalidate];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)keyboardDisplacementFix
|
||||
{
|
||||
// https://stackoverflow.com/a/9637807/824966
|
||||
|
Loading…
x
Reference in New Issue
Block a user