Skip to content
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

[WEAV-65] Background Texture View 방식 변경 #20

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
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
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"images" : [
{
"filename" : "bg-texture.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "background_default@2x.png",
"filename" : "bg-texture@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "background_default@3x.png",
"filename" : "bg-texture@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,62 @@
import SwiftUI

public struct BackgroundTextureView: View {
public init() {}
public enum ColorType {
case `default`
case splashBrown
case splashGreen
case splashPurple
case splashPink

var color: Color {
switch self {
case .default: return Color(hex: 0xF5F1EE)
case .splashBrown: return Color(hex: 0xE4DED7)
case .splashGreen: return Color(hex: 0xDFE7D1)
case .splashPurple: return Color(hex: 0xD7D7EA)
case .splashPink: return Color(hex: 0xECDAE3)
}
}
}

let type: ColorType

public init(_ type: ColorType) {
self.type = type
}

public var body: some View {
DesignCore.Images.backgroundDefault.image
.resizable()
.frame(
width: Device.width,
height: Device.height
)
.aspectRatio(contentMode: .fill)
.ignoresSafeArea()
ZStack {
type.color
DesignCore.Images.bgTexture.image
.resizable()
.frame(
width: Device.width,
height: Device.height
)
.aspectRatio(contentMode: .fill)
}
.ignoresSafeArea()
}
}

fileprivate struct BackgroundTextureViewModifier: ViewModifier {
fileprivate func body(content: Content) -> some View {
private struct BackgroundTextureViewModifier: ViewModifier {
let colorType: BackgroundTextureView.ColorType

func body(content: Content) -> some View {
content
.background {
DesignCore.Images.backgroundDefault.image
.resizable()
.frame(
width: Device.width,
height: Device.height
)
.aspectRatio(contentMode: .fill)
.ignoresSafeArea()
BackgroundTextureView(colorType)
}
Comment on lines +52 to 58
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

BackgroundTextureViewModifier 업데이트 승인 및 개선 제안

BackgroundTextureViewModifier의 변경사항은 BackgroundTextureView의 업데이트와 잘 통합되어 있습니다. colorType 매개변수를 추가한 것은 적절한 변경입니다.

SwiftLint 경고를 해결하기 위해 다음과 같이 수정을 제안합니다:

private struct BackgroundTextureViewModifier: ViewModifier {
    let colorType: BackgroundTextureView.ColorType
    
    func body(content: Content) -> some View {
        content
            .background {
                BackgroundTextureView(colorType)
            }
    }
}

fileprivate 대신 private를 사용하면 SwiftLint 경고를 해결하고 더 명확한 접근 제어를 제공할 수 있습니다. 이 구조체가 파일 외부에서 사용되지 않는다면 private로 충분할 것 같습니다.

}
}

extension View {
public func textureBackground() -> some View {
modifier(BackgroundTextureViewModifier())
public func textureBackground(_ type: BackgroundTextureView.ColorType) -> some View {
modifier(BackgroundTextureViewModifier(colorType: type))
}
}

#Preview {
BackgroundTextureView(.splashGreen)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct DesignBackgroundTextureView: View {
Text("This is Background 🎨")
.typography(.semibold_20)
}
.textureBackground()
.textureBackground(.splashPink)
.navigationTitle("Texture Background")
}
}
Expand Down
Loading