mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Bridgeless: Expose host delegate methods (#44158)
Summary: Expose host delegate methods that users can do some customize work. ## Changelog: [IOS] [ADDED] - Bridgeless: Expose host delegate methods Pull Request resolved: https://github.com/facebook/react-native/pull/44158 Test Plan: Users can do some customized work by `RCTRootViewFactory`. Reviewed By: sammy-SC Differential Revision: D56521470 Pulled By: cipolleschi fbshipit-source-id: dd22d0978b9fd4385380945a514eb6596b7d874f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
fc4e099920
commit
f500b47a95
@@ -11,6 +11,7 @@
|
||||
#import <React/RCTRootView.h>
|
||||
#import <React/RCTSurfacePresenterBridgeAdapter.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <ReactCommon/RCTHost.h>
|
||||
#import <objc/runtime.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
|
||||
@@ -32,7 +33,7 @@
|
||||
#endif
|
||||
#import <react/nativemodule/defaults/DefaultTurboModules.h>
|
||||
|
||||
@interface RCTAppDelegate () <RCTComponentViewFactoryComponentProvider>
|
||||
@interface RCTAppDelegate () <RCTComponentViewFactoryComponentProvider, RCTHostDelegate>
|
||||
@end
|
||||
|
||||
@implementation RCTAppDelegate
|
||||
@@ -158,6 +159,20 @@
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#pragma mark - RCTHostDelegate
|
||||
|
||||
- (void)hostDidStart:(RCTHost *)host
|
||||
{
|
||||
}
|
||||
|
||||
- (void)host:(RCTHost *)host
|
||||
didReceiveJSErrorStack:(NSArray<NSDictionary<NSString *, id> *> *)stack
|
||||
message:(NSString *)message
|
||||
exceptionId:(NSUInteger)exceptionId
|
||||
isFatal:(BOOL)isFatal
|
||||
{
|
||||
}
|
||||
|
||||
#pragma mark - Bridge and Bridge Adapter properties
|
||||
|
||||
- (RCTBridge *)bridge
|
||||
@@ -243,6 +258,19 @@
|
||||
return [weakSelf sourceURLForBridge:bridge];
|
||||
};
|
||||
|
||||
configuration.hostDidStartBlock = ^(RCTHost *_Nonnull host) {
|
||||
[weakSelf hostDidStart:host];
|
||||
};
|
||||
|
||||
configuration.hostDidReceiveJSErrorStackBlock =
|
||||
^(RCTHost *_Nonnull host,
|
||||
NSArray<NSDictionary<NSString *, id> *> *_Nonnull stack,
|
||||
NSString *_Nonnull message,
|
||||
NSUInteger exceptionId,
|
||||
BOOL isFatal) {
|
||||
[weakSelf host:host didReceiveJSErrorStack:stack message:message exceptionId:exceptionId isFatal:isFatal];
|
||||
};
|
||||
|
||||
if ([self respondsToSelector:@selector(extraModulesForBridge:)]) {
|
||||
configuration.extraModulesForBridge = ^NSArray<id<RCTBridgeModule>> *_Nonnull(RCTBridge *_Nonnull bridge)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,13 @@ typedef NSURL *_Nullable (^RCTBundleURLBlock)(void);
|
||||
typedef NSArray<id<RCTBridgeModule>> *_Nonnull (^RCTExtraModulesForBridgeBlock)(RCTBridge *bridge);
|
||||
typedef NSDictionary<NSString *, Class> *_Nonnull (^RCTExtraLazyModuleClassesForBridge)(RCTBridge *bridge);
|
||||
typedef BOOL (^RCTBridgeDidNotFindModuleBlock)(RCTBridge *bridge, NSString *moduleName);
|
||||
typedef void (^RCTHostDidStartBlock)(RCTHost *host);
|
||||
typedef void (^RCTHostDidReceiveJSErrorStackBlock)(
|
||||
RCTHost *host,
|
||||
NSArray<NSDictionary<NSString *, id> *> *stack,
|
||||
NSString *message,
|
||||
NSUInteger exceptionId,
|
||||
BOOL isFatal);
|
||||
|
||||
#pragma mark - RCTRootViewFactory Configuration
|
||||
@interface RCTRootViewFactoryConfiguration : NSObject
|
||||
@@ -132,6 +139,22 @@ typedef BOOL (^RCTBridgeDidNotFindModuleBlock)(RCTBridge *bridge, NSString *modu
|
||||
*/
|
||||
@property (nonatomic, nullable) RCTBridgeDidNotFindModuleBlock bridgeDidNotFindModule;
|
||||
|
||||
/**
|
||||
* Called when `RCTHost` started.
|
||||
* @parameter: host - The started `RCTHost`.
|
||||
*/
|
||||
@property (nonatomic, nullable) RCTHostDidStartBlock hostDidStartBlock;
|
||||
|
||||
/**
|
||||
* Called when `RCTHost` received JS error.
|
||||
* @parameter: host - `RCTHost` which received js error.
|
||||
* @parameter: stack - JS error stack.
|
||||
* @parameter: message - Error message.
|
||||
* @parameter: exceptionId - Exception ID.
|
||||
* @parameter: isFatal - YES if JS error is fatal.
|
||||
*/
|
||||
@property (nonatomic, nullable) RCTHostDidReceiveJSErrorStackBlock hostDidReceiveJSErrorStackBlock;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - RCTRootViewFactory
|
||||
|
||||
@@ -83,7 +83,7 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTRootViewFactory () <RCTContextContainerHandling> {
|
||||
@interface RCTRootViewFactory () <RCTContextContainerHandling, RCTHostDelegate> {
|
||||
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
|
||||
facebook::react::ContextContainer::Shared _contextContainer;
|
||||
}
|
||||
@@ -180,6 +180,26 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
|
||||
return rootView;
|
||||
}
|
||||
|
||||
#pragma mark - RCTHostDelegate
|
||||
|
||||
- (void)hostDidStart:(RCTHost *)host
|
||||
{
|
||||
if (self->_configuration.hostDidStartBlock) {
|
||||
self->_configuration.hostDidStartBlock(host);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)host:(RCTHost *)host
|
||||
didReceiveJSErrorStack:(NSArray<NSDictionary<NSString *, id> *> *)stack
|
||||
message:(NSString *)message
|
||||
exceptionId:(NSUInteger)exceptionId
|
||||
isFatal:(BOOL)isFatal
|
||||
{
|
||||
if (self->_configuration.hostDidReceiveJSErrorStackBlock) {
|
||||
self->_configuration.hostDidReceiveJSErrorStackBlock(host, stack, message, exceptionId, isFatal);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - RCTCxxBridgeDelegate
|
||||
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
|
||||
{
|
||||
@@ -238,7 +258,7 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
RCTHost *reactHost =
|
||||
[[RCTHost alloc] initWithBundleURLProvider:self->_configuration.bundleURLBlock
|
||||
hostDelegate:nil
|
||||
hostDelegate:self
|
||||
turboModuleManagerDelegate:_turboModuleManagerDelegate
|
||||
jsEngineProvider:^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
|
||||
return [weakSelf createJSRuntimeFactory];
|
||||
|
||||
Reference in New Issue
Block a user