Skip to content

Commit dfc1d06

Browse files
committed
fix: [visionOS][0.73] adjust AppDelegate and Hermes
1 parent bbfae56 commit dfc1d06

File tree

19 files changed

+895
-484
lines changed

19 files changed

+895
-484
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,6 @@ package-lock.json
154154

155155
# CircleCI
156156
.circleci/generated_config.yml
157+
158+
.circleci/storage/
159+
.yarn/cache

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@
136136
- (BOOL)bridgelessEnabled;
137137

138138
/// Return the bundle URL for the main bundle.
139-
- (NSURL *__nullable)bundleURL;
139+
- (NSURL *__nullable)getBundleURL;
140+
141+
#endif
140142

141143
/// Don't use this method, it's going to be removed soon.
142144
- (UIView *)viewWithModuleName:(NSString *)moduleName

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 74 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,17 @@ - (instancetype)init
8686

8787
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
8888
{
89-
RCTSetNewArchEnabled([self newArchEnabled]);
90-
BOOL enableTM = self.turboModuleEnabled;
89+
BOOL enableTM = NO;
90+
BOOL enableBridgeless = NO;
91+
BOOL fabricEnabled = NO;
92+
#if RCT_NEW_ARCH_ENABLED
93+
enableTM = self.turboModuleEnabled;
94+
enableBridgeless = self.bridgelessEnabled;
95+
fabricEnabled = [self fabricEnabled];
96+
#endif
97+
98+
RCTAppSetupPrepareApp(application, enableTM);
9199

92-
RCTAppSetupPrepareApp(application, enableTM, *_reactNativeConfig);
93100

94101
#if TARGET_OS_VISION
95102
/// Bail out of UIWindow initializaiton to support multi-window scenarios in SwiftUI lifecycle.
@@ -115,48 +122,52 @@ - (void)applicationDidEnterBackground:(UIApplication *)application
115122
}
116123

117124
- (UIView *)viewWithModuleName:(NSString *)moduleName initialProperties:(NSDictionary*)initialProperties launchOptions:(NSDictionary*)launchOptions {
118-
BOOL fabricEnabled = self.fabricEnabled;
119-
BOOL enableBridgeless = self.bridgelessEnabled;
120-
121-
NSDictionary *initProps = updateInitialProps(initialProperties, fabricEnabled);
125+
BOOL enableTM = NO;
126+
BOOL enableBridgeless = NO;
127+
BOOL fabricEnabled = NO;
128+
#if RCT_NEW_ARCH_ENABLED
129+
enableTM = self.turboModuleEnabled;
130+
enableBridgeless = self.bridgelessEnabled;
131+
fabricEnabled = [self fabricEnabled];
132+
#endif
133+
UIView *rootView;
134+
135+
if (enableBridgeless) {
136+
#if RCT_NEW_ARCH_ENABLED
137+
// Enable native view config interop only if both bridgeless mode and Fabric is enabled.
138+
RCTSetUseNativeViewConfigsInBridgelessMode(fabricEnabled);
122139

123-
UIView *rootView;
124-
if (enableBridgeless) {
125-
// Enable native view config interop only if both bridgeless mode and Fabric is enabled.
126-
RCTSetUseNativeViewConfigsInBridgelessMode(self.fabricEnabled);
127-
128-
// Enable TurboModule interop by default in Bridgeless mode
129-
RCTEnableTurboModuleInterop(YES);
130-
RCTEnableTurboModuleInteropBridgeProxy(YES);
131-
132-
[self createReactHost];
133-
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
134-
RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName initialProperties:initProps];
135-
136-
RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc]
137-
initWithSurface:surface
138-
sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
139-
140-
rootView = (RCTRootView *)surfaceHostingProxyRootView;
141-
} else {
142-
if (!self.bridge) {
143-
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
144-
}
145-
if ([self newArchEnabled]) {
146-
if (!self.bridgeAdapter) {
147-
self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
148-
contextContainer:_contextContainer];
149-
self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;
150-
151-
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
152-
}
153-
}
154-
rootView = [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps];
140+
// Enable TurboModule interop by default in Bridgeless mode
141+
RCTEnableTurboModuleInterop(YES);
142+
RCTEnableTurboModuleInteropBridgeProxy(YES);
143+
144+
[self createReactHost];
145+
[self unstable_registerLegacyComponents];
146+
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
147+
RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:moduleName initialProperties:initialProperties];
148+
149+
RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc]
150+
initWithSurface:surface
151+
sizeMeasureMode:RCTSurfaceSizeMeasureModeWidthExact | RCTSurfaceSizeMeasureModeHeightExact];
152+
153+
rootView = (RCTRootView *)surfaceHostingProxyRootView;
154+
#endif
155+
} else {
156+
if (!self.bridge) {
157+
self.bridge = [self createBridgeWithDelegate:self launchOptions:launchOptions];
155158
}
156-
157-
[self customizeRootView:(RCTRootView *)rootView];
159+
#if RCT_NEW_ARCH_ENABLED
160+
self.bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:self.bridge
161+
contextContainer:_contextContainer];
162+
self.bridge.surfacePresenter = self.bridgeAdapter.surfacePresenter;
158163

159-
return rootView;
164+
[self unstable_registerLegacyComponents];
165+
[RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self;
166+
#endif
167+
168+
rootView = [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initialProperties];
169+
}
170+
return rootView;
160171
}
161172

162173
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
@@ -219,20 +230,19 @@ - (void)windowScene:(UIWindowScene *)windowScene
219230
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
220231
{
221232
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
222-
if ([self newArchEnabled]) {
223-
std::shared_ptr<facebook::react::CallInvoker> callInvoker =
224-
std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
225-
RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
226-
delegate:self
227-
jsInvoker:callInvoker];
228-
_contextContainer->erase("RuntimeScheduler");
229-
_contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
230-
return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
231-
} else {
232-
return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
233-
}
233+
#if RCT_NEW_ARCH_ENABLED
234+
std::shared_ptr<facebook::react::CallInvoker> callInvoker =
235+
std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
236+
RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
237+
delegate:self
238+
jsInvoker:callInvoker];
239+
_contextContainer->erase("RuntimeScheduler");
240+
_contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
241+
return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
242+
#else
243+
return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
244+
#endif
234245
}
235-
236246
#pragma mark - New Arch Enabled settings
237247

238248
- (BOOL)newArchEnabled
@@ -259,6 +269,15 @@ - (BOOL)bridgelessEnabled
259269
return NO;
260270
}
261271

272+
#pragma mark - New Arch Utilities
273+
274+
- (void)unstable_registerLegacyComponents
275+
{
276+
for (NSString *legacyComponent in [RCTLegacyInteropComponents legacyInteropComponents]) {
277+
[RCTLegacyViewManagerInteropComponentView supportLegacyViewManagerWithName:legacyComponent];
278+
}
279+
}
280+
262281
#pragma mark - RCTComponentViewFactoryComponentProvider
263282

264283
- (NSDictionary<NSString *, Class<RCTComponentViewProtocol>> *)thirdPartyFabricComponents

packages/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ extern NSString *const RCTRemoteNotificationReceived;
1313

1414
typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);
1515

16-
#if !TARGET_OS_UIKITFORMAC
1716
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
1817
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
1918
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
2019
fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler;
2120
#if !TARGET_OS_VISION
2221
/** DEPRECATED. Use didReceiveNotification instead. */
2322
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification RCT_DEPRECATED;
24-
#endif
2523
/** DEPRECATED. Use didReceiveNotification instead. */
2624
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification RCT_DEPRECATED;
25+
#endif
2726

2827
@end

packages/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ @implementation RCTPushNotificationManager
176176
return [formatter stringFromDate:date];
177177
}
178178

179-
#endif // TARGET_OS_UIKITFORMAC
180179

181180
RCT_EXPORT_MODULE()
182181

@@ -268,14 +267,6 @@ + (void)didReceiveLocalNotification:(UILocalNotification *)notification
268267
}
269268
#endif
270269

271-
// Deprecated
272-
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
273-
{
274-
NSDictionary *userInfo = @{@"notification" : notification};
275-
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationReceived
276-
object:self
277-
userInfo:userInfo];
278-
}
279270

280271
- (void)handleLocalNotificationReceived:(NSNotification *)notification
281272
{

packages/react-native/Libraries/Text/Text/RCTTextView.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,12 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
256256
}
257257

258258
[menuController showMenuFromView:self rect:self.bounds];
259+
260+
[menuController setTargetRect:self.bounds inView:self];
261+
[menuController setMenuVisible:YES animated:YES];
259262
#endif
260263
}
261264

262-
[menuController setTargetRect:self.bounds inView:self];
263-
[menuController setMenuVisible:YES animated:YES];
264265
#endif
265266
}
266267

packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
253253
}
254254

255255
[menuController showMenuFromView:self rect:self.bounds];
256+
[menuController setTargetRect:self.bounds inView:self];
257+
[menuController setMenuVisible:YES animated:YES];
256258
#endif
257259
}
258260

259-
[menuController setTargetRect:self.bounds inView:self];
260-
[menuController setMenuVisible:YES animated:YES];
261261
#endif
262262
}
263263

packages/react-native/scripts/cocoapods/__tests__/jsengine-test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_setupHermes_installsPods
7373
assert_equal(hermes_engine_pod_invocation[:podspec], "../../sdks/hermes-engine/hermes-engine.podspec")
7474
assert_equal(hermes_engine_pod_invocation[:tag], "")
7575
assert_equal($podInvocation["React-hermes"][:path], "../../ReactCommon/hermes")
76-
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12")
76+
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12.1")
7777
end
7878

7979
end

packages/react-native/scripts/cocoapods/jsengine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ def setup_hermes!(react_native_path: "../node_modules/react-native")
3030
hermestag = File.exist?(hermestag_file) ? File.read(hermestag_file).strip : ''
3131
pod 'hermes-engine', :podspec => "#{react_native_path}/sdks/hermes-engine/hermes-engine.podspec", :tag => hermestag
3232
pod 'React-hermes', :path => "#{react_native_path}/ReactCommon/hermes"
33-
pod 'libevent', '~> 2.1.12'
33+
pod 'libevent', :podspec => "#{react_native_path}/third-party-podspecs/libevent.podspec"
3434
end

packages/react-native/scripts/codegen/generate-artifacts-executor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..', '..');
3232

3333
const CODEGEN_DEPENDENCY_NAME = '@react-native/codegen';
3434
const CODEGEN_REPO_PATH = `${REACT_NATIVE_REPOSITORY_ROOT}/packages/react-native-codegen`;
35-
const CODEGEN_NPM_PATH = `${REACT_NATIVE_PACKAGE_ROOT_FOLDER}/../${CODEGEN_DEPENDENCY_NAME}`;
35+
const CODEGEN_NPM_PATH = `${REACT_NATIVE_PACKAGE_ROOT_FOLDER}/../../${CODEGEN_DEPENDENCY_NAME}`;
3636
const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = {
3737
rncore: path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactCommon'),
3838
FBReactNativeSpec: null,

0 commit comments

Comments
 (0)