Skip to content

Commit

Permalink
Fix Xcode warnings in React-Core pod (#29622)
Browse files Browse the repository at this point in the history
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

<!-- Help reviewers and the release process by writing your own changelog entry. For example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Fixed] - Fix xcodebuild warnings in React-Core

Pull Request resolved: #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
  • Loading branch information
Jayme Deffenbaugh authored and facebook-github-bot committed Sep 9, 2020
1 parent f5c246d commit cb719a1
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 54 deletions.
4 changes: 4 additions & 0 deletions Libraries/Image/RCTImageLoaderProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#import <React/RCTImageURLLoader.h>
#import <React/RCTImageCache.h>

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
Expand Down Expand Up @@ -132,3 +134,5 @@ typedef NS_ENUM(NSUInteger, RCTImageLoaderPriority) {
- (void)setImageCache:(id<RCTImageCache>)cache;

@end

NS_ASSUME_NONNULL_END
6 changes: 5 additions & 1 deletion Libraries/Image/RCTImageURLLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#import <React/RCTBridge.h>
#import <React/RCTResizeMode.h>

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;

/**
Expand Down Expand Up @@ -71,3 +73,5 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
- (BOOL)shouldCacheLoadedImages;

@end

NS_ASSUME_NONNULL_END
40 changes: 20 additions & 20 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,24 @@ - (void)setRCTTurboModuleRegistry:(id<RCTTurboModuleRegistry>)turboModuleRegistr

- (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<Class> *)moduleClasses
Expand Down Expand Up @@ -269,32 +286,15 @@ - (BOOL)moduleIsInitialized:(Class)moduleClass
*/
- (void)reload
{
[self reloadWithReason:@"Unknown from bridge"];
RCTTriggerReloadCommandListeners(@"Unknown from bridge");
}

/**
* DEPRECATED - please use RCTReloadCommand.
*/
- (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
Expand Down
4 changes: 2 additions & 2 deletions React/Base/RCTJSStackFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions React/Base/RCTJSStackFrame.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ - (instancetype)initWithMethodName:(NSString *)methodName
file:(NSString *)file
lineNumber:(NSInteger)lineNumber
column:(NSInteger)column
collapse:(NSInteger)collapse
collapse:(BOOL)collapse
{
if (self = [super init]) {
_methodName = methodName;
Expand Down Expand Up @@ -100,7 +100,7 @@ + (instancetype)stackFrameWithLine:(NSString *)line
file:file
lineNumber:[lineNumber integerValue]
column:[column integerValue]
collapse:@NO];
collapse:NO];
}

+ (instancetype)stackFrameWithDictionary:(NSDictionary *)dict
Expand All @@ -109,7 +109,7 @@ + (instancetype)stackFrameWithDictionary:(NSDictionary *)dict
file:dict[@"file"]
lineNumber:[RCTNilIfNull(dict[@"lineNumber"]) integerValue]
column:[RCTNilIfNull(dict[@"column"]) integerValue]
collapse:[RCTNilIfNull(dict[@"collapse"]) integerValue]];
collapse:[RCTNilIfNull(dict[@"collapse"]) boolValue]];
}

+ (NSArray<RCTJSStackFrame *> *)stackFramesWithLines:(NSString *)lines
Expand Down
2 changes: 1 addition & 1 deletion React/Base/RCTKeyCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ + (void)initialize
- (void)handleKeyUIEventSwizzle:(UIEvent *)event
{
NSString *modifiedInput = nil;
UIKeyModifierFlags *modifierFlags = nil;
UIKeyModifierFlags modifierFlags = 0;
BOOL isKeyDown = NO;

if ([event respondsToSelector:@selector(_modifiedInput)]) {
Expand Down
2 changes: 1 addition & 1 deletion React/Base/RCTModuleData.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ typedef id<RCTBridgeModule> (^RCTBridgeModuleProvider)(void);
@end

RCT_EXTERN void RCTSetIsMainQueueExecutionOfConstantsToExportDisabled(BOOL val);
RCT_EXTERN BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled();
RCT_EXTERN BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled(void);
20 changes: 0 additions & 20 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1119,26 +1119,6 @@ - (void)setUp
{
}

- (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;
Expand Down
6 changes: 3 additions & 3 deletions React/Modules/RCTUIManagerUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import "RCTUIManagerUtils.h"

#import <libkern/OSAtomic.h>
#import <stdatomic.h>

#import "RCTAssert.h"

Expand Down Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion React/Profiler/RCTProfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -378,7 +379,7 @@ + (void)vsync:(CADisplayLink *)displayLink

+ (void)reload
{
[RCTProfilingBridge() reloadWithReason:@"Profiling controls"];
RCTTriggerReloadCommandListeners(@"Profiling controls");
}

+ (void)toggle:(UIButton *)target
Expand Down
6 changes: 5 additions & 1 deletion React/Views/RCTComponentData.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@class RCTShadowView;
@class UIView;

NS_ASSUME_NONNULL_BEGIN

@interface RCTComponentData : NSObject

@property (nonatomic, readonly) Class managerClass;
Expand All @@ -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<NSString *, id> *)props forView:(id<RCTComponent>)view;
- (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowView *)shadowView;
Expand All @@ -34,3 +36,5 @@
- (NSDictionary<NSString *, id> *)viewConfig;

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion React/Views/RCTComponentData.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ - (RCTViewManager *)manager

RCT_NOT_IMPLEMENTED(-(instancetype)init)

- (UIView *)createViewWithTag:(NSNumber *)tag rootTag:(NSNumber *)rootTag
- (UIView *)createViewWithTag:(nullable NSNumber *)tag rootTag:(nullable NSNumber *)rootTag
{
RCTAssertMainQueue();

Expand Down

0 comments on commit cb719a1

Please sign in to comment.