mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47761 When breaking the last dependency, we created the `RCTApDependencyProvider` in the Codegen pod. This is not an issue per sè. The problem comes in with the new template in Swift: ReactCodegen contains some headers with some C++ code that Swift can't really process. That's why most libraries started failing in jobs like [this one](https://github.com/facebook/react-native/actions/runs/11906196751/job/33177904733): the template app was not able to load the `ReactCodegen` pod in the Swift app delegate. Given that the app delegate only have to actually load the RCTAppDependencyProvider, I extracted that class in its own pod: ReactAppDependencyProvider. The name of the pod does not follow the React-RCTXXX structure because that will create issues with the import statements and the `use_frameworks!` use case. > [!NOTE] > We need to update the template and change the `import ReactCodegen` to `import ReactAppDependencyProvider` ## Changelog: [iOS][Added] - Extract RCTAppDependencyProvider in the ReactAppDependencyProvider pod Reviewed By: blakef Differential Revision: D66241941 fbshipit-source-id: 6b888109c65d9560fff322ec84a16da78fbcd64b
179 lines
6.0 KiB
Plaintext
179 lines
6.0 KiB
Plaintext
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import <UserNotifications/UserNotifications.h>
|
|
|
|
#import <RCTAppDelegate+Protected.h>
|
|
#import <React/RCTBundleURLProvider.h>
|
|
#import <React/RCTDefines.h>
|
|
#import <React/RCTLinkingManager.h>
|
|
#import <ReactCommon/RCTSampleTurboModule.h>
|
|
#import <ReactCommon/RCTTurboModuleManager.h>
|
|
#import <ReactCommon/SampleTurboCxxModule.h>
|
|
|
|
#import <React/RCTPushNotificationManager.h>
|
|
|
|
#import <NativeCxxModuleExample/NativeCxxModuleExample.h>
|
|
#ifndef RN_DISABLE_OSS_PLUGIN_HEADER
|
|
#import <RNTMyNativeViewComponentView.h>
|
|
#endif
|
|
|
|
#if __has_include(<ReactAppDependencyProvider/RCTAppDependencyProvider.h>)
|
|
#define USE_OSS_CODEGEN 1
|
|
#import <ReactAppDependencyProvider/RCTAppDependencyProvider.h>
|
|
#else
|
|
#define USE_OSS_CODEGEN 0
|
|
#endif
|
|
|
|
static NSString *kBundlePath = @"js/RNTesterApp.ios";
|
|
|
|
@interface AppDelegate () <UNUserNotificationCenterDelegate>
|
|
@end
|
|
|
|
@implementation AppDelegate
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
{
|
|
self.moduleName = @"RNTesterApp";
|
|
#if USE_OSS_CODEGEN
|
|
self.dependencyProvider = [RCTAppDependencyProvider new];
|
|
#endif
|
|
// You can add your custom initial props in the dictionary below.
|
|
// They will be passed down to the ViewController used by React Native.
|
|
self.initialProps = [self prepareInitialProps];
|
|
|
|
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
|
|
|
|
return [super application:application didFinishLaunchingWithOptions:launchOptions];
|
|
}
|
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application
|
|
{
|
|
[super applicationDidEnterBackground:application];
|
|
}
|
|
|
|
- (NSDictionary *)prepareInitialProps
|
|
{
|
|
NSMutableDictionary *initProps = [NSMutableDictionary new];
|
|
|
|
NSString *_routeUri = [[NSUserDefaults standardUserDefaults] stringForKey:@"route"];
|
|
if (_routeUri) {
|
|
initProps[@"exampleFromAppetizeParams"] = [NSString stringWithFormat:@"rntester://example/%@Example", _routeUri];
|
|
}
|
|
|
|
return initProps;
|
|
}
|
|
|
|
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
|
|
{
|
|
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath];
|
|
}
|
|
|
|
- (BOOL)application:(UIApplication *)app
|
|
openURL:(NSURL *)url
|
|
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
|
|
{
|
|
return [RCTLinkingManager application:app openURL:url options:options];
|
|
}
|
|
|
|
- (void)loadSourceForBridge:(RCTBridge *)bridge
|
|
onProgress:(RCTSourceLoadProgressBlock)onProgress
|
|
onComplete:(RCTSourceLoadBlock)loadCallback
|
|
{
|
|
[RCTJavaScriptLoader loadBundleAtURL:[self sourceURLForBridge:bridge] onProgress:onProgress onComplete:loadCallback];
|
|
}
|
|
|
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
|
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
|
{
|
|
if (name == std::string([@"SampleTurboCxxModule" UTF8String])) {
|
|
return std::make_shared<facebook::react::SampleTurboCxxModule>(jsInvoker);
|
|
}
|
|
|
|
if (name == facebook::react::NativeCxxModuleExample::kModuleName) {
|
|
return std::make_shared<facebook::react::NativeCxxModuleExample>(jsInvoker);
|
|
}
|
|
|
|
return [super getTurboModule:name jsInvoker:jsInvoker];
|
|
}
|
|
|
|
// Required for the remoteNotificationsRegistered event.
|
|
- (void)application:(__unused UIApplication *)application
|
|
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
|
|
{
|
|
[RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
|
|
}
|
|
|
|
// Required for the remoteNotificationRegistrationError event.
|
|
- (void)application:(__unused UIApplication *)application
|
|
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
|
|
{
|
|
[RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
|
|
}
|
|
|
|
#pragma mark - UNUserNotificationCenterDelegate
|
|
|
|
// Required for the remoteNotificationReceived and localNotificationReceived events
|
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
willPresentNotification:(UNNotification *)notification
|
|
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
|
|
{
|
|
[RCTPushNotificationManager didReceiveNotification:notification];
|
|
completionHandler(UNNotificationPresentationOptionNone);
|
|
}
|
|
|
|
// Required for the remoteNotificationReceived and localNotificationReceived events
|
|
// Called when a notification is tapped from background. (Foreground notification will not be shown per
|
|
// the presentation option selected above).
|
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
|
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|
withCompletionHandler:(void (^)(void))completionHandler
|
|
{
|
|
UNNotification *notification = response.notification;
|
|
|
|
// This condition will be true if tapping the notification launched the app.
|
|
if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
|
|
// This can be retrieved with getInitialNotification.
|
|
[RCTPushNotificationManager setInitialNotification:notification];
|
|
}
|
|
|
|
[RCTPushNotificationManager didReceiveNotification:notification];
|
|
completionHandler();
|
|
}
|
|
|
|
#pragma mark - New Arch Enabled settings
|
|
|
|
- (BOOL)bridgelessEnabled
|
|
{
|
|
return [super bridgelessEnabled];
|
|
}
|
|
|
|
#pragma mark - RCTComponentViewFactoryComponentProvider
|
|
|
|
#ifndef RN_DISABLE_OSS_PLUGIN_HEADER
|
|
- (nonnull NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents
|
|
{
|
|
NSMutableDictionary *dict = [super thirdPartyFabricComponents].mutableCopy;
|
|
if (!dict[@"RNTMyNativeView"]) {
|
|
dict[@"RNTMyNativeView"] = NSClassFromString(@"RNTMyNativeViewComponentView");
|
|
}
|
|
if (!dict[@"SampleNativeComponent"]) {
|
|
dict[@"SampleNativeComponent"] = NSClassFromString(@"RCTSampleNativeComponentComponentView");
|
|
}
|
|
return dict;
|
|
}
|
|
#endif
|
|
|
|
- (NSURL *)bundleURL
|
|
{
|
|
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:kBundlePath];
|
|
}
|
|
|
|
@end
|