Skip to content

Commit 4303fb5

Browse files
committed
chore: setup
1 parent fc1454f commit 4303fb5

22 files changed

+231
-18938
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
hooks/
33
node_modules/
44
platforms/
5+
package-lock.json
56

67
# Logs
78
logs

‎App_Resources/iOS/build.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
// To build for device with XCode you need to specify your development team.
55
// DEVELOPMENT_TEAM = YOUR_TEAM_ID;
66
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
7+
IPHONEOS_DEPLOYMENT_TARGET = 15.0;

‎App_Resources/iOS/src/Card.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import SwiftUI
2+
3+
class Data: ObservableObject {
4+
@Published var props: NSMutableDictionary = [:]
5+
var toggle: ((_ showing: Bool) -> Void)?
6+
}
7+
8+
struct Card : View {
9+
@State var show = false
10+
@ObservedObject var data = Data()
11+
12+
var body: some View {
13+
Button(action: {
14+
withAnimation {
15+
self.show.toggle()
16+
data.toggle!(self.show)
17+
}
18+
}) {
19+
let cardBackgroundColor = data.props.value(forKey: "cardBackgroundColor") as? UIColor
20+
21+
VStack() {
22+
let titleColor = data.props.value(forKey: "titleColor") as? UIColor
23+
Text(data.props.value(forKey: "title") as? String ?? "Learn SwiftUI")
24+
.foregroundColor((titleColor != nil) ? Color(titleColor!) : .white)
25+
.fontWeight(.bold)
26+
.font(.largeTitle)
27+
.padding(.top, show ? 100 : 20)
28+
29+
let descColor = data.props.value(forKey: "descColor") as? UIColor
30+
Text(data.props.value(forKey: "desc") as? String ?? "with NativeScript")
31+
.foregroundColor((descColor != nil) ? Color(descColor!) : Color(hue: 0.567, saturation: 0.158, brightness: 0.943))
32+
.lineLimit(-1)
33+
34+
AsyncImage(url: URL(string: "https://electreefrying.gallerycdn.vsassets.io/extensions/electreefrying/nativescript-angular-html-snippets/0.1.4/1595675332745/Microsoft.VisualStudio.Services.Icons.Default")) { image in
35+
image
36+
.resizable()
37+
.scaledToFit()
38+
.frame(width: 120, height: 120)
39+
} placeholder: {
40+
Color.gray.opacity(0.1)
41+
}
42+
43+
Spacer()
44+
45+
let subTitleColor = data.props.value(forKey: "subTitleColor") as? UIColor
46+
Text(data.props.value(forKey: "subTitle") as? String ?? "Give me a gentle touch")
47+
.foregroundColor((subTitleColor != nil) ? Color(subTitleColor!) : Color(hue: 0.498, saturation: 0.609, brightness: 1.0))
48+
.fontWeight(.bold)
49+
.font(.title)
50+
.padding(.bottom, show ? 100 : 20)
51+
}
52+
.padding()
53+
.frame(width: show ? 414 : 300, height: show ? 950 : 300)
54+
.background((cardBackgroundColor != nil) ? Color(cardBackgroundColor!) : .blue)
55+
}
56+
.cornerRadius(30)
57+
.animation(.spring())
58+
.shadow(radius: 30)
59+
}
60+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import SwiftUI
2+
3+
@objc
4+
class CardProvider: UIViewController, SwiftUIProvider {
5+
6+
// MARK: INIT
7+
8+
required init?(coder aDecoder: NSCoder) {
9+
super.init(coder: aDecoder)
10+
}
11+
12+
required public init() {
13+
super.init(nibName: nil, bundle: nil)
14+
}
15+
16+
public override func viewDidLoad() {
17+
super.viewDidLoad()
18+
setupSwiftUIView(content: swiftUIView)
19+
registerObservers()
20+
}
21+
22+
// MARK: PRIVATE
23+
24+
private var swiftUIView = Card()
25+
26+
private func registerObservers() {
27+
swiftUIView.data.toggle = { (showing: Bool) in
28+
// notify NativeScript
29+
self.onEvent?(["showing": showing])
30+
}
31+
}
32+
33+
/// Receive data from NativeScript
34+
func updateData(data: NSDictionary) {
35+
data.forEach { (k,v) in swiftUIView.data.props[k] = v }
36+
}
37+
38+
/// Allow sending of data to NativeScript
39+
var onEvent: ((NSDictionary) -> ())?
40+
}

‎README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SwiftUI with NativeScript Example
2+
3+
```
4+
ns debug ios
5+
```
6+
7+
Demonstrates:
8+
- @nativescript/swift-ui usage
9+
- HMR livesync changes to SwiftUI
10+
- Flexible data binding setup to SwiftUI from NativeScript

0 commit comments

Comments
 (0)