[♻️] 문제 되는 버튼 뷰 해결 및 버튼 뷰 구성 수정

This commit is contained in:
Seonkyu_Kim 2025-02-06 18:48:12 +09:00
parent 3beafd636b
commit 48f564d051
5 changed files with 28 additions and 30 deletions

View File

@ -15,10 +15,18 @@ struct CircleBtnView: View {
var body: some View { var body: some View {
if let state = vm.btnStates[id] { if let state = vm.btnStates[id] {
Button{ ZStack {
guard let action = state.action else {return} if state.isReverse {
action() Circle()
} label: { .foregroundStyle(state.backColor)
.frame(width: state.width, height: state.height)
.innerShadow(shape: Circle(), color: Color(.Text.black).opacity(0.75), blur: 8, x: 0, y: 4)
} else {
Circle()
.foregroundStyle(state.backColor)
.frame(width: state.width, height: state.height)
.shadow(color: Color(.Text.black).opacity(0.75), radius: 8, x: 4, y: 8)
}
VStack(alignment: .center, spacing: 0) { VStack(alignment: .center, spacing: 0) {
if let image = state.image { if let image = state.image {
image image
@ -27,30 +35,20 @@ struct CircleBtnView: View {
.foregroundStyle(state.foreColor) .foregroundStyle(state.foreColor)
.frame(width: state.width/2, height: state.height/2) .frame(width: state.width/2, height: state.height/2)
} }
//
if let title = state.title, let font = state.font { if let title = state.title, let font = state.font {
Text("\(title)") Text("\(title)")
.font(font) .font(font)
.lineLimit(1) .lineLimit(1)
.minimumScaleFactor(0.5) .minimumScaleFactor(0.5)
.truncationMode(.tail) .truncationMode(.tail)
.foregroundStyle(state.textColor) .foregroundStyle(state.foreColor)
// .padding() }
} }
} }
.background {
if state.isReverse {
Circle()
.accentColor(state.backColor)
.frame(width: state.width, height: state.height) .frame(width: state.width, height: state.height)
.innerShadow(shape: Circle(), color: Color(.Text.black).opacity(0.75), blur: 8, x: 0, y: 4) .onTapGesture {
} else { guard let action = state.action else {return}
Circle() action()
.accentColor(state.backColor)
.frame(width: state.width, height: state.height)
.shadow(color: Color(.Text.black).opacity(0.75), radius: 8, x: 4, y: 8)
}
}
} }
} }
} }

View File

@ -29,11 +29,7 @@ struct BottomView: View {
} }
} }
// MARK: TO-DO .padding(EdgeInsets(top: 12, leading: 24, bottom: 0, trailing: 24))
//
.padding([.top],12)
.padding([.horizontal],24)
// .padding(EdgeInsets(top: 12, leading: 24, bottom: 0, trailing: 24))
.background { .background {
Rectangle() Rectangle()
@ -48,7 +44,7 @@ struct BottomView: View {
idList.enumerated().forEach { (index, id) in idList.enumerated().forEach { (index, id) in
btnVM.btnStates[id] = ButtonState() btnVM.btnStates[id] = ButtonState()
btnVM.setSize(for: id, newWidth: 48, newHeight: 48) btnVM.setSize(for: id, newWidth: 52, newHeight: 52)
btnVM.setText(for: id, newText: btnText[index], btnVM.setText(for: id, newText: btnText[index],
newFont: .nps(font: .bold, size: 6)) newFont: .nps(font: .bold, size: 6))
btnVM.setImage(for: id, newImage: btnImage[index]) btnVM.setImage(for: id, newImage: btnImage[index])

View File

@ -11,13 +11,12 @@ struct TopView: View {
@StateObject var btnVM = ButtonViewModel() @StateObject var btnVM = ButtonViewModel()
@State var titleName: String = "" @State var titleName: String = ""
@State var changeLogo: Bool = false
@State var tailLogo: Bool = false
@State private var leftBtnID = UUID() @State private var leftBtnID = UUID()
@State private var rightBtnID = UUID() @State private var rightBtnID = UUID()
var myType: UserType = .Teacher //MARK: -
var myType: UserType = .Student
var body: some View { var body: some View {
HStack(alignment: .center, spacing: 0) { HStack(alignment: .center, spacing: 0) {
@ -36,6 +35,7 @@ struct TopView: View {
.foregroundStyle(Color(.Text.detail)) .foregroundStyle(Color(.Text.detail))
.font(.nps(font: .bold, size: 20)) .font(.nps(font: .bold, size: 20))
Spacer() Spacer()
SimpleBtnView(vm: btnVM, id: rightBtnID) SimpleBtnView(vm: btnVM, id: rightBtnID)
.padding(EdgeInsets(top: 12, leading: 12, bottom: 12, trailing: 24)) .padding(EdgeInsets(top: 12, leading: 12, bottom: 12, trailing: 24))

View File

@ -74,7 +74,11 @@ class ButtonViewModel: ObservableObject {
func setIsReverse(for id: UUID, newValue: Bool){ func setIsReverse(for id: UUID, newValue: Bool){
var state = btnStates[id] ?? ButtonState() var state = btnStates[id] ?? ButtonState()
state.isReverse = newValue state.isReverse = newValue
state.backColor = newValue ? Color(.Second.light) : Color(.Normal.normal) if state.isReverse {
state.backColor = Color(.Second.light)
} else {
state.backColor = Color(.Normal.normal)
}
btnStates[id] = state btnStates[id] = state
objectWillChange.send() objectWillChange.send()
} }