diff --git a/ios/Native/UIReactNativeHostingViewController.swift b/ios/Native/UIReactNativeHostingViewController.swift new file mode 100644 index 0000000..fd46ee2 --- /dev/null +++ b/ios/Native/UIReactNativeHostingViewController.swift @@ -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") + } +} diff --git a/ios/RNPlayground/AppDelegate.swift b/ios/RNPlayground/AppDelegate.swift index 9e02cbd..0bbe441 100644 --- a/ios/RNPlayground/AppDelegate.swift +++ b/ios/RNPlayground/AppDelegate.swift @@ -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 {