Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow use of RCTRootViewFactory from Swift #43590

Conversation

okwasniewski
Copy link
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

@main
class AppDelegate: NSObject, UIApplicationDelegate {
  var window: UIWindow?
  private var rootViewFactory: RCTRootViewFactory?
  
  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
  ) -> Bool {
   
    // Create config
    let config = RCTRootViewFactoryConfiguration(
      bundleURL: self.bundleURL(),
      newArchEnabled: true,
      turboModuleEnabled: true,
      bridgelessEnabled: false
    )
    
    // Create rootview factory
    rootViewFactory = RCTRootViewFactory(configuration: config)
    
    // Create rootview
    let rootView = rootViewFactory?.view(withModuleName: "RN0740RC4")
    let rootViewController = UIViewController()
    rootViewController.view = rootView
    
    // Create window and assign view controller
    window = UIWindow(frame: UIScreen.main.bounds)
    window?.rootViewController = rootViewController;
    window?.makeKeyAndVisible()
    
    return true
  }
  
  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-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 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
Copy link

analysis-bot commented Mar 21, 2024

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,385,121 +5
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,760,089 +6
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 44d59ea
Branch: main

@okwasniewski
Copy link
Contributor Author

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

@cipolleschi
Copy link
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 okwasniewski force-pushed the feat/RCTRootViewFactory-brownfield branch from 42a68f1 to 3e17ce1 Compare April 11, 2024 07:38
@okwasniewski
Copy link
Contributor Author

Hey @cipolleschi thanks for reviewing - rebased

@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 Apr 12, 2024
@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in 5aea518.

Copy link

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 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