Add hosting view controller for RN Root View
This commit is contained in:
parent
9829024b2c
commit
14aa6a777b
2 changed files with 44 additions and 6 deletions
29
ios/Native/UIReactNativeHostingViewController.swift
Normal file
29
ios/Native/UIReactNativeHostingViewController.swift
Normal 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")
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue