Skip to content

feat: allow use of RCTRootViewFactory from Swift - #43590

Closed
okwasniewski wants to merge 1 commit into
react:mainfrom
okwasniewski:feat/RCTRootViewFactory-brownfield
Closed

feat: allow use of RCTRootViewFactory from Swift#43590
okwasniewski wants to merge 1 commit into
react:mainfrom
okwasniewski:feat/RCTRootViewFactory-brownfield

Conversation

@okwasniewski

Copy link
Copy Markdown
Contributor

Summary:

The goal of this PR is to allow the usage of RCTRootViewFactory from Swift. The issue with RCTTurboModuleManager.h is that it uses C++ in its header file, which is not allowed in Swift, making this initializer unavailable.

This PR allows users to just pass configuration + adds a nullable annotation to bundleURL.

Example usage:

import Foundation
import UIKit
import React
import React_RCTAppDelegate
@mainclassAppDelegate:NSObject,UIApplicationDelegate{varwindow:UIWindow?privatevarrootViewFactory:RCTRootViewFactory?func application(
_ application:UIApplication,
didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey:Any]?=nil)->Bool{
// Create config
letconfig=RCTRootViewFactoryConfiguration(
bundleURL:self.bundleURL(),
newArchEnabled:true,
turboModuleEnabled:true,
bridgelessEnabled:false)
// Create rootview factory
rootViewFactory =RCTRootViewFactory(configuration: config)
// Create rootview
letrootView= rootViewFactory?.view(withModuleName:"RN0740RC4")letrootViewController=UIViewController()
rootViewController.view = rootView
// Create window and assign view controller
window =UIWindow(frame:UIScreen.main.bounds)
window?.rootViewController = rootViewController;
window?.makeKeyAndVisible()returntrue}func bundleURL()->URL?{RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot:"index")}}

Changelog:

[IOS] [FIXED] - Allow usage of RCTRootViewFactory from Swift

Test Plan:

CI Green, check usage of initializer without turbo module delegate

@facebook-github-botfacebook-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 Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Mar 21, 2024
@analysis-bot

analysis-bot commented Mar 21, 2024

Copy link
Copy Markdown
PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a19,385,121+5
androidhermesarmeabi-v7an/a--
androidhermesx86n/a--
androidhermesx86_64n/a--
androidjscarm64-v8a22,760,089+6
androidjscarmeabi-v7an/a--
androidjscx86n/a--
androidjscx86_64n/a--

Base commit: 44d59ea
Branch: main

@okwasniewski

Copy link
Copy Markdown
ContributorAuthor

Hey @cipolleschi could you take a look at this? 🙏

@cipolleschi

Copy link
Copy Markdown
Contributor

Changes looks good to me, but we had to fix a couple of things that conflicts with the RCTRootViewFactory. Can you rebase on top of main and fix the conflicts?

@okwasniewski
okwasniewskiforce-pushed the feat/RCTRootViewFactory-brownfield branch from 42a68f1 to 3e17ce1CompareApril 11, 2024 07:38
@okwasniewski

Copy link
Copy Markdown
ContributorAuthor

Hey @cipolleschi thanks for reviewing - rebased

@facebook-github-bot

Copy link
Copy Markdown
Contributor

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

@facebook-github-botfacebook-github-bot added the Merged This PR has been merged. label Apr 12, 2024
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@cipolleschi merged this pull request in 5aea518.

@github-actions

Copy link
Copy Markdown

This pull request was successfully merged by @okwasniewski in 5aea518.

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

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.MergedThis PR has been merged.p: CallstackPartner: CallstackPartnerShared with MetaApplied 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

@okwasniewski@analysis-bot@cipolleschi@facebook-github-bot