-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#84] SettingView 내 ListView 분리 및 추가 리팩터링 #89
base: develop
Are you sure you want to change the base?
Changes from 9 commits
46a29d4
2d55349
5073dfd
5c5ad2a
5737557
5bae3ca
ac3efb2
90e0ed7
e83f104
7a8df00
9295f66
130ab0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,92 @@ | ||||||||||||||
// | ||||||||||||||
// ListRowView.swift | ||||||||||||||
// Soomsil-USaint | ||||||||||||||
// | ||||||||||||||
// Created by 최지우 on 2/5/25. | ||||||||||||||
// | ||||||||||||||
|
||||||||||||||
import SwiftUI | ||||||||||||||
|
||||||||||||||
import YDS_SwiftUI | ||||||||||||||
|
||||||||||||||
enum RightItem { | ||||||||||||||
case none | ||||||||||||||
case toggle(isPushAuthorizationEnabled: Binding<Bool>) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
struct ListRowView: View { | ||||||||||||||
let title: String | ||||||||||||||
let items: [ItemModel] | ||||||||||||||
|
||||||||||||||
init(title: String, items: [ItemModel]) { | ||||||||||||||
self.title = title | ||||||||||||||
self.items = items | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
var body: some View { | ||||||||||||||
VStack(alignment: .leading, spacing: 0) { | ||||||||||||||
Text(title) | ||||||||||||||
.font(YDSFont.subtitle3) | ||||||||||||||
.foregroundColor(YDSColor.textSecondary) | ||||||||||||||
.padding(20) | ||||||||||||||
.frame(height: 48) | ||||||||||||||
|
||||||||||||||
ForEach(items.indices, id: \.self) { index in | ||||||||||||||
HStack { | ||||||||||||||
items[index] | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
struct ItemModel: View { | ||||||||||||||
let text: String | ||||||||||||||
let rightItem: RightItem | ||||||||||||||
let action: () -> Void | ||||||||||||||
@State private var isPressed: Bool = false | ||||||||||||||
|
||||||||||||||
var body: some View { | ||||||||||||||
HStack { | ||||||||||||||
Text(text) | ||||||||||||||
.font(YDSFont.button3) | ||||||||||||||
.foregroundColor(YDSColor.textSecondary) | ||||||||||||||
.padding(20) | ||||||||||||||
.frame(height: 48) | ||||||||||||||
.frame(maxWidth: .infinity, alignment: .leading) | ||||||||||||||
.background(isPressed ? Color(red: 0.95, green: 0.96, blue: 0.97) : Color.white) | ||||||||||||||
.gesture( | ||||||||||||||
DragGesture(minimumDistance: 0) | ||||||||||||||
.onChanged { _ in isPressed = true } | ||||||||||||||
.onEnded { _ in | ||||||||||||||
isPressed = false | ||||||||||||||
switch rightItem { | ||||||||||||||
case .none: | ||||||||||||||
action() | ||||||||||||||
case .toggle(let isPushAuthorizationEnabled): | ||||||||||||||
return | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
switch rightItem { | ||||||||||||||
case .none: | ||||||||||||||
EmptyView() | ||||||||||||||
case .toggle(let isPushAuthorizationEnabled): | ||||||||||||||
Toggle("", isOn: isPushAuthorizationEnabled) | ||||||||||||||
.labelsHidden() | ||||||||||||||
.padding(.horizontal, 20) | ||||||||||||||
.padding(.vertical, 20) | ||||||||||||||
.tint(YDSColor.buttonPoint) | ||||||||||||||
.frame(height: 48) | ||||||||||||||
// TODO: onChange 액션 추가 | ||||||||||||||
.onChange(of: isPushAuthorizationEnabled) { | ||||||||||||||
action() | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
이렇게 사용하면 에러가 안나요! 제가 추측하기로는 onChange(of:perform:) 메서드를 사용할 때, of: 매개변수로 전달하는 값이 Equatable 프로토콜을 준수해야 해서 값을 전달할 때 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
// .onReceive(isPushAuthorizationEnabled.projectedValue) { newValue in | ||||||||||||||
// action() | ||||||||||||||
// } | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 주석이 필요한 부분이 아니면 삭제하는게 좋을 것 같아요! 위에 TODO도 마찬가지로요! |
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한 가지 걸리는 건
ItemModel
이란 네이밍이 적절할까 고민이긴 한데,, ItemModel하면 뭔가 View가 아닌 느낌이 더 들어서, Row나 RowView와 같은 이름이 더 적절할 것 같아요!