-
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
[Feat] #24 - segment control component #33
Conversation
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.
Gongbaek_iOS/Gongbaek_iOS/Global/Component/Bar/CustomSegmentControl.swift
Outdated
Show resolved
Hide resolved
import SwiftUI | ||
|
||
struct CustomSegmentControl: View { | ||
let segments: [String] |
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.
enum SegmentState에 타이틀 배열도 정의해놨으니 생성자에서 받을건 String 배열이 아니라 enum 타입을 받으면 될거같아요!! 😆
ZStack(alignment: .bottom) { | ||
Color(.gray02) | ||
.frame(height: 2) | ||
selected == segment ? Color(.gray09).frame(height: 4) : nil | ||
} |
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.
여기는 ZStack은 안 써도 될 것 같아요! Color를 덮어씌우는 것보다 이미 만든 삼항연산자 하나에 합치는 건 어떨까요?!
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.
역시 뭐든지 직접 커스텀해서 컴포넌트 만들어서 쓰는 건 어렵네요.....🥺
Segmented Control 만든 거 자체가 대단한 거임 ㅜ.ㅜ
우리도 이제 @ViewBuilder 쓸 줄 안다~~ 성장했다.
extension SegmentState { | ||
var titles: [String] { | ||
switch self { | ||
case .detail: | ||
return ["모임정보", "댓글"] | ||
case .myfill: | ||
return ["내가 모집한", "내가 신청한"] | ||
} | ||
} | ||
} |
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.
여기 enum도 각각 모임상세, 채우기 화면별 세그먼트 타이틀도 다시 나누면 확장성에 좋을 것 같슴다
enum SegmentDetailType: String, CaseIterable {
case meetingInfo = "모임정보"
case comment = "댓글"
}
enum SegmentMyFillType: String, CaseIterable {
case recruit = "내가 모집한"
case apply = "내가 신청한"
}
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.
저도 몰랐는데 뷰빌더 기능을 쓰면 공통적인 부모 Container를 만드는데 유용하다고 해요!! 요런식으로 여러 개의 뷰를 조건마다 다르게 보여줘야 할 때도 쓰면 좋을 거 같네요 🤓
@ViewBuilder
func view(at index: Int) -> some View {
switch self {
case .detail:
switch SegmentDetailType.allCases[index] {
case .meetingInfo: AddMeetingButton()
case .comment: Text("민서 바부")
}
case .myfill:
switch SegmentMyFillType.allCases[index] {
case .recruit: Text("희은이 바부")
case .apply: Text("나연이가 더 바보")
}
}
}
🧩 작업 내용
🪁 PR Point
사용방법
📱 스크린샷
🔗 Issue
Resolved #24