diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m index c3a626552..7e91ae015 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTAllocationTests.m @@ -42,15 +42,16 @@ _Pragma("clang diagnostic pop") @end @interface AllocationTestModule : NSObject + +@property (nonatomic, assign, getter=isValid) BOOL valid; + @end @implementation AllocationTestModule RCT_EXPORT_MODULE(); -@synthesize valid = _valid; - -- (id)init +- (instancetype)init { if ((self = [super init])) { _valid = YES; diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index 108b80cca..7af103b31 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -62,6 +62,7 @@ id RCTGetLatestExecutor(void) @implementation RCTBatchedBridge { BOOL _loading; + BOOL _valid; __weak id _javaScriptExecutor; NSMutableArray *_moduleDataByID; RCTModuleMap *_modulesByName; @@ -72,8 +73,6 @@ id RCTGetLatestExecutor(void) RCTSparseArray *_scheduledCallbacks; } -@synthesize valid = _valid; - - (instancetype)initWithParentBridge:(RCTBridge *)bridge { RCTAssertMainThread(); diff --git a/React/Base/RCTBridge.h b/React/Base/RCTBridge.h index dce1c1f5f..88bcf8971 100644 --- a/React/Base/RCTBridge.h +++ b/React/Base/RCTBridge.h @@ -145,6 +145,11 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass); */ @property (nonatomic, readonly, getter=isLoading) BOOL loading; +/** + * Use this to check if the bridge has been invalidated. + */ +@property (nonatomic, readonly, getter=isValid) BOOL valid; + /** * The block passed in the constructor with pre-initialized modules */ diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index de6caaf70..fd06342b3 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -244,11 +244,6 @@ RCT_NOT_IMPLEMENTED(-init) return _batchedBridge.loading; } -- (BOOL)isValid -{ - return _batchedBridge.isValid; -} - - (void)invalidate { RCTAssertMainThread(); @@ -260,7 +255,7 @@ RCT_NOT_IMPLEMENTED(-init) + (void)logMessage:(NSString *)message level:(NSString *)level { dispatch_async(dispatch_get_main_queue(), ^{ - if (!RCTGetLatestExecutor().isValid) { + if (![RCTGetLatestExecutor() isValid]) { return; } diff --git a/React/Base/RCTInvalidating.h b/React/Base/RCTInvalidating.h index e961a3979..1c8cf7920 100644 --- a/React/Base/RCTInvalidating.h +++ b/React/Base/RCTInvalidating.h @@ -9,13 +9,8 @@ #import -// TODO (#5906496): This protocol is only used to add method definitions to -// classes. We should decide if it's actually necessary. - @protocol RCTInvalidating -@property (nonatomic, assign, readonly, getter = isValid) BOOL valid; - - (void)invalidate; @end diff --git a/React/Base/RCTJavaScriptExecutor.h b/React/Base/RCTJavaScriptExecutor.h index af4b4cef6..87d4dda78 100644 --- a/React/Base/RCTJavaScriptExecutor.h +++ b/React/Base/RCTJavaScriptExecutor.h @@ -29,6 +29,11 @@ typedef void (^RCTJavaScriptCallback)(id json, NSError *error); */ - (void)setUp; +/** + * Whether the executor has been invalidated + */ +@property (nonatomic, readonly, getter=isValid) BOOL valid; + /** * Executes given method with arguments on JS thread and calls the given callback * with JSValue and JSContext as a result of the JS module call. diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 0cdd1b78c..a804c810b 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -292,14 +292,9 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder) [_bridge.uiManager registerRootView:self]; } -- (BOOL)isValid -{ - return self.userInteractionEnabled; -} - - (void)invalidate { - if (self.isValid) { + if (self.userInteractionEnabled) { self.userInteractionEnabled = NO; [(RCTRootView *)self.superview contentViewInvalidated]; [_bridge enqueueJSCall:@"ReactNative.unmountComponentAtNodeAndRemoveContainer" diff --git a/React/Modules/RCTAsyncLocalStorage.h b/React/Modules/RCTAsyncLocalStorage.h index 4fd1064ad..e7e871b02 100644 --- a/React/Modules/RCTAsyncLocalStorage.h +++ b/React/Modules/RCTAsyncLocalStorage.h @@ -25,6 +25,8 @@ @property (nonatomic, assign) BOOL clearOnInvalidate; +@property (nonatomic, readonly, getter=isValid) BOOL valid; + - (void)multiGet:(NSArray *)keys callback:(RCTResponseSenderBlock)callback; - (void)multiSet:(NSArray *)kvPairs callback:(RCTResponseSenderBlock)callback; - (void)multiRemove:(NSArray *)keys callback:(RCTResponseSenderBlock)callback; diff --git a/React/Modules/RCTAsyncLocalStorage.m b/React/Modules/RCTAsyncLocalStorage.m index 8300cc869..923a3a14a 100644 --- a/React/Modules/RCTAsyncLocalStorage.m +++ b/React/Modules/RCTAsyncLocalStorage.m @@ -164,6 +164,7 @@ RCT_EXPORT_MODULE() _manifest = [[NSMutableDictionary alloc] init]; _haveSetup = NO; } + - (BOOL)isValid { return _haveSetup; diff --git a/React/Modules/RCTDevMenu.h b/React/Modules/RCTDevMenu.h index ed1ff90b8..13ddb0689 100644 --- a/React/Modules/RCTDevMenu.h +++ b/React/Modules/RCTDevMenu.h @@ -11,7 +11,6 @@ #import "RCTBridge.h" #import "RCTBridgeModule.h" -#import "RCTInvalidating.h" /** * Developer menu, useful for exposing extra functionality when debugging. diff --git a/React/Modules/RCTDevMenu.m b/React/Modules/RCTDevMenu.m index e8762a62d..32f3946b1 100644 --- a/React/Modules/RCTDevMenu.m +++ b/React/Modules/RCTDevMenu.m @@ -223,11 +223,6 @@ RCT_EXPORT_MODULE() }); } -- (BOOL)isValid -{ - return NO; -} - - (void)dealloc { [_updateTask cancel]; diff --git a/React/Modules/RCTTiming.m b/React/Modules/RCTTiming.m index 29e3b3f92..a776c58dc 100644 --- a/React/Modules/RCTTiming.m +++ b/React/Modules/RCTTiming.m @@ -112,11 +112,6 @@ RCT_EXPORT_MODULE() return RCTJSThread; } -- (BOOL)isValid -{ - return _bridge != nil; -} - - (void)invalidate { [self stopTimers]; @@ -130,7 +125,7 @@ RCT_EXPORT_MODULE() - (void)startTimers { - if (![self isValid] || _timers.count == 0) { + if (!_bridge || _timers.count == 0) { return; } diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 0a8ac410c..19d478284 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -253,11 +253,6 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); }); } -- (BOOL)isValid -{ - return _viewRegistry != nil; -} - - (void)invalidate { /** @@ -325,7 +320,7 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); __weak RCTUIManager *weakSelf = self; dispatch_async(_shadowQueue, ^{ RCTUIManager *strongSelf = weakSelf; - if (!strongSelf.isValid) { + if (!_viewRegistry) { return; } RCTShadowView *shadowView = [[RCTShadowView alloc] init]; @@ -369,7 +364,7 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); __weak RCTUIManager *weakSelf = self; dispatch_async(_shadowQueue, ^{ RCTUIManager *strongSelf = weakSelf; - if (!strongSelf.isValid) { + if (!_viewRegistry) { return; } RCTShadowView *rootShadowView = strongSelf->_shadowViewRegistry[reactTag]; @@ -410,14 +405,14 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); return; } - if (!self.isValid) { + if (!_viewRegistry) { return; } __weak RCTUIManager *weakViewManager = self; dispatch_block_t outerBlock = ^{ RCTUIManager *strongViewManager = weakViewManager; - if (strongViewManager && strongViewManager.isValid) { + if (strongViewManager && strongViewManager->_viewRegistry) { block(strongViewManager, strongViewManager->_viewRegistry); } }; diff --git a/React/Views/RCTNavigator.h b/React/Views/RCTNavigator.h index c59c9a3d3..a1905a87d 100644 --- a/React/Views/RCTNavigator.h +++ b/React/Views/RCTNavigator.h @@ -10,7 +10,6 @@ #import #import "RCTFrameUpdate.h" -#import "RCTInvalidating.h" @class RCTBridge;