Hello for SwiftUI
This commit is contained in:
parent
14aa6a777b
commit
4e4a92c2a3
5 changed files with 75 additions and 33 deletions
24
ios/Native/Application/RootView.swift
Normal file
24
ios/Native/Application/RootView.swift
Normal file
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// RootView.swift
|
||||
// RNPlayground
|
||||
//
|
||||
// Created by Artur Gurgul on 02/08/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct RootView: View {
|
||||
private let sharedState: SharedState
|
||||
init(_ sharedState: SharedState) {
|
||||
self.sharedState = sharedState
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("Hello to SwiftUI!")
|
||||
if let reactNativeFactory = sharedState.reactNativeFactory {
|
||||
UIReactNativeView(reactNativeFactory)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
ios/Native/Application/SharedState.swift
Normal file
16
ios/Native/Application/SharedState.swift
Normal file
|
@ -0,0 +1,16 @@
|
|||
//
|
||||
// SharedState.swift
|
||||
// RNPlayground
|
||||
//
|
||||
// Created by Artur Gurgul on 02/08/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import React
|
||||
import React_RCTAppDelegate
|
||||
import ReactAppDependencyProvider
|
||||
|
||||
final class SharedState: ObservableObject {
|
||||
var reactNativeFactory: RCTReactNativeFactory?
|
||||
}
|
29
ios/Native/Application/UIReactNativeView.swift
Normal file
29
ios/Native/Application/UIReactNativeView.swift
Normal file
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// UIReactNativeView.swift
|
||||
// RNPlayground
|
||||
//
|
||||
// Created by Artur Gurgul on 01/08/2025.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
import React
|
||||
import React_RCTAppDelegate
|
||||
import ReactAppDependencyProvider
|
||||
|
||||
|
||||
struct UIReactNativeView: UIViewRepresentable {
|
||||
var factory: RCTReactNativeFactory
|
||||
|
||||
init(_ reactNativeFactory: RCTReactNativeFactory) {
|
||||
factory = reactNativeFactory
|
||||
}
|
||||
|
||||
func makeUIView(context: Context) -> UIView {
|
||||
return factory.rootViewFactory.view(withModuleName: "RNPlayground")
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UIView, context: Context) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// 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")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue