-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathReactNativeView.swift
43 lines (37 loc) · 1.22 KB
/
ReactNativeView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import SwiftUI
/**
A UIViewControllerRepresentable that bridges ReactNativeViewController to SwiftUI.
*/
struct ReactNativeViewRepresentable: UIViewControllerRepresentable {
var moduleName: String
var initialProperties: [String: Any] = [:]
func makeUIViewController(context: Context) -> UIViewController {
return ReactNativeViewController(moduleName: moduleName)
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
/**
Exposes React Native view to SwiftUI.
Supports pop to native when using SwiftUI's NavigationView or NavigationStack.
*/
@available(iOS 15.0, *)
public struct ReactNativeView: View {
@Environment(\.dismiss) var dismiss
var moduleName: String
var initialProperties: [String: Any] = [:]
public init(moduleName: String, initialProperties: [String : Any] = [:]) {
self.moduleName = moduleName
self.initialProperties = initialProperties
}
public var body: some View {
ReactNativeViewRepresentable(
moduleName: moduleName,
initialProperties: initialProperties
)
.ignoresSafeArea(.all)
.onReceive(NotificationCenter.default.publisher(for: NSNotification.Name.popToNative))
{ notification in
dismiss()
}
}
}