Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions Example/HostingExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,61 @@ import SwiftUI

class ViewController: UINavigationController {
override func viewDidAppear(_ animated: Bool) {
let vc = UIHostingController(rootView: ContentView())
pushViewController(vc, animated: false)
pushViewController(EntryViewController(), animated: false)
}
}

final class EntryViewController: UIViewController {
override func viewDidLoad() {
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "Push",
style: .plain,
target: self,
action: #selector(pushHostingVC)
)
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.pushHostingVC()
}
}

@objc
private func pushHostingVC() {
guard let navigationController else { return }
let hostingVC = UIHostingController(rootView: ContentView())
navigationController.pushViewController(hostingVC, animated: true)
}
}

// TODO: Known issue
// 1. State toggle crash
// 2. pop - UIHostingView deinit crash / onDisappear
// 3. if else builder issue
struct ContentView: View {
@State private var first = true

var body: some View {
AnyView(EmptyView())
if first {
Color.red
.onAppear {
print("Red appear")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
first.toggle()
}
}
.onDisappear {
print("Red disappear")
}
} else {
Color.blue
.onAppear {
print("Blue appear")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
first.toggle()
}
}
.onDisappear {
print("Blue disappear")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ extension _SceneModifier {
extension _SceneModifier where Body == Never {
@inline(__always)
public func body(content _: SceneContent) -> Body {
preconditionFailure("body() should not be called on \(Self.self)")
preconditionFailure("body() should not be called on \(Self.self).")
}
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Scene/Core/Scene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ extension Never: Scene {}

extension Scene {
func sceneBodyError() -> Never {
preconditionFailure("body() should not be called on \(Self.self)")
preconditionFailure("body() should not be called on \(Self.self).")
}
}
34 changes: 28 additions & 6 deletions Sources/OpenSwiftUICore/Graphic/Color/ColorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,39 @@
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Empty
// Status: Empty

@MainActor
@preconcurrency
package struct ColorView: PrimitiveView { //FIXME
package import Foundation

package struct ColorView: RendererLeafView, Animatable {
package var color: Color.Resolved

package init(_ color: Color.Resolved) {
self.color = color
}

@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
package typealias Body = Swift.Never
nonisolated package static func _makeView(view: _GraphValue<ColorView>, inputs: _ViewInputs) -> _ViewOutputs {
var inputs = inputs
if inputs.base.options.isEmpty {
// TODO: AnimatableAttribute
}
return makeLeafView(view: view, inputs: inputs)
}

package var descriptionAttributes: [(name: String, value: String)] {
preconditionFailure("TODO")
}

package func contains(points: [PlatformPoint], size: CGSize) -> BitVector64 {
preconditionFailure("TODO")
}

package func content() -> DisplayList.Content.Value {
preconditionFailure("TODO")
}

package var animatableData: Color.Resolved.AnimatableData {
get { color.animatableData }
set { color.animatableData = newValue }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ extension ViewModifier where Self: _GraphInputsModifier, Body == Never {

extension ViewModifier {
func bodyError() -> Never {
preconditionFailure("body() should not be called on \(Self.self)")
preconditionFailure("body() should not be called on \(Self.self).")
}
}

Expand Down
28 changes: 28 additions & 0 deletions Sources/OpenSwiftUICore/Render/RendererLeafView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// RendererLeafView.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: WIP

import Foundation

package protocol RendererLeafView: /*ContentResponder,*/ PrimitiveView, UnaryView {
static var requiresMainThread: Bool { get }
func content() -> DisplayList.Content.Value
}

extension RendererLeafView {
package static var requiresMainThread: Swift.Bool {
false
}

func contains(points: [PlatformPoint], size: CGSize) -> BitVector64 {
preconditionFailure("TODO")
}

package static func makeLeafView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
// preconditionFailure("TODO")
_ViewOutputs()
}
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/View/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extension PrimitiveView {

extension View {
package func bodyError() -> Never {
preconditionFailure("body() should not be called on \(Self.self)")
preconditionFailure("body() should not be called on \(Self.self).")
}
}

Expand Down
15 changes: 11 additions & 4 deletions Sources/OpenSwiftUICore/View/ViewBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
//
// ViewBuilder.swift
// OpenSwiftUI
// OpenSwiftUICore
//
// Audited for RELEASE_2023
// Audited for iOS 18.0
// Status: Complete

@resultBuilder
public enum ViewBuilder {
public struct ViewBuilder {
@_alwaysEmitIntoClient
public static func buildExpression<Content>(_ content: Content) -> Content where Content: View {
content
}

@available(*, unavailable, message: "this expression does not conform to 'View'")
@_disfavoredOverload
@_alwaysEmitIntoClient
public static func buildExpression(_ invalid: Any) -> some View {
fatalError()
}

@_alwaysEmitIntoClient
public static func buildBlock() -> EmptyView {
Expand All @@ -30,7 +37,7 @@ public enum ViewBuilder {
}

@available(*, unavailable)
extension ViewBuilder: Swift.Sendable {}
extension ViewBuilder: Sendable {}

extension ViewBuilder {
@_alwaysEmitIntoClient
Expand Down
Loading