|
struct VrboButtonStyle: ButtonStyle { |
|
|
|
let iconMode: UTButtonIconMode? |
|
let inverse: Bool |
|
let size: UTButtonSize |
|
let type: UTButtonType |
|
|
|
func makeBody(configuration: Configuration) -> some View { |
|
ButtonStyleView(configuration: configuration, |
|
type: type, |
|
size: size, |
|
inverse: inverse, |
|
iconMode: iconMode) |
|
} |
|
} |
|
|
|
private struct ButtonStyleView: View { |
|
|
|
typealias ViewModel = ButtonViewModel |
|
|
|
@Environment(\.isEnabled) private var isEnabled: Bool |
|
|
|
let configuration: ButtonStyle.Configuration |
|
let viewModel: ViewModel |
|
|
|
init(configuration: ButtonStyle.Configuration, |
|
type: ButtonType, |
|
size: ButtonSize, |
|
inverse: Bool, |
|
iconMode: ButtonIconMode?) { |
|
self.configuration = configuration |
|
self.viewModel = ViewModel(iconMode: iconMode, inverse: inverse, size: size, type: type) |
|
} |
|
|
|
var body: some View { |
|
configuration.label |
|
.fixedSize() |
|
.lineLimit(2) |
|
.multilineTextAlignment(.center) |
|
.frame(width: viewModel.width, height: viewModel.height) |
|
.padding(viewModel.padding) |
|
.background(viewModel.backgroundColor(for: isEnabled, isPressed: configuration.isPressed)) |
|
.foregroundColor(viewModel.foregroundColor(for: isEnabled, isPressed: configuration.isPressed)) |
|
.cornerRadius(viewModel.cornerRadius) |
|
.modifier(VrboText(typeStyle: viewModel.typeStyle)) |
|
.overlay( |
|
RoundedRectangle(cornerRadius: viewModel.cornerRadius) |
|
.stroke(viewModel.borderColor(for: isEnabled, isPressed: configuration.isPressed), lineWidth: 1) |
|
) |
|
.accentColor(viewModel.accentColor(for: isEnabled, isPressed: configuration.isPressed)) |
|
.scaleEffect(viewModel.scaleEffect(for: isEnabled, isPressed: configuration.isPressed)) |
|
.animation(.spring()) |
|
} |
|
} |