Finish add support for tvOS
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public struct ActiveDashboardView: View {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
.onChange(of: selectedProfileID) { _ in
|
||||
.onChangeCompat(of: selectedProfileID) {
|
||||
reasserting = true
|
||||
Task.detached {
|
||||
await switchProfile(selectedProfileID!)
|
||||
|
||||
@@ -46,7 +46,7 @@ public struct ExtensionStatusView: View {
|
||||
Rectangle()
|
||||
.fill(.clear)
|
||||
.frame(height: 1)
|
||||
.onChange(of: geometry.size.width) { newValue in
|
||||
.onChangeCompat(of: geometry.size.width) { newValue in
|
||||
updateColumnCount(newValue)
|
||||
}
|
||||
.onAppear {
|
||||
|
||||
@@ -82,7 +82,7 @@ public struct GroupView: View {
|
||||
Rectangle()
|
||||
.fill(.clear)
|
||||
.frame(height: 1)
|
||||
.onChange(of: geometry.size.width) { newValue in
|
||||
.onChangeCompat(of: geometry.size.width) { newValue in
|
||||
geometryWidth = newValue
|
||||
}
|
||||
.onAppear {
|
||||
|
||||
@@ -46,7 +46,7 @@ public struct LogView: View {
|
||||
Spacer(minLength: 5)
|
||||
}
|
||||
|
||||
.onChange(of: logClient.logList.count) { newCount in
|
||||
.onChangeCompat(of: logClient.logList.count) { newCount in
|
||||
withAnimation {
|
||||
reader.scrollTo(newCount - 1)
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public extension NavigationPage {
|
||||
switch self {
|
||||
case .dashboard:
|
||||
DashboardView()
|
||||
|
||||
case .groups:
|
||||
GroupListView()
|
||||
case .logs:
|
||||
@@ -78,8 +79,9 @@ public extension NavigationPage {
|
||||
#if os(tvOS)
|
||||
// TODO: fix groups ui
|
||||
return false
|
||||
#else
|
||||
return profile?.status.isConnectedStrict == true
|
||||
#endif
|
||||
return profile?.status.isConnectedStrict == true
|
||||
default:
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -43,17 +43,13 @@ public struct ProfileView: View {
|
||||
#if os(iOS) || os(tvOS)
|
||||
ZStack {
|
||||
if let importRemoteProfileRequest {
|
||||
NavigationLink(
|
||||
destination: NewProfileView(importRemoteProfileRequest) {
|
||||
NavigationDestinationCompat(isPresented: $importRemoteProfilePresented) {
|
||||
NewProfileView(importRemoteProfileRequest) {
|
||||
Task.detached {
|
||||
doReload()
|
||||
}
|
||||
},
|
||||
isActive: $importRemoteProfilePresented,
|
||||
label: {
|
||||
EmptyView()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
FormView {
|
||||
#if os(iOS) || os(tvOS)
|
||||
|
||||
@@ -67,7 +67,7 @@ public struct SettingView: View {
|
||||
#endif
|
||||
Section("Packet Tunnel") {
|
||||
Toggle("Disable Memory Limit", isOn: $disableMemoryLimit)
|
||||
.onChange(of: disableMemoryLimit) { newValue in
|
||||
.onChangeCompat(of: disableMemoryLimit) { newValue in
|
||||
Task.detached {
|
||||
SharedPreferences.disableMemoryLimit = newValue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user