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

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 {
if let state = vm.btnStates[id] {
Button{
guard let action = state.action else {return}
action()
} label: {
ZStack {
if state.isReverse {
Circle()
.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) {
if let image = state.image {
image
@ -27,31 +35,21 @@ struct CircleBtnView: View {
.foregroundStyle(state.foreColor)
.frame(width: state.width/2, height: state.height/2)
}
//
if let title = state.title, let font = state.font {
Text("\(title)")
.font(font)
.lineLimit(1)
.minimumScaleFactor(0.5)
.truncationMode(.tail)
.foregroundStyle(state.textColor)
// .padding()
}
}
.background {
if state.isReverse {
Circle()
.accentColor(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()
.accentColor(state.backColor)
.frame(width: state.width, height: state.height)
.shadow(color: Color(.Text.black).opacity(0.75), radius: 8, x: 4, y: 8)
.foregroundStyle(state.foreColor)
}
}
}
.frame(width: state.width, height: state.height)
.onTapGesture {
guard let action = state.action else {return}
action()
}
}
}
}

View File

@ -29,11 +29,7 @@ struct BottomView: View {
}
}
// MARK: TO-DO
//
.padding([.top],12)
.padding([.horizontal],24)
// .padding(EdgeInsets(top: 12, leading: 24, bottom: 0, trailing: 24))
.padding(EdgeInsets(top: 12, leading: 24, bottom: 0, trailing: 24))
.background {
Rectangle()
@ -48,7 +44,7 @@ struct BottomView: View {
idList.enumerated().forEach { (index, id) in
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],
newFont: .nps(font: .bold, size: 6))
btnVM.setImage(for: id, newImage: btnImage[index])

View File

@ -11,13 +11,12 @@ struct TopView: View {
@StateObject var btnVM = ButtonViewModel()
@State var titleName: String = ""
@State var changeLogo: Bool = false
@State var tailLogo: Bool = false
@State private var leftBtnID = UUID()
@State private var rightBtnID = UUID()
var myType: UserType = .Teacher
//MARK: -
var myType: UserType = .Student
var body: some View {
HStack(alignment: .center, spacing: 0) {
@ -36,6 +35,7 @@ struct TopView: View {
.foregroundStyle(Color(.Text.detail))
.font(.nps(font: .bold, size: 20))
Spacer()
SimpleBtnView(vm: btnVM, id: rightBtnID)
.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){
var state = btnStates[id] ?? ButtonState()
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
objectWillChange.send()
}