react-native/ios/RNPlayground/AppDelegate.swift
2025-08-02 13:00:06 +02:00

59 lines
1.5 KiB
Swift

import UIKit
import SwiftUI
import React
import React_RCTAppDelegate
import ReactAppDependencyProvider
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var reactNativeDelegate: ReactNativeDelegate?
private let sharedState = SharedState()
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
let delegate = ReactNativeDelegate()
let factory = RCTReactNativeFactory(delegate: delegate)
delegate.dependencyProvider = RCTAppDependencyProvider()
reactNativeDelegate = delegate
sharedState.reactNativeFactory = factory
window = UIWindow(frame: UIScreen.main.bounds)
startNativeApp()
// factory.startReactNative(
// withModuleName: "RNPlayground",
// in: window,
// launchOptions: launchOptions
// )
return true
}
func startNativeApp() {
guard let window, sharedState.reactNativeFactory != nil else {
return
}
window.rootViewController = UIHostingController(rootView: RootView(sharedState))
window.makeKeyAndVisible()
}
}
class ReactNativeDelegate: RCTDefaultReactNativeFactoryDelegate {
override func sourceURL(for bridge: RCTBridge) -> URL? {
self.bundleURL()
}
override func bundleURL() -> URL? {
#if DEBUG
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
#else
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
#endif
}
}