generated from NativeScript/plugin-seed
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
BasicViewProvider.swift
51 lines (40 loc) · 1.23 KB
/
BasicViewProvider.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
44
45
46
47
48
49
50
51
import UIKit
import SwiftUI
@objc
class BasicViewProvider: UIViewController, SwiftUIProvider {
// MARK: INIT
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
required public init() {
super.init(nibName: nil, bundle: nil)
}
public override func viewDidLoad() {
super.viewDidLoad()
setupSwiftUIView(content: swiftUIView)
registerObservers()
}
// MARK: PRIVATE
private var swiftUIView = BasicView()
private func registerObservers() {
swiftUIView.props.incrementCount = {
let count = self.swiftUIView.props.count + 1
// update swiftUI view
self.swiftUIView.props.count = count
// notify nativescript
self.onEvent?(["count": count])
}
}
// MARK: API
/// Receive data from NativeScript
func updateData(data: NSDictionary) {
if let count = data.value(forKey: "count") as? Int {
// update swiftUI view
swiftUIView.props.count = count
// notify nativescript
self.onEvent?(["count": count])
}
}
/// Send data to NativeScript
var onEvent: ((NSDictionary) -> ())?
}