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
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 {
EquatableDemoView(count: 0, tag: 0)
ColorAnimationExample()
}
}
28 changes: 28 additions & 0 deletions Example/SharedExample/Animation/ColorAnimationExample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ColorAnimationExample.swift
// SharedExample
//
// Created by Kyle on 2025/7/20.
//
#if OPENSWIFTUI
import OpenSwiftUI
#else
import SwiftUI
#endif
import Foundation

struct ColorAnimationExample: View {
@State private var showRed = false
var body: some View {
VStack {
Color(platformColor: showRed ? .red : .blue)
.frame(width: showRed ? 200 : 400, height: showRed ? 200 : 400)
}
.animation(.easeInOut(duration: 2), value: showRed)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
showRed.toggle()
}
}
}
}
30 changes: 30 additions & 0 deletions Example/SharedExample/Extension/Color+Platform.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Color+Platform.swift
// SharedExample
//
// Created by Kyle on 2025/7/20.
//

#if OPENSWIFTUI
import OpenSwiftUI
#else
import SwiftUI
#endif

#if os(iOS)
import UIKit
typealias PlatformColor = UIColor
#elseif os(macOS)
import AppKit
typealias PlatformColor = NSColor
#endif

extension Color {
init(platformColor: PlatformColor) {
#if os(iOS)
self.init(uiColor: platformColor)
#elseif os(macOS)
self.init(nsColor: platformColor)
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@ import Foundation
struct AppearanceActionModifierExample: View {
@State private var first = true

var color: Color {
#if os(macOS)
Color(nsColor: first ? .red : .blue)
#else
Color(uiColor: first ? .red : .blue)
#endif
}

var body: some View {
color
Color(platformColor: first ? .red : .blue)
.onAppear {
print("View appear")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
Expand Down
11 changes: 1 addition & 10 deletions Example/SharedExample/View/NamespaceExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,8 @@ struct NamespaceExample: View {
@State private var first = true
@Namespace private var id

var color: Color {
#if os(macOS)
Color.red
#else

Color(uiColor: first ? .red : .blue)
#endif
}

var body: some View {
color
Color(platformColor: first ? .red : .blue)
.onAppear {
print("View appear \(id)")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
Expand Down
Loading