another.im-ios/ConversationsClassic/View/UIToolkit/ButtonStyles.swift

51 lines
1.9 KiB
Swift
Raw Normal View History

2024-06-19 15:15:27 +00:00
import SwiftUI
private enum ButtonSizes {
static let padding = 16.0
static let cornerRadius = 4.0
static let scaleEffect: CGFloat = 0.9
static let opacity: Double = 0.6
}
struct PrimaryButtonStyle: ButtonStyle {
@Environment(\.isEnabled) private var isEnabled
func makeBody(configuration: Configuration) -> some View {
configuration
.label
.font(.head2)
.padding(ButtonSizes.padding)
.frame(maxWidth: .infinity)
.foregroundColor(.Main.white)
.background {
RoundedRectangle(cornerRadius: ButtonSizes.cornerRadius)
.foregroundColor(isEnabled ? .Material.greenDark500 : .Main.separator)
}
.contentShape(Rectangle())
.scaleEffect(configuration.isPressed ? ButtonSizes.scaleEffect : 1.0)
.opacity(configuration.isPressed ? ButtonSizes.opacity : 1.0)
.animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
}
}
struct SecondaryButtonStyle: ButtonStyle {
@Environment(\.isEnabled) private var isEnabled
func makeBody(configuration: Configuration) -> some View {
configuration
.label
.font(.head2)
.padding(ButtonSizes.padding)
.frame(maxWidth: .infinity)
.foregroundColor(isEnabled ? .Material.greenDark500 : .Main.separator)
.background {
RoundedRectangle(cornerRadius: ButtonSizes.cornerRadius)
.stroke(isEnabled ? Color.Material.greenDark500 : Color.Main.separator)
}
.contentShape(Rectangle())
.scaleEffect(configuration.isPressed ? ButtonSizes.scaleEffect : 1.0)
.opacity(configuration.isPressed ? ButtonSizes.opacity : 1.0)
.animation(.easeInOut(duration: 0.1), value: configuration.isPressed)
}
}