Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f040174
Update ViewFactory
Kyle-Ye Jul 27, 2025
9ac59fc
Update PlatformViewCoordinator
Kyle-Ye Jul 27, 2025
397a9d4
Add PlatformViewHost interface
Kyle-Ye Jul 27, 2025
c50ff8f
Add PlatformViewRepresentableContext
Kyle-Ye Jul 27, 2025
de97fec
Add ViewLeafView and PlatformViewLayoutEngine
Kyle-Ye Aug 10, 2025
07dadc9
Add LeafLayoutEnvironment
Kyle-Ye Aug 10, 2025
a3f0392
Add InvalidatableLeafLayoutComputer
Kyle-Ye Aug 10, 2025
a16853f
Add PlatformViewDisplayList
Kyle-Ye Aug 10, 2025
86152d5
Update ViewLeafView
Kyle-Ye Aug 10, 2025
f804dbb
Add PlatformArchivedDisplayList
Kyle-Ye Aug 10, 2025
5dda9d7
Add PlatformViewChild support
Kyle-Ye Aug 10, 2025
fd65559
Add PlatformViewRepresentable._makeView
Kyle-Ye Aug 10, 2025
5e30f9c
Fix invalid value type for attribute issue
Kyle-Ye Aug 10, 2025
fed4da0
Add PlatformConstraintBasedLayoutHostingView
Kyle-Ye Aug 10, 2025
28816ef
Add makePlatformView
Kyle-Ye Aug 10, 2025
504dcd7
Update headers
Kyle-Ye Aug 10, 2025
986675e
Add SafeAreaHelper interface
Kyle-Ye Aug 10, 2025
1be4e28
Update PlatformViewHost
Kyle-Ye Aug 10, 2025
3f64d20
Update PlatformViewLayoutEngine
Kyle-Ye Aug 10, 2025
b806d34
Update PlatformViewHost init
Kyle-Ye Aug 10, 2025
a791a9f
Add PlatformViewRepresentableUITests
Kyle-Ye Aug 10, 2025
d69000c
Update PlatformViewHost for macOS
Kyle-Ye Aug 10, 2025
4f44d7c
Add NSViewRepresentable and update UIViewRepresentable
Kyle-Ye Aug 10, 2025
58a8f49
Fix Linux platform build issue
Kyle-Ye Aug 10, 2025
28d8c2b
Update UIViewControllerRepresentable
Kyle-Ye Aug 10, 2025
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
2 changes: 1 addition & 1 deletion Example/HostingExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ class ViewController: NSViewController {

struct ContentView: View {
var body: some View {
SpringAnimationExample()
ColorRepresentableExample()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// PlatformViewRepresentableUITests.swift
// OpenSwiftUIUITests

import Testing
import SnapshotTesting

#if os(iOS)
import UIKit
typealias PlatformViewRepresentable = UIViewRepresentable
#elseif os(macOS)
import AppKit
typealias PlatformViewRepresentable = NSViewRepresentable
#endif

@MainActor
@Suite(.snapshots(record: .never, diffTool: diffTool))
struct PlatformViewRepresentableUITests {
@Test
func plainColorView() {
struct PlainColorView: PlatformViewRepresentable {
#if os(iOS)
func makeUIView(context: Context) -> some UIView {
let v = UIView()
v.backgroundColor = .red
return v
}

func updateUIView(_ uiView: UIViewType, context: Context) {}
#elseif os(macOS)
func makeNSView(context: Context) -> some NSView {
let v = NSView()
v.wantsLayer = true
v.layer?.backgroundColor = NSColor.red.cgColor
return v
}

func updateNSView(_ uiView: NSViewType, context: Context) {}
#endif
}
struct ContentView: View {
var body: some View {
PlainColorView()
}
}
openSwiftUIAssertSnapshot(of: ContentView())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ColorRepresentable.swift
// SharedExample

#if OPENSWIFTUI
import OpenSwiftUI
#else
import SwiftUI
#endif

#if os(iOS)
import UIKit
typealias PlatformViewRepresentable = UIViewRepresentable
#elseif os(macOS)
import AppKit
typealias PlatformViewRepresentable = NSViewRepresentable
#endif

struct ColorRepresentableExample: PlatformViewRepresentable {
#if os(iOS)
func makeUIView(context: Context) -> some UIView {
let v = UIView()
v.backgroundColor = .red
return v
}

func updateUIView(_ uiView: UIViewType, context: Context) {}
#elseif os(macOS)
func makeNSView(context: Context) -> some NSView {
let v = NSView()
v.wantsLayer = true
v.layer?.backgroundColor = NSColor.red.cgColor
return v
}

func updateNSView(_ uiView: NSViewType, context: Context) {}
#endif
}
8 changes: 8 additions & 0 deletions Sources/OpenSwiftUI/Event/Focus/FocusedValueKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Status: WIP

import OpenSwiftUICore
import OpenGraphShims

@available(OpenSwiftUI_v2_0, *)
@propertyWrapper
Expand Down Expand Up @@ -99,3 +100,10 @@ extension FocusedValues: Equatable {
lhs.seed.matches(rhs.seed)
}
}

// FIXME
struct FocusedValuesInputKey: ViewInput {
static var defaultValue: OptionalAttribute<FocusedValues> {
.init()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,17 @@ final class NSViewPlatformViewDefinition: PlatformViewDefinition, @unchecked Sen
override static func makeLayerView(type: CALayer.Type, kind: PlatformViewDefinition.ViewKind) -> AnyObject {
_openSwiftUIUnimplementedFailure()
}

override class func makePlatformView(view: AnyObject, kind: PlatformViewDefinition.ViewKind) {
Self.initView(view as! NSView, kind: kind)
}

override class func setAllowsWindowActivationEvents(_ value: Bool?, for view: AnyObject) {
_openSwiftUIUnimplementedWarning()
}

override class func setHitTestsAsOpaque(_ value: Bool, for view: AnyObject) {
_openSwiftUIUnimplementedWarning()
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ final class UIViewPlatformViewDefinition: PlatformViewDefinition, @unchecked Sen
break
}
}

override class func makePlatformView(view: AnyObject, kind: PlatformViewDefinition.ViewKind) {
Self.initView(view as! UIView, kind: kind)
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// NSViewControllerRepresentable.swift
// OpenSwiftUI

// TODO
package struct NSViewControllerRepresentable {}
Loading
Loading