Skip to content

Commit cb719a1

Browse files
Jayme Deffenbaughfacebook-github-bot
Jayme Deffenbaugh
authored andcommitted
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 <!-- 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
1 parent f5c246d commit cb719a1

12 files changed

+47
-54
lines changed

Libraries/Image/RCTImageLoaderProtocol.h

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#import <React/RCTImageURLLoader.h>
1515
#import <React/RCTImageCache.h>
1616

17+
NS_ASSUME_NONNULL_BEGIN
18+
1719
/**
1820
* If available, RCTImageRedirectProtocol is invoked before loading an asset.
1921
* Implementation should return either a new URL or nil when redirection is
@@ -132,3 +134,5 @@ typedef NS_ENUM(NSUInteger, RCTImageLoaderPriority) {
132134
- (void)setImageCache:(id<RCTImageCache>)cache;
133135

134136
@end
137+
138+
NS_ASSUME_NONNULL_END

Libraries/Image/RCTImageURLLoader.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#import <React/RCTBridge.h>
1111
#import <React/RCTResizeMode.h>
1212

13+
NS_ASSUME_NONNULL_BEGIN
14+
1315
typedef void (^RCTImageLoaderProgressBlock)(int64_t progress, int64_t total);
1416
typedef void (^RCTImageLoaderPartialLoadBlock)(UIImage *image);
15-
typedef void (^RCTImageLoaderCompletionBlock)(NSError *error, UIImage *image);
17+
typedef void (^RCTImageLoaderCompletionBlock)(NSError * _Nullable error, UIImage * _Nullable image);
1618
typedef dispatch_block_t RCTImageLoaderCancellationBlock;
1719

1820
/**
@@ -71,3 +73,5 @@ typedef dispatch_block_t RCTImageLoaderCancellationBlock;
7173
- (BOOL)shouldCacheLoadedImages;
7274

7375
@end
76+
77+
NS_ASSUME_NONNULL_END

React/Base/RCTBridge.m

+20-20
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,24 @@ - (void)setRCTTurboModuleRegistry:(id<RCTTurboModuleRegistry>)turboModuleRegistr
218218

219219
- (void)didReceiveReloadCommand
220220
{
221-
[self reloadWithReason:@"Command"];
221+
#if RCT_ENABLE_INSPECTOR
222+
// Disable debugger to resume the JsVM & avoid thread locks while reloading
223+
[RCTInspectorDevServerHelper disableDebugger];
224+
#endif
225+
226+
[[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeWillReloadNotification object:self userInfo:nil];
227+
228+
/**
229+
* Any thread
230+
*/
231+
dispatch_async(dispatch_get_main_queue(), ^{
232+
// WARNING: Invalidation is async, so it may not finish before re-setting up the bridge,
233+
// causing some issues. TODO: revisit this post-Fabric/TurboModule.
234+
[self invalidate];
235+
// Reload is a special case, do not preserve launchOptions and treat reload as a fresh start
236+
self->_launchOptions = nil;
237+
[self setUp];
238+
});
222239
}
223240

224241
- (NSArray<Class> *)moduleClasses
@@ -269,32 +286,15 @@ - (BOOL)moduleIsInitialized:(Class)moduleClass
269286
*/
270287
- (void)reload
271288
{
272-
[self reloadWithReason:@"Unknown from bridge"];
289+
RCTTriggerReloadCommandListeners(@"Unknown from bridge");
273290
}
274291

275292
/**
276293
* DEPRECATED - please use RCTReloadCommand.
277294
*/
278295
- (void)reloadWithReason:(NSString *)reason
279296
{
280-
#if RCT_ENABLE_INSPECTOR
281-
// Disable debugger to resume the JsVM & avoid thread locks while reloading
282-
[RCTInspectorDevServerHelper disableDebugger];
283-
#endif
284-
285-
[[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeWillReloadNotification object:self userInfo:nil];
286-
287-
/**
288-
* Any thread
289-
*/
290-
dispatch_async(dispatch_get_main_queue(), ^{
291-
// WARNING: Invalidation is async, so it may not finish before re-setting up the bridge,
292-
// causing some issues. TODO: revisit this post-Fabric/TurboModule.
293-
[self invalidate];
294-
// Reload is a special case, do not preserve launchOptions and treat reload as a fresh start
295-
self->_launchOptions = nil;
296-
[self setUp];
297-
});
297+
RCTTriggerReloadCommandListeners(reason);
298298
}
299299

300300
- (void)onFastRefresh

React/Base/RCTJSStackFrame.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
@property (nonatomic, copy, readonly) NSString *file;
1414
@property (nonatomic, readonly) NSInteger lineNumber;
1515
@property (nonatomic, readonly) NSInteger column;
16-
@property (nonatomic, readonly) NSInteger collapse;
16+
@property (nonatomic, readonly) BOOL collapse;
1717

1818
- (instancetype)initWithMethodName:(NSString *)methodName
1919
file:(NSString *)file
2020
lineNumber:(NSInteger)lineNumber
2121
column:(NSInteger)column
22-
collapse:(NSInteger)collapse;
22+
collapse:(BOOL)collapse;
2323
- (NSDictionary *)toDictionary;
2424

2525
+ (instancetype)stackFrameWithLine:(NSString *)line;

React/Base/RCTJSStackFrame.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ - (instancetype)initWithMethodName:(NSString *)methodName
5757
file:(NSString *)file
5858
lineNumber:(NSInteger)lineNumber
5959
column:(NSInteger)column
60-
collapse:(NSInteger)collapse
60+
collapse:(BOOL)collapse
6161
{
6262
if (self = [super init]) {
6363
_methodName = methodName;
@@ -100,7 +100,7 @@ + (instancetype)stackFrameWithLine:(NSString *)line
100100
file:file
101101
lineNumber:[lineNumber integerValue]
102102
column:[column integerValue]
103-
collapse:@NO];
103+
collapse:NO];
104104
}
105105

106106
+ (instancetype)stackFrameWithDictionary:(NSDictionary *)dict
@@ -109,7 +109,7 @@ + (instancetype)stackFrameWithDictionary:(NSDictionary *)dict
109109
file:dict[@"file"]
110110
lineNumber:[RCTNilIfNull(dict[@"lineNumber"]) integerValue]
111111
column:[RCTNilIfNull(dict[@"column"]) integerValue]
112-
collapse:[RCTNilIfNull(dict[@"collapse"]) integerValue]];
112+
collapse:[RCTNilIfNull(dict[@"collapse"]) boolValue]];
113113
}
114114

115115
+ (NSArray<RCTJSStackFrame *> *)stackFramesWithLines:(NSString *)lines

React/Base/RCTKeyCommands.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ + (void)initialize
113113
- (void)handleKeyUIEventSwizzle:(UIEvent *)event
114114
{
115115
NSString *modifiedInput = nil;
116-
UIKeyModifierFlags *modifierFlags = nil;
116+
UIKeyModifierFlags modifierFlags = 0;
117117
BOOL isKeyDown = NO;
118118

119119
if ([event respondsToSelector:@selector(_modifiedInput)]) {

React/Base/RCTModuleData.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ typedef id<RCTBridgeModule> (^RCTBridgeModuleProvider)(void);
9797
@end
9898

9999
RCT_EXTERN void RCTSetIsMainQueueExecutionOfConstantsToExportDisabled(BOOL val);
100-
RCT_EXTERN BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled();
100+
RCT_EXTERN BOOL RCTIsMainQueueExecutionOfConstantsToExportDisabled(void);

React/CxxBridge/RCTCxxBridge.mm

-20
Original file line numberDiff line numberDiff line change
@@ -1119,26 +1119,6 @@ - (void)setUp
11191119
{
11201120
}
11211121

1122-
- (void)reload
1123-
{
1124-
if (!_valid) {
1125-
RCTLogWarn(
1126-
@"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.",
1127-
self);
1128-
}
1129-
RCTTriggerReloadCommandListeners(@"Unknown from cxx bridge");
1130-
}
1131-
1132-
- (void)reloadWithReason:(NSString *)reason
1133-
{
1134-
if (!_valid) {
1135-
RCTLogWarn(
1136-
@"Attempting to reload bridge before it's valid: %@. Try restarting the development server if connected.",
1137-
self);
1138-
}
1139-
RCTTriggerReloadCommandListeners(reason);
1140-
}
1141-
11421122
- (Class)executorClass
11431123
{
11441124
return _parentBridge.executorClass;

React/Modules/RCTUIManagerUtils.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#import "RCTUIManagerUtils.h"
99

10-
#import <libkern/OSAtomic.h>
10+
#import <stdatomic.h>
1111

1212
#import "RCTAssert.h"
1313

@@ -98,6 +98,6 @@ void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block)
9898
NSNumber *RCTAllocateRootViewTag()
9999
{
100100
// Numbering of these tags goes from 1, 11, 21, 31, ..., 100501, ...
101-
static int64_t rootViewTagCounter = -1;
102-
return @(OSAtomicIncrement64(&rootViewTagCounter) * 10 + 1);
101+
static _Atomic int64_t rootViewTagCounter = 0;
102+
return @(atomic_fetch_add_explicit(&rootViewTagCounter, 1, memory_order_relaxed) * 10 + 1);
103103
}

React/Profiler/RCTProfile.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "RCTDefines.h"
2323
#import "RCTLog.h"
2424
#import "RCTModuleData.h"
25+
#import "RCTReloadCommand.h"
2526
#import "RCTUIManager.h"
2627
#import "RCTUIManagerUtils.h"
2728
#import "RCTUtils.h"
@@ -378,7 +379,7 @@ + (void)vsync:(CADisplayLink *)displayLink
378379

379380
+ (void)reload
380381
{
381-
[RCTProfilingBridge() reloadWithReason:@"Profiling controls"];
382+
RCTTriggerReloadCommandListeners(@"Profiling controls");
382383
}
383384

384385
+ (void)toggle:(UIButton *)target

React/Views/RCTComponentData.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
@class RCTShadowView;
1616
@class UIView;
1717

18+
NS_ASSUME_NONNULL_BEGIN
19+
1820
@interface RCTComponentData : NSObject
1921

2022
@property (nonatomic, readonly) Class managerClass;
@@ -23,7 +25,7 @@
2325

2426
- (instancetype)initWithManagerClass:(Class)managerClass bridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
2527

26-
- (UIView *)createViewWithTag:(NSNumber *)tag rootTag:(NSNumber *)rootTag;
28+
- (UIView *)createViewWithTag:(nullable NSNumber *)tag rootTag:(nullable NSNumber *)rootTag;
2729
- (RCTShadowView *)createShadowViewWithTag:(NSNumber *)tag;
2830
- (void)setProps:(NSDictionary<NSString *, id> *)props forView:(id<RCTComponent>)view;
2931
- (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowView *)shadowView;
@@ -34,3 +36,5 @@
3436
- (NSDictionary<NSString *, id> *)viewConfig;
3537

3638
@end
39+
40+
NS_ASSUME_NONNULL_END

React/Views/RCTComponentData.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ - (RCTViewManager *)manager
6363

6464
RCT_NOT_IMPLEMENTED(-(instancetype)init)
6565

66-
- (UIView *)createViewWithTag:(NSNumber *)tag rootTag:(NSNumber *)rootTag
66+
- (UIView *)createViewWithTag:(nullable NSNumber *)tag rootTag:(nullable NSNumber *)rootTag
6767
{
6868
RCTAssertMainQueue();
6969

0 commit comments

Comments
 (0)