Skip to content

Commit

Permalink
fix(react-native-host): fix SurfaceRegistryBinding::startSurface fa…
Browse files Browse the repository at this point in the history
…iled (#3130)
  • Loading branch information
tido64 committed May 7, 2024
1 parent d7758b4 commit 76f92c1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/orange-paws-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/react-native-host": patch
---

Fix `SurfaceRegistryBinding::startSurface` failed on startup with New Architecture
6 changes: 6 additions & 0 deletions packages/react-native-host/cocoa/ReactNativeHost+Private.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#import "ReactNativeHost.h"

@class RCTHost;
@class RCTSurfacePresenter;

NS_ASSUME_NONNULL_BEGIN

@interface ReactNativeHost (Private)

/// Returns the current ``RCTHost`` instance.
///
/// - Note: Returns `nil` if New Architecture is not enabled.
@property (nonatomic, readonly, nullable) RCTHost *reactHost;

/// Returns the current ``RCTSurfacePresenter`` instance.
///
/// - Note: Returns `nil` if New Architecture is not enabled.
Expand Down
12 changes: 11 additions & 1 deletion packages/react-native-host/cocoa/ReactNativeHost+View.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#import <React/RCTFabricSurface.h>
#import <React/RCTSurfaceHostingProxyRootView.h>
#endif // __has_include(<React/RCTFabricSurfaceHostingProxyRootView.h>)
#ifdef USE_BRIDGELESS
#import <ReactCommon/RCTHost.h>
#endif // USE_BRIDGELESS
static NSString *const kReactConcurrentRoot = @"concurrentRoot";
#else
#else // USE_FABRIC
#import <React/RCTRootView.h>
#endif // USE_FABRIC

Expand Down Expand Up @@ -53,6 +56,13 @@ - (RNXView *)viewWithModuleName:(NSString *)moduleName
return [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:self.bridge
moduleName:moduleName
initialProperties:initialProps];
#elif USE_BRIDGELESS
RCTFabricSurface *surface = [self.reactHost createSurfaceWithModuleName:moduleName
initialProperties:initialProps];
RCTSurfaceSizeMeasureMode sizeMeasureMode =
RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact;
return [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface
sizeMeasureMode:sizeMeasureMode];
#else
RCTFabricSurface *surface =
[[RCTFabricSurface alloc] initWithSurfacePresenter:self.surfacePresenter
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native-host/cocoa/ReactNativeHost.mm
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ - (RCTBridge *)bridge
}
}

- (RCTHost *)reactHost
{
return _reactHost;
}

- (RCTSurfacePresenter *)surfacePresenter
{
#if USE_BRIDGELESS
Expand Down

0 comments on commit 76f92c1

Please sign in to comment.