Add hosting view controller for RN Root View

This commit is contained in:
Artur Gurgul 2025-08-01 21:02:00 +02:00
parent 9829024b2c
commit 14aa6a777b
2 changed files with 44 additions and 6 deletions

View file

@ -0,0 +1,29 @@
//
// UIReactNativeHostingViewController.swift
// RNPlayground
//
// Created by Artur Gurgul on 01/08/2025.
//
import UIKit
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
class UIReactNativeHostingViewController: UIViewController {
var factory: RCTReactNativeFactory
init(_ reactNativeFactory: RCTReactNativeFactory) {
self.factory = reactNativeFactory
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func loadView() {
view = factory.rootViewFactory.view(withModuleName: "RNPlayground")
}
}

View file

@ -22,15 +22,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
reactNativeFactory = factory
window = UIWindow(frame: UIScreen.main.bounds)
factory.startReactNative(
withModuleName: "RNPlayground",
in: window,
launchOptions: launchOptions
)
startNativeApp()
// factory.startReactNative(
// withModuleName: "RNPlayground",
// in: window,
// launchOptions: launchOptions
// )
return true
}
func startNativeApp() {
guard let window, let reactNativeFactory else {
return
}
window.rootViewController = UIReactNativeHostingViewController(reactNativeFactory)
window.makeKeyAndVisible()
}
}
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {