From cb719a16cc496b0cdb09d8d971b5e95cc8863b77 Mon Sep 17 00:00:00 2001 From: Jayme Deffenbaugh Date: Wed, 9 Sep 2020 12:45:38 -0700 Subject: [PATCH] Fix Xcode warnings in React-Core pod (#29622) Summary: With the upgrade to React Native 0.63, we started running into nullability warnings that were breaking our build. This PR fixes those nullability warnings as well as a few other warnings in React-Core. ## Changelog [iOS] [Fixed] - Fix xcodebuild warnings in React-Core Pull Request resolved: https://github.com/facebook/react-native/pull/29622 Test Plan: - Nullability annotations should only affect compilation, but even though RNTester compiles, I'm not fully convinced that this won't break projects downstream. It would be good to get another opinion on this. - The change in `RCTAllocateRootViewTag` is the only real logic change in this PR. We throw an exception if the root view tag is not in the correct format, so this change seems safe after some basic manual testing in RNTester. Reviewed By: shergin Differential Revision: D23386678 Pulled By: appden fbshipit-source-id: a74875195a4614c3248e8f968aa98602e3ee2de0 --- Libraries/Image/RCTImageLoaderProtocol.h | 4 +++ Libraries/Image/RCTImageURLLoader.h | 6 +++- React/Base/RCTBridge.m | 40 ++++++++++++------------ React/Base/RCTJSStackFrame.h | 4 +-- React/Base/RCTJSStackFrame.m | 6 ++-- React/Base/RCTKeyCommands.m | 2 +- React/Base/RCTModuleData.h | 2 +- React/CxxBridge/RCTCxxBridge.mm | 20 ------------ React/Modules/RCTUIManagerUtils.m | 6 ++-- React/Profiler/RCTProfile.m | 3 +- React/Views/RCTComponentData.h | 6 +++- React/Views/RCTComponentData.m | 2 +- 12 files changed, 47 insertions(+), 54 deletions(-) diff --git a/Libraries/Image/RCTImageLoaderProtocol.h b/Libraries/Image/RCTImageLoaderProtocol.h index 366fb7b57ce..f1bb2689607 100644 --- a/Libraries/Image/RCTImageLoaderProtocol.h +++ b/Libraries/Image/RCTImageLoaderProtocol.h @@ -14,6 +14,8 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + /** * If available, RCTImageRedirectProtocol is invoked before loading an asset. * Implementation should return either a new URL or nil when redirection is @@ -132,3 +134,5 @@ typedef NS_ENUM(NSUInteger, RCTImageLoaderPriority) { - (void)setImageCache:(id)cache; @end + +NS_ASSUME_NONNULL_END diff --git a/Libraries/Image/RCTImageURLLoader.h b/Libraries/Image/RCTImageURLLoader.h index d950b46f745..866ae9ada61 100644 --- a/Libraries/Image/RCTImageURLLoader.h +++ b/Libraries/Image/RCTImageURLLoader.h @@ -10,9 +10,11 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + typedef void (^RCTImageLoaderProgressBlock)(int64_t progress, int64_t total); typedef void (^RCTImageLoaderPartialLoadBlock)(UIImage *image); -typedef void (^RCTImageLoaderCompletionBlock)(NSError *error, UIImage *image); +typedef void (^RCTImageLoaderCompletionBlock)(NSError * _Nullable error, UIImage * _Nullable image); typedef dispatch_block_t RCTImageLoaderCancellationBlock; /** @@ -71,3 +73,5 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock; - (BOOL)shouldCacheLoadedImages; @end + +NS_ASSUME_NONNULL_END diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 4c5bc035c03..8cca1a00b9d 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -218,7 +218,24 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) - (void)didReceiveReloadCommand { - [self reloadWithReason:@"Command"]; +#if RCT_ENABLE_INSPECTOR + // Disable debugger to resume the JsVM & avoid thread locks while reloading + [RCTInspectorDevServerHelper disableDebugger]; +#endif + + [[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeWillReloadNotification object:self userInfo:nil]; + + /** + * Any thread + */ + dispatch_async(dispatch_get_main_queue(), ^{ + // WARNING: Invalidation is async, so it may not finish before re-setting up the bridge, + // causing some issues. TODO: revisit this post-Fabric/TurboModule. + [self invalidate]; + // Reload is a special case, do not preserve launchOptions and treat reload as a fresh start + self->_launchOptions = nil; + [self setUp]; + }); } - (NSArray *)moduleClasses @@ -269,7 +286,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) */ - (void)reload { - [self reloadWithReason:@"Unknown from bridge"]; + RCTTriggerReloadCommandListeners(@"Unknown from bridge"); } /** @@ -277,24 +294,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) */ - (void)reloadWithReason:(NSString *)reason { -#if RCT_ENABLE_INSPECTOR - // Disable debugger to resume the JsVM & avoid thread locks while reloading - [RCTInspectorDevServerHelper disableDebugger]; -#endif - - [[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeWillReloadNotification object:self userInfo:nil]; - - /** - * Any thread - */ - dispatch_async(dispatch_get_main_queue(), ^{ - // WARNING: Invalidation is async, so it may not finish before re-setting up the bridge, - // causing some issues. TODO: revisit this post-Fabric/TurboModule. - [self invalidate]; - // Reload is a special case, do not preserve launchOptions and treat reload as a fresh start - self->_launchOptions = nil; - [self setUp]; - }); + RCTTriggerReloadCommandListeners(reason); } - (void)onFastRefresh diff --git a/React/Base/RCTJSStackFrame.h b/React/Base/RCTJSStackFrame.h index 43592ec18d0..1a66e29e587 100644 --- a/React/Base/RCTJSStackFrame.h +++ b/React/Base/RCTJSStackFrame.h @@ -13,13 +13,13 @@ @property (nonatomic, copy, readonly) NSString *file; @property (nonatomic, readonly) NSInteger lineNumber; @property (nonatomic, readonly) NSInteger column; -@property (nonatomic, readonly) NSInteger collapse; +@property (nonatomic, readonly) BOOL collapse; - (instancetype)initWithMethodName:(NSString *)methodName file:(NSString *)file lineNumber:(NSInteger)lineNumber column:(NSInteger)column - collapse:(NSInteger)collapse; + collapse:(BOOL)collapse; - (NSDictionary *)toDictionary; + (instancetype)stackFrameWithLine:(NSString *)line; diff --git a/React/Base/RCTJSStackFrame.m b/React/Base/RCTJSStackFrame.m index 2458626f349..1e3d5498eaf 100644 --- a/React/Base/RCTJSStackFrame.m +++ b/React/Base/RCTJSStackFrame.m @@ -57,7 +57,7 @@ static NSRegularExpression *RCTJSStackFrameRegex() file:(NSString *)file lineNumber:(NSInteger)lineNumber column:(NSInteger)column - collapse:(NSInteger)collapse + collapse:(BOOL)collapse { if (self = [super init]) { _methodName = methodName; @@ -100,7 +100,7 @@ static NSRegularExpression *RCTJSStackFrameRegex() file:file lineNumber:[lineNumber integerValue] column:[column integerValue] - collapse:@NO]; + collapse:NO]; } + (instancetype)stackFrameWithDictionary:(NSDictionary *)dict @@ -109,7 +109,7 @@ static NSRegularExpression *RCTJSStackFrameRegex() file:dict[@"file"] lineNumber:[RCTNilIfNull(dict[@"lineNumber"]) integerValue] column:[RCTNilIfNull(dict[@"column"]) integerValue] - collapse:[RCTNilIfNull(dict[@"collapse"]) integerValue]]; + collapse:[RCTNilIfNull(dict[@"collapse"]) boolValue]]; } + (NSArray *)stackFramesWithLines:(NSString *)lines diff --git a/React/Base/RCTKeyCommands.m b/React/Base/RCTKeyCommands.m index 220a8b321f0..7e4ccb2a6a1 100644 --- a/React/Base/RCTKeyCommands.m +++ b/React/Base/RCTKeyCommands.m @@ -113,7 +113,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)init) - (void)handleKeyUIEventSwizzle:(UIEvent *)event { NSString *modifiedInput = nil; - UIKeyModifierFlags *modifierFlags = nil; + UIKeyModifierFlags modifierFlags = 0; BOOL isKeyDown = NO; if ([event respondsToSelector:@selector(_modifiedInput)]) { diff --git a/React/Base/RCTModuleData.h b/React/Base/RCTModuleData.h index 04d6271eeed..5ff81532eb3 100644 --- a/React/Base/RCTModuleData.h +++ b/React/Base/RCTModuleData.h @@ -97,4 +97,4 @@ typedef id (^RCTBridgeModuleProvider)(void); @end RCT_EXTERN void RCTSetIsMainQueueExecutionOfConstantsToExportDisabled(BOOL val); -RCT_EXTERN BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled(); +RCT_EXTERN BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled(void); diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 171005a4f02..594b1cbeec6 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -1119,26 +1119,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithBundleURL { } -- (void)reload -{ - if (!_valid) { - RCTLogWarn( - @"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.", - self); - } - RCTTriggerReloadCommandListeners(@"Unknown from cxx bridge"); -} - -- (void)reloadWithReason:(NSString *)reason -{ - if (!_valid) { - RCTLogWarn( - @"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.", - self); - } - RCTTriggerReloadCommandListeners(reason); -} - - (Class)executorClass { return _parentBridge.executorClass; diff --git a/React/Modules/RCTUIManagerUtils.m b/React/Modules/RCTUIManagerUtils.m index 54f77f67a6e..7b19bf2cf35 100644 --- a/React/Modules/RCTUIManagerUtils.m +++ b/React/Modules/RCTUIManagerUtils.m @@ -7,7 +7,7 @@ #import "RCTUIManagerUtils.h" -#import +#import #import "RCTAssert.h" @@ -98,6 +98,6 @@ void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block) NSNumber *RCTAllocateRootViewTag() { // Numbering of these tags goes from 1, 11, 21, 31, ..., 100501, ... - static int64_t rootViewTagCounter = -1; - return @(OSAtomicIncrement64(&rootViewTagCounter) * 10 + 1); + static _Atomic int64_t rootViewTagCounter = 0; + return @(atomic_fetch_add_explicit(&rootViewTagCounter, 1, memory_order_relaxed) * 10 + 1); } diff --git a/React/Profiler/RCTProfile.m b/React/Profiler/RCTProfile.m index 12d42000e3c..149451ad6bf 100644 --- a/React/Profiler/RCTProfile.m +++ b/React/Profiler/RCTProfile.m @@ -22,6 +22,7 @@ #import "RCTDefines.h" #import "RCTLog.h" #import "RCTModuleData.h" +#import "RCTReloadCommand.h" #import "RCTUIManager.h" #import "RCTUIManagerUtils.h" #import "RCTUtils.h" @@ -378,7 +379,7 @@ void RCTProfileUnhookModules(RCTBridge *bridge) + (void)reload { - [RCTProfilingBridge() reloadWithReason:@"Profiling controls"]; + RCTTriggerReloadCommandListeners(@"Profiling controls"); } + (void)toggle:(UIButton *)target diff --git a/React/Views/RCTComponentData.h b/React/Views/RCTComponentData.h index b61dc4011e1..614ca5f0f94 100644 --- a/React/Views/RCTComponentData.h +++ b/React/Views/RCTComponentData.h @@ -15,6 +15,8 @@ @class RCTShadowView; @class UIView; +NS_ASSUME_NONNULL_BEGIN + @interface RCTComponentData : NSObject @property (nonatomic, readonly) Class managerClass; @@ -23,7 +25,7 @@ - (instancetype)initWithManagerClass:(Class)managerClass bridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER; -- (UIView *)createViewWithTag:(NSNumber *)tag rootTag:(NSNumber *)rootTag; +- (UIView *)createViewWithTag:(nullable NSNumber *)tag rootTag:(nullable NSNumber *)rootTag; - (RCTShadowView *)createShadowViewWithTag:(NSNumber *)tag; - (void)setProps:(NSDictionary *)props forView:(id)view; - (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowView *)shadowView; @@ -34,3 +36,5 @@ - (NSDictionary *)viewConfig; @end + +NS_ASSUME_NONNULL_END diff --git a/React/Views/RCTComponentData.m b/React/Views/RCTComponentData.m index f4ecbb1b042..c8c893863e2 100644 --- a/React/Views/RCTComponentData.m +++ b/React/Views/RCTComponentData.m @@ -63,7 +63,7 @@ static SEL selectorForType(NSString *type) RCT_NOT_IMPLEMENTED(-(instancetype)init) -- (UIView *)createViewWithTag:(NSNumber *)tag rootTag:(NSNumber *)rootTag +- (UIView *)createViewWithTag:(nullable NSNumber *)tag rootTag:(nullable NSNumber *)rootTag { RCTAssertMainQueue();