Skip to content

Commit

Permalink
fix(WKWebview): [iOS] Add shared process pool so cookies and localSto…
Browse files Browse the repository at this point in the history
…rage are shared across webviews (react-native-webview#68)
  • Loading branch information
kylemantesso committed Nov 15, 2018
1 parent b284bf9 commit 19fb449
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ios/RNCWKWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
- (void)goBack;
- (void)reload;
- (void)stopLoading;

- (instancetype)initWithProcessPool:(WKProcessPool*)processPool;

@end
9 changes: 9 additions & 0 deletions ios/RNCWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ @implementation RNCWKWebView
{
UIColor * _savedBackgroundColor;
BOOL _savedHideKeyboardAccessoryView;
WKProcessPool *_processPool;
}

- (void)dealloc
Expand All @@ -63,6 +64,13 @@ + (BOOL)dynamicallyLoadWebKitIfAvailable

return _webkitAvailable;
}

- (instancetype)initWithProcessPool:(WKProcessPool*)processPool {
if (self = [self initWithFrame:CGRectZero]) {
_processPool = processPool;
}
return self;
}


- (instancetype)initWithFrame:(CGRect)frame
Expand All @@ -85,6 +93,7 @@ - (void)didMoveToWindow
};

WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new];
wkWebViewConfig.processPool = _processPool;
wkWebViewConfig.userContentController = [WKUserContentController new];
[wkWebViewConfig.userContentController addScriptMessageHandler: self name: MessageHanderName];
wkWebViewConfig.allowsInlineMediaPlayback = _allowsInlineMediaPlayback;
Expand Down
11 changes: 10 additions & 1 deletion ios/RNCWKWebViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ @implementation RNCWKWebViewManager
{
NSConditionLock *_shouldStartLoadLock;
BOOL _shouldStartLoad;
WKProcessPool *_processPool;
}

RCT_EXPORT_MODULE()

- (id)init {
if (self = [super init]) {
_processPool = [[WKProcessPool alloc] init];
}

return self;
}

- (UIView *)view
{
RNCWKWebView *webView = [RNCWKWebView new];
RNCWKWebView *webView = [[RNCWKWebView alloc] initWithProcessPool:_processPool];
webView.delegate = self;
return webView;
}
Expand Down

0 comments on commit 19fb449

Please sign in to comment.