Finish add support for tvOS

This commit is contained in:
世界
2023-07-29 19:40:38 +08:00
parent bb0385f53c
commit 27ffee06e2
28 changed files with 104 additions and 26 deletions
@@ -0,0 +1,15 @@
import SwiftUI
func NavigationDestinationCompat(isPresented: Binding<Bool>, @ViewBuilder destination: () -> some View) -> some View {
if #unavailable(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0) {
return NavigationLink(
destination: destination(),
isActive: isPresented,
label: {
EmptyView()
}
)
} else {
return EmptyView().navigationDestination(isPresented: isPresented, destination: destination)
}
}
@@ -0,0 +1,14 @@
import SwiftUI
public func NavigationStackCompat(@ViewBuilder content: () -> some View) -> some View {
viewBuilder {
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, *) {
NavigationStack(root: content)
} else {
NavigationView(content: content)
#if !os(macOS)
.navigationViewStyle(.stack)
#endif
}
}
}
@@ -0,0 +1,23 @@
import SwiftUI
public extension View {
func onChangeCompat(of value: some Equatable, _ action: @escaping () -> Void) -> some View {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) {
return onChange(of: value, action)
} else {
return onChange(of: value) { _ in
action()
}
}
}
func onChangeCompat<V>(of value: V, _ action: @escaping (_ newValue: V) -> Void) -> some View where V: Equatable {
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) {
return onChange(of: value) { _, newValue in
action(newValue)
}
} else {
return onChange(of: value, perform: action)
}
}
}