Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Xcode warnings in React-Core pod #29622

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
jdeff marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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
42 changes: 22 additions & 20 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,26 @@ - (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 @@ -258,32 +277,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;
jdeff marked this conversation as resolved.
Show resolved Hide resolved
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);
jdeff marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDelay;
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration;

- (instancetype)initWithSurface:(RCTSurface *)surface
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode NS_UNAVAILABLE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdeff Sorry, I had to remove this one before merging because it caused issues with Facebook's internal builds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@appden Can you share details about the build failure?


- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
Expand Down
20 changes: 0 additions & 20 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1105,26 +1105,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);
jdeff marked this conversation as resolved.
Show resolved Hide resolved
static _Atomic int64_t rootViewTagCounter = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs:

Atomically replaces the value pointed by obj with the result of addition of arg to the old value of obj, and returns the value obj held previously.

So that’s why this should initialise with 0 instead of -1, like previously was the case.

Do you know if there are tests that cover this API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know of any tests per se, but the RNTester app crashed immediately when this was initialized to -1.

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