Skip to content

Commit

Permalink
Fix build errors when inheriting RCTAppDelegate in Swift modules (#35661
Browse files Browse the repository at this point in the history
)

Summary:
When inheriting `RCTAppDelegate` in a module with swift code, the compiler will have a build error when it goes through module headers. because swift does not support cxx headers. we found this issue when we try to inherit the class at Expo's [`EXAppDelegateWrapper`](https://github.com/expo/expo/blob/main/packages/expo-modules-core/ios/AppDelegates/EXAppDelegateWrapper.h) with RCTAppDelegate in new architecture mode.

## Changelog

[IOS][FIXED] - Fix build errors when inheriting RCTAppDelegate in Swift modules

Pull Request resolved: #35661

Test Plan:
- ci passed
- tested with expo's setup: expo/expo#20470

Reviewed By: rshest

Differential Revision: D42293851

Pulled By: cipolleschi

fbshipit-source-id: 8a173279db070cc0008c6f8214093951f504dcc1
  • Loading branch information
Kudo authored and facebook-github-bot committed Dec 30, 2022
1 parent 70d9b56 commit 5eb25d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 4 additions & 12 deletions Libraries/AppDelegate/RCTAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>

#if RCT_NEW_ARCH_ENABLED
// When the new architecture is enabled, the RCTAppDelegate imports some additional headers
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTTurboModuleManager.h>

#endif
@class RCTSurfacePresenterBridgeAdapter;
@class RCTTurboModuleManager;

/**
* The RCTAppDelegate is an utility class that implements some base configurations for all the React Native apps.
Expand Down Expand Up @@ -98,11 +93,7 @@
*/
- (UIViewController *)createRootViewController;

@end

#if RCT_NEW_ARCH_ENABLED
/// Extension that makes the RCTAppDelegate conform to New Architecture delegates
@interface RCTAppDelegate () <RCTTurboModuleManagerDelegate, RCTCxxBridgeDelegate>

/// The TurboModule manager
@property (nonatomic, strong) RCTTurboModuleManager *turboModuleManager;
Expand All @@ -126,5 +117,6 @@
/// @return: `true` if the Fabric Renderer is enabled. Otherwise, it returns `false`.
- (BOOL)fabricEnabled;

@end
#endif

@end
5 changes: 4 additions & 1 deletion Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

#if RCT_NEW_ARCH_ENABLED
#import <React/CoreModulesPlugins.h>
#import <React/RCTCxxBridgeDelegate.h>
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
#import <React/RCTSurfacePresenter.h>
#import <React/RCTSurfacePresenterBridgeAdapter.h>
#import <ReactCommon/RCTTurboModuleManager.h>
#import <react/config/ReactNativeConfig.h>

static NSString *const kRNConcurrentRoot = @"concurrentRoot";

@interface RCTAppDelegate () {
@interface RCTAppDelegate () <RCTTurboModuleManagerDelegate, RCTCxxBridgeDelegate> {
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
facebook::react::ContextContainer::Shared _contextContainer;
}
Expand Down

0 comments on commit 5eb25d2

Please sign in to comment.