Skip to content

Commit

Permalink
Fix up designated initializers 8/x (#47316)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #47316

Pull Request resolved: #47300

In preparation of enabling `-Wobjc-designated-initializers` error

## Changelog:

[iOS][Fixed] - Fix numerous class interfaces having incorrect designated initializer patterns

Reviewed By: caodoan

Differential Revision: D65180118

fbshipit-source-id: 6f977816ede0397225ec681a5357241c28e83f6c
  • Loading branch information
Nolan O'Brien authored and facebook-github-bot committed Oct 31, 2024
1 parent 13b93cf commit b98846c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 34 deletions.
3 changes: 3 additions & 0 deletions packages/react-native/React/Base/RCTBridgeProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ NS_ASSUME_NONNULL_BEGIN

@interface RCTBridgeProxy : NSProxy

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
bundleManager:(RCTBundleManager *)bundleManager
Expand Down
10 changes: 10 additions & 0 deletions packages/react-native/React/Base/RCTBridgeProxy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ @implementation RCTBridgeProxy {
void *_runtime;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
bundleManager:(RCTBundleManager *)bundleManager
Expand All @@ -61,8 +63,10 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
_runtime = runtime;
_launchOptions = [launchOptions copy];
}

return self;
}
#pragma clang diagnostic pop

- (void)dispatchBlock:(dispatch_block_t)block queue:(dispatch_queue_t)queue
{
Expand Down Expand Up @@ -414,6 +418,10 @@ @implementation RCTUIManagerProxy {
RCTViewRegistry *_viewRegistry;
NSMutableDictionary<NSNumber *, UIView *> *_legacyViewRegistry;
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"

- (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
{
self = [super self];
Expand All @@ -424,6 +432,8 @@ - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry
return self;
}

#pragma clang diagnostic pop

/**
* RCTViewRegistry
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native/React/Base/RCTCallInvoker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ @implementation RCTCallInvoker {
std::shared_ptr<facebook::react::CallInvoker> _callInvoker;
}

- (instancetype)init
{
return [self initWithCallInvoker:nullptr];
}

- (instancetype)initWithCallInvoker:(std::shared_ptr<facebook::react::CallInvoker>)callInvoker
{
if (self = [super init]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Base/RCTModuleData.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef id<RCTBridgeModule> (^RCTBridgeModuleProvider)(void);
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
viewRegistry_DEPRECATED:(RCTViewRegistry *)viewRegistry_DEPRECATED
bundleManager:(RCTBundleManager *)bundleManager
callableJSModules:(RCTCallableJSModules *)callableJSModules;
callableJSModules:(RCTCallableJSModules *)callableJSModules NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithModuleInstance:(id<RCTBridgeModule>)instance
bridge:(RCTBridge *)bridge
Expand Down
60 changes: 27 additions & 33 deletions packages/react-native/React/Base/RCTModuleData.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,21 @@ @implementation RCTModuleData {
@synthesize instance = _instance;
@synthesize methodQueue = _methodQueue;

- (void)setUp
- (void)_setUpWithBridge:(RCTBridge *)bridge
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
viewRegistry_DEPRECATED:(RCTViewRegistry *)viewRegistry_DEPRECATED
bundleManager:(RCTBundleManager *)bundleManager
callableJSModules:(RCTCallableJSModules *)callableJSModules
{
// start with the ivars
{
_bridge = bridge;
_moduleRegistry = moduleRegistry;
_viewRegistry_DEPRECATED = viewRegistry_DEPRECATED;
_bundleManager = bundleManager;
_callableJSModules = callableJSModules;
}

_implementsBatchDidComplete = [_moduleClass instancesRespondToSelector:@selector(batchDidComplete)];

// If a module overrides `constantsToExport` and doesn't implement `requiresMainQueueSetup`, then we must assume
Expand Down Expand Up @@ -86,35 +99,17 @@ - (instancetype)initWithModuleClass:(Class)moduleClass
viewRegistry_DEPRECATED:(RCTViewRegistry *)viewRegistry_DEPRECATED
bundleManager:(RCTBundleManager *)bundleManager
callableJSModules:(RCTCallableJSModules *)callableJSModules
{
return [self _initWithModuleClass:moduleClass
moduleProvider:^id<RCTBridgeModule> {
return [moduleClass new];
}
bridge:bridge
moduleRegistry:moduleRegistry
viewRegistry_DEPRECATED:viewRegistry_DEPRECATED
bundleManager:bundleManager
callableJSModules:callableJSModules];
}

- (instancetype)_initWithModuleClass:(Class)moduleClass
moduleProvider:(RCTBridgeModuleProvider)moduleProvider
bridge:(RCTBridge *)bridge
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
viewRegistry_DEPRECATED:(RCTViewRegistry *)viewRegistry_DEPRECATED
bundleManager:(RCTBundleManager *)bundleManager
callableJSModules:(RCTCallableJSModules *)callableJSModules
{
if (self = [super init]) {
_bridge = bridge;
_moduleClass = moduleClass;
_moduleProvider = [moduleProvider copy];
_moduleRegistry = moduleRegistry;
_viewRegistry_DEPRECATED = viewRegistry_DEPRECATED;
_bundleManager = bundleManager;
_callableJSModules = callableJSModules;
[self setUp];
_moduleProvider = [^id<RCTBridgeModule> {
return [moduleClass new];
} copy];
[self _setUpWithBridge:bridge
moduleRegistry:moduleRegistry
viewRegistry_DEPRECATED:viewRegistry_DEPRECATED
bundleManager:bundleManager
callableJSModules:callableJSModules];
}
return self;
}
Expand All @@ -127,14 +122,13 @@ - (instancetype)initWithModuleInstance:(id<RCTBridgeModule>)instance
callableJSModules:(RCTCallableJSModules *)callableJSModules
{
if (self = [super init]) {
_bridge = bridge;
_instance = instance;
_moduleClass = [instance class];
_moduleRegistry = moduleRegistry;
_viewRegistry_DEPRECATED = viewRegistry_DEPRECATED;
_bundleManager = bundleManager;
_callableJSModules = callableJSModules;
[self setUp];
[self _setUpWithBridge:bridge
moduleRegistry:moduleRegistry
viewRegistry_DEPRECATED:viewRegistry_DEPRECATED
bundleManager:bundleManager
callableJSModules:callableJSModules];
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration;
@property (nonatomic, assign) CGSize minimumSize;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode NS_UNAVAILABLE;

- (instancetype)initWithSurface:(id<RCTSurfaceProtocol>)surface NS_DESIGNATED_INITIALIZER;

- (void)cancelTouches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ typedef std::shared_ptr<facebook::react::JSRuntimeFactory> (^RCTHostJSEngineProv
jsEngineProvider:(RCTHostJSEngineProvider)jsEngineProvider
launchOptions:(nullable NSDictionary *)launchOptions __deprecated;

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

@property (nonatomic, weak, nullable) id<RCTHostRuntimeDelegate> runtimeDelegate;

@property (nonatomic, readonly) RCTSurfacePresenter *surfacePresenter;
Expand Down

0 comments on commit b98846c

Please sign in to comment.