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
85 changes: 50 additions & 35 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ let swiftLogCondition = envEnable("OPENSWIFTUI_SWIFT_LOG", default: !buildForDar

let swiftCryptoCondition = envEnable("OPENSWIFTUI_SWIFT_CRYPTO", default: !buildForDarwinPlatform)

// MARK: - [env] OPENSWIFTUI_RENDER_GTK

let renderGTKCondition = envEnable("OPENSWIFTUI_RENDER_GTK", default: !buildForDarwinPlatform)

let cgtkTarget = Target.systemLibrary(
name: "CGTK",
pkgConfig: "gtk4",
providers: [
.brew(["gtk4"]),
.apt(["libgtk-4-dev clang"]),
]
)

// MARK: - [env] OPENGSWIFTUI_SWIFTUI_RENDER

let swiftUIRenderCondition = envEnable("OPENSWIFTUI_SWIFTUI_RENDER", default: buildForDarwinPlatform)
Expand Down Expand Up @@ -153,9 +166,10 @@ if libraryEvolutionCondition && !openCombineCondition && !swiftLogCondition {
// MARK: - [env] OPENSWIFTUI_COMPATIBILITY_TEST

let compatibilityTestCondition = envEnable("OPENSWIFTUI_COMPATIBILITY_TEST")

if compatibilityTestCondition {
sharedSwiftSettings.append(.define("OPENSWIFTUI_COMPATIBILITY_TEST"))
sharedCSettings.append(.define("OPENSWIFTUI", to: compatibilityTestCondition ? "0" : "1"))
sharedCxxSettings.append(.define("OPENSWIFTUI", to: compatibilityTestCondition ? "0" : "1"))
if !compatibilityTestCondition {
sharedSwiftSettings.append(.define("OPENSWIFTUI"))
}

// MARK: - [env] OPENSWIFTUI_IGNORE_AVAILABILITY
Expand Down Expand Up @@ -268,6 +282,8 @@ let openSwiftUITestsSupportTarget = Target.target(
dependencies: [
"OpenSwiftUI",
],
cSettings: sharedCSettings,
cxxSettings: sharedCxxSettings,
swiftSettings: sharedSwiftSettings
)

Expand Down Expand Up @@ -396,36 +412,48 @@ let package = Package(
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.3"),
],
targets: [
// TODO: Add SwiftGTK as an backend alternative for UIKit/AppKit on Linux and macOS
.systemLibrary(
name: "CGTK",
pkgConfig: "gtk4",
providers: [
.brew(["gtk4"]),
.apt(["libgtk-4-dev clang"]),
]
),
coreGraphicsShimsTarget,
coreGraphicsShimsTestTarget,

openSwiftUISPITarget,
openSwiftUISPITestTarget,

openSwiftUICoreTarget,
openSwiftUICoreTestTarget,

cOpenSwiftUITarget,
openSwiftUITarget,
openSwiftUITestsSupportTarget,
openSwiftUIExtensionTarget,
openSwiftUITestTarget,
openSwiftUICompatibilityTestTarget,

openSwiftUIBridgeTarget,
openSwiftUIBridgeTestTarget,
]
)

if renderGTKCondition {
package.targets.append(cgtkTarget)
}

if !compatibilityTestCondition {
package.targets.append(contentsOf: [
coreGraphicsShimsTestTarget,
openSwiftUISPITestTarget,
openSwiftUICoreTestTarget,
openSwiftUITestTarget,
openSwiftUIBridgeTestTarget,
])
}

if buildForDarwinPlatform {
package.targets.append(openSwiftUICompatibilityTestTarget)
}

// MARK: - SymbolLocator

if symbolLocatorCondition {
package.dependencies.append(
.package(url: "https://github.com/OpenSwiftUIProject/SymbolLocator.git", from: "0.2.0")
)

package.targets += [
openSwiftUISymbolDualTestsSupportTarget,
openSwiftUISymbolDualTestsTarget,
]
}

extension Target {
func addAGSettings() {
// FIXME: Weird SwiftPM behavior for test Target. Otherwize we'll get the following error message
Expand Down Expand Up @@ -557,19 +585,6 @@ if swiftCryptoCondition {
openSwiftUITarget.addSwiftCryptoSettings()
}

// MARK: - SymbolLocator

if symbolLocatorCondition {
package.dependencies.append(
.package(url: "https://github.com/OpenSwiftUIProject/SymbolLocator.git", from: "0.2.0")
)

package.targets += [
openSwiftUISymbolDualTestsSupportTarget,
openSwiftUISymbolDualTestsTarget,
]
}

extension [Platform] {
static var darwinPlatforms: [Platform] {
[.macOS, .iOS, .macCatalyst, .tvOS, .watchOS, .visionOS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,9 @@ open class NSHostingController<Content>: NSViewController where Content: View {
return result
}


public func _forEachIdentifiedView(body: (_IdentifiedViewProxy) -> Void) {
host.forEachIdentifiedView(body: body)
}


}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ open class _UIHostingView<Content>: UIView, XcodeViewDebugDataProvider where Con
UIEdgeInsets(top: explicitSafeAreaInsets.top, left: explicitSafeAreaInsets.leading, bottom: explicitSafeAreaInsets.bottom, right: explicitSafeAreaInsets.trailing)
}
}


override dynamic open func sizeThatFits(_ size: CGSize) -> CGSize {
base._layoutSizeThatFits(size)
}

// FIXME
final public func _viewDebugData() -> [_ViewDebug.Data] {
// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ package class UIHostingViewBase {
}
}

func _layoutSizeThatFits(
_ size: CGSize
// fixedAxes: _UILayoutAxes
) -> CGSize {
guard let host else {
return .zero
}
let maxValue = 2777780.0
let fittingSize = host.sizeThatFits(.init(
width: size.width >= maxValue ? nil : size.width,
height: size.height >= maxValue ? nil : size.height
))
let pixelLength = host.viewGraph.environment.pixelLength
return fittingSize.rounded(.up, toMultipleOf: pixelLength)
}

// func _baselineOffsets(at: CGSize) -> _UIBaselineOffsetPair

// MARK: - Update
Expand Down
36 changes: 34 additions & 2 deletions Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,42 @@ extension ViewGraph {

//package typealias SizeThatFitsObservers = ViewGraphGeometryObservers<SizeThatFitsMeasurer>
extension ViewGraph {
private var layoutComputer: LayoutComputer? {
guard requestedOutputs.contains(.layout) else {
preconditionFailure("Cannot fetch layout computer without layout output")
}
instantiateIfNeeded()
return rootLayoutComputer
}

private var rootViewInsets: EdgeInsets {
guard !safeAreaInsets.elements.isEmpty else {
return .zero
}
// FIXME
return .zero
}

static func sizeThatFits(
_ proposal: _ProposedSize,
layoutComputer: LayoutComputer?,
insets: EdgeInsets
) -> CGSize {
var proposal = proposal
proposal.width = proposal.width.map { max($0 - insets.horizontal, .zero) }
proposal.height = proposal.width.map { max($0 - insets.vertical, .zero) }
let fittingSize = if let layoutComputer {
layoutComputer.sizeThatFits(proposal)
} else {
CGSize(width: 10.0, height: 10.0)
}
return fittingSize.outset(by: insets)
}

package func sizeThatFits(_ proposal: _ProposedSize) -> CGSize {
_openSwiftUIUnimplementedFailure()
Self.sizeThatFits(proposal, layoutComputer: layoutComputer, insets: rootViewInsets)
}

package func explicitAlignment(of guide: VerticalAlignment, at size: CGSize) -> CGFloat? {
_openSwiftUIUnimplementedFailure()
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ extension ViewRendererHost {
}

package func sizeThatFits(_ proposal: _ProposedSize) -> CGSize {
updateViewGraph { $0.sizeThatFits(proposal)
}
updateViewGraph { $0.sizeThatFits(proposal) }
}
package func explicitAlignment(of guide: HorizontalAlignment, at size: CGSize) -> CGFloat? {
updateViewGraph { $0.explicitAlignment(of: guide, at: size) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// PlatformAlias.swift
// OpenSwiftUITestsSupport

#if OPENSWIFTUI_COMPATIBILITY_TEST
package import SwiftUI
#else
#if OPENSWIFTUI
package import OpenSwiftUI
#else
package import SwiftUI
#endif

#if os(iOS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension PlatformHostingController {

// FIXME: A workaround to bypass the Issue #87
package func workaroundIssue87(_ vc: PlatformViewController) {
#if !OPENSWIFTUI_COMPATIBILITY_TEST
#if OPENSWIFTUI
// TODO: Use swift-test exist test feature to detect the crash instead or sliently workaroun it
CrashWorkaround.shared.objects.append(vc)
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ struct AnimationCompatibilityTests {
func description() {
let animation = Animation.default
#expect(animation.description == "DefaultAnimation()")
#if OPENSWIFTUI_COMPATIBILITY_TEST
#expect(animation.debugDescription == "AnyAnimator(SwiftUI.DefaultAnimation())")
#else
#if OPENSWIFTUI
#expect(animation.debugDescription == "AnyAnimator(OpenSwiftUICore.DefaultAnimation())")
#else
#expect(animation.debugDescription == "AnyAnimator(SwiftUI.DefaultAnimation())")
#endif
#expect(animation.customMirror.description == "Mirror for Animation")
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/OpenSwiftUICompatibilityTests/Export.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Export.swift
// OpenSwiftUICompatibilityTests

#if OPENSWIFTUI_COMPATIBILITY_TEST
@_exported import SwiftUI
let compatibilityTestEnabled = true
#else
#if OPENSWIFTUI
@_exported import OpenSwiftUI
let compatibilityTestEnabled = false
#else
@_exported import SwiftUI
let compatibilityTestEnabled = true
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// OpenSwiftUICompatibilityTests

import Testing
#if !OPENSWIFTUI_COMPATIBILITY_TEST
#if OPENSWIFTUI
@_spi(ForTestOnly)
import OpenSwiftUI
#endif
Expand Down Expand Up @@ -38,23 +38,23 @@ struct ColorResolvedTests {
swiftUIExpected: String,
openSwiftUIExpected: String
) {
#if OPENSWIFTUI_COMPATIBILITY_TEST
guard #available(iOS 17, macOS 14, *) else {
print("This test is not available")
return
}
let resolved = Color.Resolved(colorSpace: colorSpace, red: red, green: green, blue: blue, opacity: opacity)
#expect(resolved.description == swiftUIExpected)
#else
#if OPENSWIFTUI
Update.locked {
Color.Resolved._alignWithSwiftUIImplementation = false
let resolved = Color.Resolved(colorSpace: colorSpace, red: red, green: green, blue: blue, opacity: opacity)
#expect(resolved.description == openSwiftUIExpected)

Color.Resolved._alignWithSwiftUIImplementation = true
let resolved2 = Color.Resolved(colorSpace: colorSpace, red: red, green: green, blue: blue, opacity: opacity)
#expect(resolved2.description == swiftUIExpected)
}
#else
guard #available(iOS 17, macOS 14, *) else {
print("This test is not available")
return
}
let resolved = Color.Resolved(colorSpace: colorSpace, red: red, green: green, blue: blue, opacity: opacity)
#expect(resolved.description == swiftUIExpected)
#endif
}
}
6 changes: 3 additions & 3 deletions Tests/OpenSwiftUICompatibilityTests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Test public API of OpenSwiftUI and run it against with SwiftUI on Apple Platform.

```swift
#if OPENSWIFTUI_COMPATIBILITY_TEST
import SwiftUI
#else
#if OPENSWIFTUI
import OpenSwiftUI
#else
import SwiftUI
#endif
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ struct ChangedBodyPropertyTests {
let entries = try store
.getEntries(at: position) // getEntries's with and at param is not respected on iOS, so I have to use last then.
.compactMap { $0 as? OSLogEntryLog }
#if OPENSWIFTUI_COMPATIBILITY_TEST
.filter { $0.subsystem == "com.apple.SwiftUI" && $0.category == "Changed Body Properties" }
#else
#if OPENSWIFTUI
.filter { $0.subsystem == "org.OpenSwiftUIProject.OpenSwiftUI" && $0.category == "Changed Body Properties" }
#else
.filter { $0.subsystem == "com.apple.SwiftUI" && $0.category == "Changed Body Properties" }
#endif
.map { $0.composedMessage }
#expect(entries.last == expected)
}

#if OPENSWIFTUI_COMPATIBILITY_TEST
#if !OPENSWIFTUI
@available(iOS 17.1, macOS 14.1, *)
#else
@available(iOS 15, macOS 12, *)
#endif
@Test
func zeroPropertyView() throws {
Expand All @@ -44,10 +42,8 @@ struct ChangedBodyPropertyTests {
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.")
}

#if OPENSWIFTUI_COMPATIBILITY_TEST
#if !OPENSWIFTUI
@available(iOS 17.1, macOS 14.1, *)
#else
@available(iOS 15, macOS 12, *)
#endif
@Test
func propertyView() throws {
Expand All @@ -64,10 +60,8 @@ struct ChangedBodyPropertyTests {
try verifyLog(expected: "ChangedBodyPropertyTests.ContentView: @self changed.")
}

#if OPENSWIFTUI_COMPATIBILITY_TEST
#if !OPENSWIFTUI
@available(iOS 17.1, macOS 14.1, *)
#else
@available(iOS 15, macOS 12, *)
#endif
@Test
func statePropertyView() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct EquatableViewTests {
}
}

#if !OPENSWIFTUI_COMPATIBILITY_TEST
#if OPENSWIFTUI
struct Number: Equatable {
var value: Int

Expand Down
Loading
Loading