1#import "RNCWebViewDecisionManager.h" 2 3 4 5@implementation RNCWebViewDecisionManager 6 7@synthesize nextLockIdentifier; 8@synthesize decisionHandlers; 9 10+ (id)getInstance { 11 static RNCWebViewDecisionManager *lockManager = nil; 12 static dispatch_once_t onceToken; 13 dispatch_once(&onceToken, ^{ 14 lockManager = [[self alloc] init]; 15 }); 16 return lockManager; 17} 18 19- (int)setDecisionHandler:(DecisionBlock)decisionHandler { 20 int lockIdentifier = self.nextLockIdentifier++; 21 22 [self.decisionHandlers setObject:decisionHandler forKey:@(lockIdentifier)]; 23 return lockIdentifier; 24} 25 26- (void) setResult:(BOOL)shouldStart 27 forLockIdentifier:(int)lockIdentifier { 28 DecisionBlock handler = [self.decisionHandlers objectForKey:@(lockIdentifier)]; 29 if (handler == nil) { 30 RCTLogWarn(@"Lock not found"); 31 return; 32 } 33 handler(shouldStart); 34 [self.decisionHandlers removeObjectForKey:@(lockIdentifier)]; 35} 36 37- (id)init { 38 if (self = [super init]) { 39 self.nextLockIdentifier = 1; 40 self.decisionHandlers = [[NSMutableDictionary alloc] init]; 41 } 42 return self; 43} 44 45- (void)dealloc {} 46 47@end 48