Skip to content

Conversation

@okwasniewski
Copy link
Contributor

@okwasniewski okwasniewski commented Sep 2, 2024

Summary:

This PR implements ReactNativeFactory to encapsulate further the logic of creating an instance of React Native for iOS.

This will remove the strong coupling on the RCTAppDelegate and allow us to support Scene Delegate in the future.

The goal is to have a following API:

self.reactNativeFactory = [[RCTReactNativeFactory alloc] initWithDelegate:self];

UIView *rootView = [self.reactNativeFactory.rootViewFactory viewWithModuleName:self.moduleName
                                                               initialProperties:self.initialProps
                                                                   launchOptions:launchOptions];
                                                                   
// Standard iOS stuff here 

Changelog:

[IOS] [ADDED] - implement ReactNativeFactory

Test Plan:

Test out all the methods of AppDelegate

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner labels Sep 2, 2024
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The direction looks the right one to me. I left a couple of comments with internal considerations, but it looks promising.

@okwasniewski okwasniewski force-pushed the feat/ReactNativeFactory branch from 7754580 to 969d347 Compare September 12, 2024 14:42
facebook-github-bot pushed a commit that referenced this pull request Oct 30, 2024
Summary:
This PR introduces `RCTUIConfiguratorProtocol` for better separation of concerns inside of RCTAppDelegate.

It's also a prerequisite for #46298

Discussed with cipolleschi

## Changelog:

[IOS] [ADDED] - introduce RCTUIConfiguratorProtocol

Pull Request resolved: #47139

Test Plan:
- CI Green
- Test if methods can be overriden

Reviewed By: blakef

Differential Revision: D65063839

Pulled By: cipolleschi

fbshipit-source-id: b63766e245d57f369ab94bd8047d5de9a3447b3e
facebook-github-bot pushed a commit that referenced this pull request Oct 30, 2024
Summary:
This PR introduces `RCTArchConfiguratorProtocol` for better separation of concerns inside of RCTAppDelegate.

It's also a prerequisite for #46298

Discussed with cipolleschi

## Changelog:

[IOS] [ADDED] - introduce RCTArchConfiguratorProtocol

Pull Request resolved: #47306

Test Plan:
- CI Green
- Test if methods can be overriden

Reviewed By: realsoelynn

Differential Revision: D65212703

Pulled By: cipolleschi

fbshipit-source-id: 9850fec31c421f0c6230e7e23d7a208d823d828f
@okwasniewski okwasniewski force-pushed the feat/ReactNativeFactory branch from 969d347 to 13d0fa4 Compare November 18, 2024 15:34
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long wait @okwasniewski.
I love the direction of this!

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pressed on approve by mistake.
There are a couple of things that are missing.

@okwasniewski
Copy link
Contributor Author

@cipolleschi Sorry I kind of left it in-progress, as I was experimenting with the new approach, of course everything you pointed out needs to be fixed! Thanks for checking it out and making sure the direction is good.

We are finishing a client project, so I will have some time to get back to this work soon

@okwasniewski okwasniewski force-pushed the feat/ReactNativeFactory branch 9 times, most recently from 7f64781 to e69d9dc Compare December 18, 2024 10:23
Comment on lines -10 to -14
#import <ReactCommon/RCTTurboModuleManager.h>
#import "RCTAppDelegate.h"

@interface RCTAppDelegate () <RCTTurboModuleManagerDelegate>
@end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cipolleschi I'm not sure how to handle this. This should be defined on the ReactNativeFactoryDelegate now but removing this might be a breaking change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added the conformance already here so, technically, the RCTAppDelegate conforms to the RCTTurboModuleManagerDelegate.

If the breaking change is for the missing file/import, we can land it and ship it in 0.78.

@okwasniewski okwasniewski force-pushed the feat/ReactNativeFactory branch 2 times, most recently from 400d438 to 7f60df3 Compare December 18, 2024 10:27
@okwasniewski okwasniewski marked this pull request as ready for review December 18, 2024 10:38
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Dec 18, 2024
@cipolleschi
Copy link
Contributor

uhm... dynamic frameworks are failing, could you have a look at why and fix it, please?

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job. I left a few other comments that probably needs to be addressed.

Can you also check whether the packages/helloworld/ios app requires any change? This mimics the template in our CI.

@okwasniewski okwasniewski force-pushed the feat/ReactNativeFactory branch from 7f60df3 to 06e3513 Compare December 18, 2024 14:08
@okwasniewski
Copy link
Contributor Author

uhm... dynamic frameworks are failing, could you have a look at why and fix it, please?

Yeah.. wrong import, should be good now

@okwasniewski okwasniewski force-pushed the feat/ReactNativeFactory branch from 06e3513 to 5bb5a94 Compare December 18, 2024 15:11
@cipolleschi
Copy link
Contributor

And now we have a conflict with your other PR.. 🤣

wip: work on new implementation
@okwasniewski okwasniewski force-pushed the feat/ReactNativeFactory branch from 5bb5a94 to 4c456ee Compare December 18, 2024 15:52
@okwasniewski
Copy link
Contributor Author

And now we have a conflict with your other PR.. 🤣

Rebased ✅ At least now we have a clear history why it was deleted 😄

Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the amazing work!

Comment on lines -10 to -14
#import <ReactCommon/RCTTurboModuleManager.h>
#import "RCTAppDelegate.h"

@interface RCTAppDelegate () <RCTTurboModuleManagerDelegate>
@end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added the conformance already here so, technically, the RCTAppDelegate conforms to the RCTTurboModuleManagerDelegate.

If the breaking change is for the missing file/import, we can land it and ship it in 0.78.

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Dec 31, 2024
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @okwasniewski in 081be01

When will my fix make it into a release? | How to file a pick request?

@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in 081be01.

facebook-github-bot pushed a commit that referenced this pull request Feb 17, 2025
Summary:
Recently, I've introduced `RCTReactNativeFactory` in this PR: #46298, which is a good successor for `RCTAppDelegate`.

### Why?

`RCTAppDelegate` introduced strong coupling between React Native and AppDelegate pattern. From iOS 13+ there is a newer equivalent (Scene Delegate) which is not possible to achieve with current architecture. The proposed solution involves migration to a `RCTReactNativeFactory` a class that encapsulates initialization logic of React Native.

This migration will make brownfield initialization easier by making it more flexible and simpler to integrate into already established apps.

### Deprecation plan

The plan I've discussed with cipolleschi involves:

- Deprecation of `RCTAppDelegate` in 0.79 (current main)
- Migration off `RCTAppDelegate` to SceneDelegate + `RCTReactNativeFactory` in 0.80

## Changelog:

[IOS] [DEPRECATED] - deprecate RCTAppDelegate

Pull Request resolved: #49078

Test Plan: Not needed

Reviewed By: cortinico

Differential Revision: D69061022

Pulled By: cipolleschi

fbshipit-source-id: b02a0ff3f26be9320da749f38c9cf083804f9f30
gabrieldonadel pushed a commit to gabrieldonadel/react-native that referenced this pull request Aug 12, 2025
Summary:
Recently, I've introduced `RCTReactNativeFactory` in this PR: facebook#46298, which is a good successor for `RCTAppDelegate`.

### Why?

`RCTAppDelegate` introduced strong coupling between React Native and AppDelegate pattern. From iOS 13+ there is a newer equivalent (Scene Delegate) which is not possible to achieve with current architecture. The proposed solution involves migration to a `RCTReactNativeFactory` a class that encapsulates initialization logic of React Native.

This migration will make brownfield initialization easier by making it more flexible and simpler to integrate into already established apps.

### Deprecation plan

The plan I've discussed with cipolleschi involves:

- Deprecation of `RCTAppDelegate` in 0.79 (current main)
- Migration off `RCTAppDelegate` to SceneDelegate + `RCTReactNativeFactory` in 0.80

## Changelog:

[IOS] [DEPRECATED] - deprecate RCTAppDelegate

Pull Request resolved: facebook#49078

Test Plan: Not needed

Reviewed By: cortinico

Differential Revision: D69061022

Pulled By: cipolleschi

fbshipit-source-id: b02a0ff3f26be9320da749f38c9cf083804f9f30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants