Skip to content

Commit

Permalink
SwiftUI bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Usbergo committed Dec 1, 2019
1 parent 2969d20 commit d8c439b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repositoryURL": "https://github.com/alexdrone/Render",
"state": {
"branch": "master",
"revision": "a610de390578501b5208b06ddef204ece84dd9d2",
"revision": "2969d20a67d52efe1a88ff557ca20133383cb301",
"version": null
}
}
Expand Down
2 changes: 1 addition & 1 deletion Demo/CoreRenderDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var useSwiftUI = true
var useSwiftUI = false
var window: UIWindow?

func scene(
Expand Down
35 changes: 24 additions & 11 deletions Demo/CoreRenderDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,34 @@ import CoreRender
import Render

struct ContentView: View {
var body: some View {
VStack {
Text("Hello World")
CoreRenderBridgeView { context in
VStackNode {
LabelNode(text: "Hello World")
EmptyNode()
}
var body: some View {
VStack {
Text("Hello From SwiftUI")
CoreRenderBridgeView { context in
VStackNode {
LabelNode(text: "Hello")
.font(UIFont.boldSystemFont(ofSize: 12))
.textAlignment(.center)
.padding(8)
LabelNode(text: "From")
.textAlignment(.center)
.font(UIFont.boldSystemFont(ofSize: 12))
.padding(8)
LabelNode(text: "CoreRender")
.textAlignment(.center)
.font(UIFont.boldSystemFont(ofSize: 14))
.padding(8)
}
.alignItems(.center)
.background(UIColor.systemGroupedBackground)
.matchHostingViewWidth(withMargin: 0)
}
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
static var previews: some View {
ContentView()
}
}
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ func makeFragment(context: Context) {

```

### Use it with SwiftUI

Render nodes can be nested inside SwiftUI bodies by using `CoreRenderBridgeView`:
```swift

struct ContentView: View {
var body: some View {
VStack {
Text("Hello From SwiftUI")
CoreRenderBridgeView { context in
VStackNode {
LabelNode(text: "Hello")
LabelNode(text: "From")
LabelNode(text: "CoreRender")
}
.alignItems(.center)
.background(UIColor.systemGroupedBackground)
.matchHostingViewWidth(withMargin: 0)
}
Text("Back to SwiftUI")
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

```

# Credits:
Layout engine:

Expand Down

0 comments on commit d8c439b

Please sign in to comment.