mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
172 lines
3.2 KiB
Swift
172 lines
3.2 KiB
Swift
//
|
|
// ViewModifiers.swift
|
|
// StickerSlack
|
|
//
|
|
// Created by neon443 on 03/11/2025.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
struct numericTextCompat: ViewModifier {
|
|
func body(content: Content) -> some View {
|
|
if #available(iOS 16, *) {
|
|
content.contentTransition(.numericText())
|
|
} else {
|
|
content.transition(.opacity)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct glassButtonIfAv: ViewModifier {
|
|
var enabled: Bool
|
|
|
|
init(_ enabled: Bool = true) {
|
|
self.enabled = enabled
|
|
}
|
|
|
|
func body(content: Content) -> some View {
|
|
#if compiler(>=6.2)
|
|
if enabled {
|
|
if #available(iOS 19, *) {
|
|
content.buttonStyle(.glassProminent)
|
|
} else {
|
|
content.buttonStyle(.borderedProminent)
|
|
}
|
|
} else {
|
|
content
|
|
}
|
|
#else
|
|
if enabled {
|
|
content.buttonStyle(.borderedProminent)
|
|
} else {
|
|
content
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
|
|
struct NavigationView2<T: View>: View {
|
|
@ViewBuilder var contents: T
|
|
|
|
var body: some View {
|
|
if #available(iOS 16, *) {
|
|
NavigationStack {
|
|
contents
|
|
}
|
|
} else {
|
|
NavigationView {
|
|
contents
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct presentationHalfAndFullIfAv: ViewModifier {
|
|
func body(content: Content) -> some View {
|
|
if #available(iOS 16, *) {
|
|
content
|
|
.presentationDetents([.medium, .large])
|
|
.presentationDragIndicator(.visible)
|
|
} else {
|
|
content
|
|
}
|
|
}
|
|
}
|
|
|
|
struct BoldSafe: ViewModifier {
|
|
var isEnabled: Bool = true
|
|
var style: Font.TextStyle = .body
|
|
|
|
func body(content: Content) -> some View {
|
|
if #available(iOS 16, *) {
|
|
content.bold(isEnabled)
|
|
} else {
|
|
if isEnabled {
|
|
content.font(.system(style).bold())
|
|
} else {
|
|
content.font(.system(style))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MonospacedSafe: ViewModifier {
|
|
var isEnabled: Bool = true
|
|
var style: Font.TextStyle = .body
|
|
|
|
func body(content: Content) -> some View {
|
|
if #available(iOS 16, *) {
|
|
content.monospaced(isEnabled)
|
|
} else {
|
|
if isEnabled {
|
|
content.font(.system(style).monospaced())
|
|
} else {
|
|
content.font(.system(style))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ScrollContentBackgroundHidden: ViewModifier {
|
|
func body(content: Content) -> some View {
|
|
if #available(iOS 16, *) {
|
|
content.scrollContentBackground(.hidden)
|
|
} else {
|
|
content
|
|
}
|
|
}
|
|
}
|
|
|
|
struct TabViewBottomAcceessorySafe<T: View>: ViewModifier {
|
|
var isEnabled: Bool
|
|
@ViewBuilder var contents: () -> T
|
|
|
|
func body(content: Content) -> some View where Content: View {
|
|
#if compiler(>=6.2.1)
|
|
if #available(iOS 26.1, *) {
|
|
content
|
|
.tabViewBottomAccessory(isEnabled: isEnabled, content: contents)
|
|
} else {
|
|
content
|
|
}
|
|
#else
|
|
content
|
|
#endif
|
|
}
|
|
}
|
|
|
|
extension View {
|
|
func tabViewBottomAccessorySafe<Content: View>(
|
|
isEnabled: Bool = true,
|
|
@ViewBuilder content: @escaping () -> Content
|
|
) -> some View {
|
|
modifier(TabViewBottomAcceessorySafe(isEnabled: isEnabled, contents: content))
|
|
}
|
|
}
|
|
|
|
struct fadeIn: ViewModifier {
|
|
@State private var enabled: Bool
|
|
@State private var isVisible: Bool = false
|
|
|
|
init(enabled: Bool = true) {
|
|
self.enabled = enabled
|
|
}
|
|
|
|
func body(content: Content) -> some View {
|
|
if enabled {
|
|
content
|
|
.opacity(isVisible ? 1 : 0)
|
|
.scaleEffect(isVisible ? 1 : 0)
|
|
.onAppear {
|
|
withAnimation { isVisible = true }
|
|
}
|
|
.onDisappear {
|
|
withAnimation { isVisible = false }
|
|
}
|
|
} else {
|
|
content
|
|
}
|
|
}
|
|
}
|