У меня здесь пользовательский стек из двух кнопок Нет / Да. У обоих реализованы внешние действия. Но я не могу найти способ изменить с помощью действия принять / отклонить , мне также нужно изменить внутреннее
@ State var type: SelectionType = .none - до .yes или .no
struct SegmentedButtonView: View {
@State var type: SelectionType = .none
var accept: () -> ()
var decline: () -> ()
var body: some View {
HStack(alignment: .center) {
Button(action: accept ){
Spacer()
Text(SelectionType.no.rawValue)
.font(.Montserrat(weight: (type == .yes || type == .none) ? .SemiBold : .Bold, size: 16))
.foregroundColor((type == .none || type == .yes) ? Color.lightGray : Color.white)
Spacer()
}
.frame(height: 40)
.background(type == .no ? Color.brand_purple : Color.white)
Rectangle().vertical_line().background(type == .none ? Color.lightGray : Color.brand_purple)
Button(action: decline){
Spacer()
Text(SelectionType.yes.rawValue)
.font(.Montserrat(weight: (type == .no || type == .none) ? .SemiBold : .Bold, size: 16))
.foregroundColor((type == .none || type == .no) ? Color.lightGray : Color.white)
Spacer()
}
.frame(height: 40)
.background(type == .yes ? Color.brand_purple : Color.white)
}.frame(width: 138, height: 40)
.font(.Montserrat(weight: .Bold, size: 16))
.background(Color.white)
.cornerRadius(7)
.overlay(
RoundedRectangle(cornerRadius: 7)
.stroke(type != .none ? Color.brand_purple : Color.lightGray, lineWidth: 1))
}
}