1010#import < React/RCTUIManager.h>
1111#import < React/RCTDefines.h>
1212#import " RNCWebView.h"
13+ #import " RNCWebViewDecisionManager.h"
1314
14- @interface RNCWebViewManager () <RNCWebViewDelegate>
15+ @interface RNCWebViewManager ()
1516@end
1617
1718@implementation RCTConvert (WKWebView )
@@ -35,10 +36,6 @@ @implementation RCTConvert (WKWebView)
3536@end
3637
3738@implementation RNCWebViewManager
38- {
39- NSConditionLock *_shouldStartLoadLock;
40- BOOL _shouldStartLoad;
41- }
4239
4340RCT_EXPORT_MODULE ()
4441
@@ -49,7 +46,6 @@ - (RCTUIView *)view
4946#endif // !TARGET_OS_OSX
5047{
5148 RNCWebView *webView = [RNCWebView new ];
52- webView.delegate = self;
5349 return webView;
5450}
5551
@@ -243,38 +239,11 @@ - (RCTUIView *)view
243239 }];
244240}
245241
246- #pragma mark - Exported synchronous methods
247-
248- - (BOOL ) webView : (RNCWebView *)webView
249- shouldStartLoadForRequest : (NSMutableDictionary <NSString *, id> *)request
250- withCallback : (RCTDirectEventBlock)callback
251- {
252- _shouldStartLoadLock = [[NSConditionLock alloc ] initWithCondition: arc4random ()];
253- _shouldStartLoad = YES ;
254- request[@" lockIdentifier" ] = @(_shouldStartLoadLock.condition );
255- callback (request);
256-
257- // Block the main thread for a maximum of 500ms until the JS thread returns
258- if ([_shouldStartLoadLock lockWhenCondition: 0 beforeDate: [NSDate dateWithTimeIntervalSinceNow: .50 ]]) {
259- BOOL returnValue = _shouldStartLoad;
260- [_shouldStartLoadLock unlock ];
261- _shouldStartLoadLock = nil ;
262- return returnValue;
263- } else {
264- RCTLogWarn (@" Did not receive response to shouldStartLoad in time, defaulting to NO" );
265- return NO ;
266- }
267- }
242+ #pragma mark - Exported methods
268243
269244RCT_EXPORT_METHOD (startLoadWithResult:(BOOL )result lockIdentifier:(NSInteger )lockIdentifier)
270245{
271- if ([_shouldStartLoadLock tryLockWhenCondition: lockIdentifier]) {
272- _shouldStartLoad = result;
273- [_shouldStartLoadLock unlockWithCondition: 0 ];
274- } else {
275- RCTLogWarn (@" startLoadWithResult invoked with invalid lockIdentifier: "
276- " got %lld , expected %lld " , (long long )lockIdentifier, (long long )_shouldStartLoadLock.condition );
277- }
246+ [[RNCWebViewDecisionManager getInstance ] setResult: result forLockIdentifier: (int )lockIdentifier];
278247}
279248
280249@end
0 commit comments