mirror of
https://github.com/status-im/react-native-webview.git
synced 2025-02-23 09:18:38 +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;
|
BOOL _savedHideKeyboardAccessoryView;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc{}
|
||||||
{
|
|
||||||
if(_webView){
|
|
||||||
[_webView removeObserver:self forKeyPath:@"estimatedProgress"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/WebKitAvail.html.
|
* 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 addSubview:_webView];
|
||||||
[self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
|
[self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
|
||||||
[self visitSource];
|
[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
|
-(void)keyboardWillHide
|
||||||
{
|
{
|
||||||
keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];
|
keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];
|
||||||
[[NSRunLoop mainRunLoop] addTimer:keyboardTimer forMode:NSRunLoopCommonModes];
|
[[NSRunLoop mainRunLoop] addTimer:keyboardTimer forMode:NSRunLoopCommonModes];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)keyboardWillShow
|
-(void)keyboardWillShow
|
||||||
{
|
{
|
||||||
if (keyboardTimer != nil) {
|
if (keyboardTimer != nil) {
|
||||||
[keyboardTimer invalidate];
|
[keyboardTimer invalidate];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)keyboardDisplacementFix
|
-(void)keyboardDisplacementFix
|
||||||
{
|
{
|
||||||
// https://stackoverflow.com/a/9637807/824966
|
// https://stackoverflow.com/a/9637807/824966
|
||||||
|
Loading…
x
Reference in New Issue
Block a user