Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from 0xLeif/develop
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
0xLeif authored Aug 7, 2021
2 parents 7712d2e + 20ca367 commit d410b7f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Sources/ObjectUI/View/ObjectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import SwiftUI

public struct ObjectView<Content>: View where Content: View {
@StateObject private var object: Object = Object()
@ObservedObject private var object: Object

private var content: (Object) -> Content
private let content: (Object) -> Content

public init(
data: Any? = nil,
content: @escaping (Object) -> Content
@ViewBuilder content: @escaping (Object) -> Content
) {
self.object = Object(data)
self.content = content
self.object.consume(Object(data))
}

public var body: some View {
Expand All @@ -28,8 +28,11 @@ public struct ObjectView<Content>: View where Content: View {
struct ObjectView_Previews: PreviewProvider {
static var previews: some View {
ObjectView(data: "Hello, World 👋") { object in
object.value(as: String.self).map { message in
Text(message)
if let text = object.value(as: String.self) {
Text(text)
} else {
ProgressView()

}
}
}
Expand Down
41 changes: 41 additions & 0 deletions Sources/ObjectUI/View/StateObjectView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// ObjectView.swift
// ObjectUI
//
// Created by Leif on 5/24/21.
//

import SwiftUI

public struct StateObjectView<Content>: View where Content: View {
@StateObject private var object: Object = Object()

private let content: (Object) -> Content

public init(
@ViewBuilder content: @escaping (Object) -> Content
) {
self.content = content
}

public var body: some View {
content(object)
}
}

struct StateObjectView_Previews: PreviewProvider {
static var previews: some View {
StateObjectView { object in
if let text = object.value(as: String.self) {
Text(text)
} else {
ProgressView()
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
object.set(value: "👋")
}
}
}
}
}
}

0 comments on commit d410b7f

Please sign in to comment.