@@ -2,11 +2,61 @@ import BrownfieldLib
22import Brownie
33import ReactBrownfield
44import SwiftUI
5+ import UIKit
56
67class AppDelegate : NSObject , UIApplicationDelegate {
78 var window : UIWindow ?
89}
910
11+ public class RNNavigationDelegate : BrownfieldNavigationDelegate {
12+ public func navigateToSettings( ) {
13+ present ( SettingsScreen ( ) )
14+ }
15+
16+ public func navigateToReferrals( userId: String ) {
17+ present ( ReferralsScreen ( userId: userId) )
18+ }
19+
20+ private func present< Content: View > ( _ view: Content ) {
21+ DispatchQueue . main. async {
22+ let hostingController = UIHostingController ( rootView: view)
23+
24+ guard let topController = UIApplication . shared. topMostViewController ( ) else {
25+ return
26+ }
27+
28+ if let navigationController = topController. navigationController {
29+ navigationController. pushViewController ( hostingController, animated: true )
30+ return
31+ }
32+
33+ let navigationController = UINavigationController ( rootViewController: hostingController)
34+ topController. present ( navigationController, animated: true )
35+ }
36+ }
37+ }
38+
39+ private extension UIApplication {
40+ func topMostViewController(
41+ base: UIViewController ? = UIApplication . shared. connectedScenes
42+ . compactMap { $0 as? UIWindowScene }
43+ . flatMap { $0. windows }
44+ . first ( where: { $0. isKeyWindow } ) ? . rootViewController
45+ ) -> UIViewController ? {
46+ if let navigationController = base as? UINavigationController {
47+ return topMostViewController ( base: navigationController. visibleViewController)
48+ }
49+ if let tabBarController = base as? UITabBarController ,
50+ let selected = tabBarController. selectedViewController {
51+ return topMostViewController ( base: selected)
52+ }
53+ if let presented = base? . presentedViewController {
54+ return topMostViewController ( base: presented)
55+ }
56+ return base
57+ }
58+ }
59+
1060@main
1161struct BrownfieldAppleApp : App {
1262 @UIApplicationDelegateAdaptor ( AppDelegate . self) var appDelegate
@@ -16,6 +66,21 @@ struct BrownfieldAppleApp: App {
1666 ReactNativeBrownfield . shared. startReactNative {
1767 print ( " React Native has been loaded " )
1868 }
69+
70+ // let mgr = ReactBrownfield.BrownfieldNavigationManager.shared
71+ // print("SWIFT mgr:", Unmanaged.passUnretained(mgr).toOpaque())
72+ // print("SWIFT class:", NSStringFromClass(type(of: mgr)))
73+ // print("SWIFT bundle:", Bundle(for: ReactBrownfield.BrownfieldNavigationManager.self).bundlePath)
74+ // ReactBrownfield.BrownfieldNavigationManager.shared.setDelegate(navigationDelegate: RNNavigationDelegate())
75+
76+ let mgr = BrownfieldNavigationManager . shared
77+ print ( " 11 SWIFT mgr: " , Unmanaged . passUnretained ( mgr) . toOpaque ( ) )
78+ print ( " 11 SWIFT class: " , NSStringFromClass ( type ( of: mgr) ) )
79+ print ( " 11 SWIFT bundle: " , Bundle ( for: BrownfieldNavigationManager . self) . bundlePath)
80+
81+ mgr. setDelegate (
82+ navigationDelegate: RNNavigationDelegate ( )
83+ )
1984
2085 BrownfieldStore . register ( initialState)
2186 }
0 commit comments