Skip to content

Commit

Permalink
fix(WKWebview): Reverts #134, fixes issue where keyboard dismiss woul…
Browse files Browse the repository at this point in the history
…d scroll to top (#210)
  • Loading branch information
ryanlntn authored and jamonholmgren committed Dec 14, 2018
1 parent 8323566 commit 9f37dde
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions ios/RNCWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#import "objc/runtime.h"

static NSTimer *keyboardTimer;
static NSString *const MessageHanderName = @"ReactNative";

// runtime trick to remove WKWebView keyboard default toolbar
Expand Down Expand Up @@ -71,19 +70,6 @@ - (instancetype)initWithFrame:(CGRect)frame
_automaticallyAdjustContentInsets = YES;
_contentInset = UIEdgeInsetsZero;
}

// Workaround for a keyboard dismissal bug present in iOS 12
// https://openradar.appspot.com/radar?id=5018321736957952
if (@available(iOS 12.0, *)) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillHide)
name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillShow)
name:UIKeyboardWillShowNotification object:nil];
}
return self;
}

Expand Down Expand Up @@ -145,27 +131,6 @@ - (void)removeFromSuperview
[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
[UIView animateWithDuration:.25 animations:^{
self.webView.scrollView.contentOffset = CGPointMake(0, 0);
}];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
if ([keyPath isEqual:@"estimatedProgress"] && object == self.webView) {
if(_onLoadingProgress){
Expand Down

0 comments on commit 9f37dde

Please sign in to comment.