Files
sing-box-for-apple/ApplicationLibrary/Views/Abstract/ViewModifiers.swift
T
2025-12-03 11:15:56 +08:00

59 lines
1.8 KiB
Swift

import SwiftUI
public extension View {
@ViewBuilder
func presentationDetentsIfAvailable() -> some View {
#if os(iOS) || os(tvOS)
if #available(iOS 16.0, tvOS 17.0, *) {
self.presentationDetents([.large])
.presentationDragIndicator(.visible)
} else {
self
}
#else
self
#endif
}
#if os(iOS) || os(tvOS)
@available(iOS 16.0, tvOS 17.0, *)
@ViewBuilder
func presentationDetentsIfAvailable(_ detents: PresentationDetent...) -> some View {
let detentSet: Set<PresentationDetent> = detents.isEmpty ? [.large] : Set(detents)
presentationDetents(detentSet)
.presentationDragIndicator(.visible)
}
#endif
@ViewBuilder
func actionButtonStyle() -> some View {
#if os(tvOS)
ActionButtonWrapper { self }
#else
if #available(iOS 26.0, macOS 26.0, *) {
self.frame(width: 44, height: 32)
.glassEffect(.regular.interactive(), in: .rect(cornerRadius: 8))
} else {
frame(width: 44, height: 32)
.background(Color.secondary.opacity(0.1))
.clipShape(RoundedRectangle(cornerRadius: 8))
}
#endif
}
}
#if os(tvOS)
private struct ActionButtonWrapper<Content: View>: View {
@Environment(\.isFocused) private var isFocused
let content: () -> Content
var body: some View {
content()
.frame(width: 70, height: 48)
.background(isFocused ? Color.secondary.opacity(0.3) : Color.secondary.opacity(0.1))
.clipShape(RoundedRectangle(cornerRadius: 12))
.focusEffectDisabled()
}
}
#endif