Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions DevLog/UI/Extension/View+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ private struct ScrollViewOffsetTracker: UIViewRepresentable {

extension View {
@ViewBuilder
func adaptiveButtonStyle(
shape: some Shape = .capsule,
color: Color = .clear)
-> some View {
func adaptiveButtonStyle<S: InsettableShape>(
shape: S = Capsule(),
color: Color = .clear
) -> some View {
Comment on lines +96 to +99
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

제네릭 타입 S에 대해 Capsule()을 기본값으로 설정할 수 없습니다. S는 어떤 InsettableShape이든 될 수 있기 때문에 컴파일러가 타입을 추론할 수 없어 오류가 발생합니다.

가장 직접적인 수정은 아래와 같이 기본값을 제거하는 것입니다. 하지만 이 경우 기존 호출 코드에 영향을 줄 수 있습니다.

더 나은 해결책은 기본값을 사용하는 오버로드 함수를 추가하는 것입니다:

@ViewBuilder
func adaptiveButtonStyle(color: Color = .clear) -> some View {
    self.adaptiveButtonStyle(shape: Capsule(), color: color)
}

// 그리고 이 함수의 시그니처를 아래와 같이 변경합니다.
@ViewBuilder
func adaptiveButtonStyle<S: InsettableShape>(
    shape: S,
    color: Color = .clear
) -> some View {
    // ... implementation
}
Suggested change
func adaptiveButtonStyle<S: InsettableShape>(
shape: S = Capsule(),
color: Color = .clear
) -> some View {
func adaptiveButtonStyle<S: InsettableShape>(
shape: S,
color: Color = .clear
) -> some View {

if #available(iOS 26.0, *) {
self.foregroundStyle(Color(.label))
.padding(8)
Expand All @@ -106,19 +106,9 @@ extension View {
self.foregroundStyle(Color(.label))
.padding(8)
.background {
Group {
if color == .clear {
shape
.fill(Color(.systemGray5))
} else {
shape
.fill(color)
}
}
.overlay {
shape
.stroke(Color.white.opacity(0.2), lineWidth: 1)
}
shape
.fill(color == .clear ? Color(.systemGray5) : color)
.strokeBorder(Color.white.opacity(0.2), lineWidth: 1)
Comment on lines +109 to +111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

.fill 메서드는 some View를 반환하므로 InsettableShape의 메서드인 .strokeBorder를 직접 체이닝할 수 없습니다. 이 코드는 컴파일되지 않습니다.

배경과 테두리를 함께 적용하려면 overlay 수정자를 사용하는 것이 좋습니다. 이렇게 하면 코드를 간결하게 유지하면서도 올바르게 테두리를 그릴 수 있습니다.

Suggested change
shape
.fill(color == .clear ? Color(.systemGray5) : color)
.strokeBorder(Color.white.opacity(0.2), lineWidth: 1)
shape
.fill(color == .clear ? Color(.systemGray5) : color)
.overlay(shape.strokeBorder(Color.white.opacity(0.2), lineWidth: 1))

}
}
}
Expand Down