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

Conversation

jisu15-kim
Copy link
Member

@jisu15-kim jisu15-kim commented Sep 24, 2024

구현사항

  • 기존 구현해두었던 Background Texture View 를 이미지 리소스 방식으로 사용했었음
  • 컬러별로 variation 이 생겨야 하는 상황
  • 리소스 최적화를 위해 Zstack을 활용해 Texture 리소스 와 코드로 색상을 구현하기로 함

Summary by CodeRabbit

  • 새로운 기능

    • 배경 텍스처 뷰에 다양한 색상 옵션을 정의하는 ColorType 열거형 추가.
    • 배경 색상을 선택할 수 있는 기능이 추가되어 사용자 정의 배경 색상 적용 가능.
    • 새로운 배경 텍스처 이미지 파일 추가 및 기존 이미지 파일 이름 변경.
  • 버그 수정

    • 배경 텍스처 메서드 호출 시 색상 매개변수 적용.

@jisu15-kim jisu15-kim self-assigned this Sep 24, 2024
Copy link

coderabbitai bot commented Sep 24, 2024

Walkthrough

이 변경 사항은 bg-texture.imageset의 이미지 자산 파일 이름을 업데이트하고, BackgroundTextureView 구조체에 색상 옵션을 추가하며, DesignBackgroundTextureView에서 배경 텍스처 메서드 호출을 수정하는 내용을 포함합니다. 새로운 이미지 파일이 추가되고, 기존의 파일 이름이 변경되었습니다. 또한, 여러 구조체와 메서드의 초기화 및 시그니처가 업데이트되었습니다.

Changes

파일 경로 변경 요약
Projects/DesignSystem/DesignCore/Resources/Images/Images.xcassets/bg-texture.imageset/Contents.json 이미지 파일 이름 업데이트 및 1x 스케일 이미지 추가: bg-texture.png, [email protected], [email protected]로 변경.
Projects/DesignSystem/DesignCore/Sources/BackgroundTextureView.swift BackgroundTextureViewColorType 열거형 추가, 초기화 메서드 변경, body 속성 수정, BackgroundTextureViewModifier 업데이트, 미리보기 추가.
Projects/Features/DesignPreview/Sources/DesignBackgroundTextureView.swift .textureBackground() 메서드 호출을 .textureBackground(.splashPink)로 변경하여 배경 텍스처를 색상 매개변수로 지정.

Possibly related PRs

  • [WEAV-46] Design Component 구현 #19: DesignBackgroundTextureView.swift 파일의 변경 사항은 배경 이미지 처리 방식을 수정하는 점에서 주요 PR과 관련이 있습니다.

Suggested labels

Feature

Poem

🐰
배경이 바뀌고, 색이 더해져,
텍스처의 향연, 새로워져.
귀여운 색상, 뚜렷한 모습,
디자인의 변화, 즐거운 소식!
아, 변화는 언제나 신나!
우리 함께 춤추자, 하하! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (3)
Projects/DesignSystem/DesignCore/Sources/BackgroundTextureView.swift (3)

12-28: ColorType 열거형 추가에 대한 승인 및 제안

ColorType 열거형의 추가는 PR의 목표와 잘 부합하며, 다양한 배경색 변형을 효과적으로 처리할 수 있게 해줍니다. 구현이 깔끔하고 Swift의 모범 사례를 따르고 있습니다.

개선을 위한 작은 제안:

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

이렇게 하면 코드가 더 간결해지고 각 케이스에 대한 색상 값을 한눈에 볼 수 있습니다.


37-47: body 프로퍼티 업데이트 승인 및 개선 제안

ZStack을 사용한 새로운 구현은 PR의 목표와 잘 부합하며, 리소스 최적화와 유연한 배경색 적용을 가능하게 합니다. 텍스처와 색상을 효과적으로 결합하고 있습니다.

SwiftUI 모범 사례를 따르기 위해 다음과 같은 작은 개선을 제안합니다:

ZStack {
    type.color
        .ignoresSafeArea()
    DesignCore.Images.bgTexture.image
        .resizable()
        .aspectRatio(contentMode: .fill)
        .ignoresSafeArea()
}

이렇게 하면 각 레이어에 대해 개별적으로 ignoresSafeArea()를 적용하여 더 정확한 레이아웃 제어가 가능해집니다. 또한 Device.widthDevice.height를 사용하는 대신 aspectRatio(contentMode: .fill)만으로 전체 화면을 채울 수 있습니다.


68-70: 프리뷰 추가 승인 및 개선 제안

BackgroundTextureView에 대한 프리뷰 추가는 좋은 변경사항입니다. 개발 중 빠른 시각적 피드백을 얻을 수 있어 유용합니다.

더 다양한 사용 사례를 보여주기 위해 다음과 같이 여러 색상 옵션을 포함하는 프리뷰를 추가하는 것은 어떨까요?

#Preview {
    VStack {
        BackgroundTextureView(.default)
        BackgroundTextureView(.splashBrown)
        BackgroundTextureView(.splashGreen)
        BackgroundTextureView(.splashPurple)
        BackgroundTextureView(.splashPink)
    }
}

이렇게 하면 모든 색상 옵션을 한 번에 비교해볼 수 있어 개발 및 디자인 과정에 도움이 될 것 같습니다.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e4fa962 and ba3f674.

Files ignored due to path filters (5)
  • Projects/DesignSystem/DesignCore/Resources/Images/Images.xcassets/background_default.imageset/[email protected] is excluded by !**/*.png
  • Projects/DesignSystem/DesignCore/Resources/Images/Images.xcassets/background_default.imageset/[email protected] is excluded by !**/*.png
  • Projects/DesignSystem/DesignCore/Resources/Images/Images.xcassets/bg-texture.imageset/bg-texture.png is excluded by !**/*.png
  • Projects/DesignSystem/DesignCore/Resources/Images/Images.xcassets/bg-texture.imageset/[email protected] is excluded by !**/*.png
  • Projects/DesignSystem/DesignCore/Resources/Images/Images.xcassets/bg-texture.imageset/[email protected] is excluded by !**/*.png
Files selected for processing (3)
  • Projects/DesignSystem/DesignCore/Resources/Images/Images.xcassets/bg-texture.imageset/Contents.json (1 hunks)
  • Projects/DesignSystem/DesignCore/Sources/BackgroundTextureView.swift (1 hunks)
  • Projects/Features/DesignPreview/Sources/DesignBackgroundTextureView.swift (1 hunks)
Additional context used
SwiftLint
Projects/DesignSystem/DesignCore/Sources/BackgroundTextureView.swift

[Warning] 51-51: Prefer private over fileprivate declarations

(private_over_fileprivate)

Additional comments not posted (7)
Projects/DesignSystem/DesignCore/Resources/Images/Images.xcassets/bg-texture.imageset/Contents.json (4)

4-6: 1x 스케일 이미지 추가 승인

1x 스케일 이미지 "bg-texture.png"를 추가한 것은 좋은 변경사항입니다.

이 추가로 인해:

  1. 표준 해상도 디스플레이를 가진 기기에 대한 지원이 개선됩니다.
  2. 다양한 디바이스 해상도에 대한 대응이 더욱 완벽해집니다.
  3. 이미지 네이밍 규칙이 2x, 3x 버전과 일관성을 유지하고 있습니다.

9-11: 2x 스케일 이미지 파일명 변경 승인

2x 스케일 이미지의 파일명을 "[email protected]"에서 "[email protected]"로 변경한 것은 적절합니다.

이 변경의 장점:

  1. 에셋 이름(bg-texture)과 더 일관성 있는 명명이 되었습니다.
  2. 1x 및 3x 버전과 동일한 명명 규칙을 따르게 되어 전체적인 일관성이 향상되었습니다.
  3. 향후 유지보수 시 이미지 파일을 더 쉽게 식별하고 관리할 수 있게 되었습니다.

14-16: 3x 스케일 이미지 파일명 변경 승인

3x 스케일 이미지의 파일명을 "[email protected]"에서 "[email protected]"로 변경한 것은 매우 적절합니다.

이 변경의 의의:

  1. 1x 및 2x 버전과 완벽하게 일치하는 명명 규칙을 적용하였습니다.
  2. 모든 스케일 팩터에 걸쳐 이미지 네이밍의 표준화가 완성되었습니다.
  3. 이는 에셋 관리의 일관성과 명확성을 크게 향상시킵니다.

Line range hint 1-23: 전체 변경사항 요약 및 PR 목표와의 연관성

이 파일의 변경사항들은 전반적으로 매우 긍정적이며, PR의 목표와 잘 부합합니다:

  1. 모든 스케일(1x, 2x, 3x)에 대해 일관된 네이밍 규칙을 적용하여 에셋 관리를 개선했습니다.
  2. 새로운 1x 스케일 이미지를 추가하여 다양한 디바이스 해상도에 대한 지원을 강화했습니다.
  3. 이러한 변경은 PR 목표에서 언급된 ZStack 기반 구현과의 통합을 용이하게 할 것으로 예상됩니다.
  4. 표준화된 네이밍은 리소스 최적화와 유연성 향상이라는 PR의 주요 목표를 지원합니다.

이러한 변경사항들은 Background Texture View의 새로운 구현 방식에 잘 부합하며, 향후 유지보수와 확장성 측면에서도 긍정적인 영향을 미칠 것으로 보입니다.

Projects/Features/DesignPreview/Sources/DesignBackgroundTextureView.swift (1)

18-18: 변경 사항이 PR 목표와 일치합니다.

.textureBackground(.splashPink)로의 변경은 PR 목표에서 언급된 대로 색상 변형을 지원하는 것으로 보입니다. 이는 리소스 최적화와 유연성 향상이라는 목표에 부합합니다.

그러나 PR 목표에서 언급된 ZStack의 사용이 이 파일에서는 명확히 보이지 않습니다. ZStack이 .textureBackground 수정자 내부에 구현되어 있거나 다른 파일에 있을 수 있습니다. 이에 대한 추가 설명이나 관련 코드를 제공해 주시면 좋겠습니다.

Verification successful

리뷰 코멘트가 PR 목표와 일치함을 확인했습니다.

.textureBackground(.splashPink) 변경 사항은 색상 변형을 지원하며, 해당 파일 내에서 ZStack이 제대로 사용되고 있음을 확인했습니다. 변경 사항을 승인합니다.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# ZStack 구현을 확인하기 위한 스크립트

# .textureBackground 수정자 구현 검색
echo "Searching for .textureBackground implementation:"
rg --type swift -A 10 "func textureBackground"

# ZStack 사용 검색
echo "\nSearching for ZStack usage:"
rg --type swift -A 5 "ZStack"

Length of output: 10681

Projects/DesignSystem/DesignCore/Sources/BackgroundTextureView.swift (2)

30-34: 이니셜라이저 업데이트 승인

BackgroundTextureView의 이니셜라이저 업데이트는 새로운 ColorType 열거형과 잘 통합되어 있습니다. 이를 통해 사용자가 원하는 배경색을 쉽게 지정할 수 있게 되었습니다. 구현이 간단하고 명확합니다.


63-64: textureBackground 확장 메서드 업데이트 승인

textureBackground 메서드의 업데이트는 BackgroundTextureViewBackgroundTextureViewModifier의 변경사항과 잘 통합되어 있습니다. ColorType 매개변수를 추가함으로써 사용자가 원하는 배경색을 쉽게 지정할 수 있게 되었습니다. 구현이 간결하고 명확합니다.

Comment on lines +52 to 58
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)
}
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로 충분할 것 같습니다.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (3)
Projects/DesignSystem/DesignCore/Sources/BackgroundTextureView.swift (3)

12-28: ColorType 열거형 구현이 잘 되었습니다.

ColorType 열거형의 구현이 명확하고 잘 구조화되어 있습니다. 각 케이스에 대한 색상 값을 계산 속성으로 정의한 것은 좋은 접근 방식입니다.

가독성을 더욱 높이기 위해 각 케이스에 대한 간단한 설명을 주석으로 추가하는 것을 고려해 보세요. 예를 들어:

public enum ColorType {
    /// 기본 배경색
    case `default`
    /// 갈색 계열의 스플래시 배경
    case splashBrown
    // ... 기타 케이스에 대해서도 유사한 주석 추가
}

36-47: body 프로퍼티의 구현이 효과적입니다.

ZStack을 사용하여 색상과 텍스처를 레이어링하는 방식이 적절합니다. type.color를 사용하여 배경색을 동적으로 설정하는 것도 좋은 접근입니다.

성능 최적화를 위해 텍스처 이미지의 크기 조정을 고려해 보세요. 현재 구현에서는 매번 이미지 크기를 조정하고 있습니다. 대신 미리 크기가 조정된 이미지를 사용하거나, @State 변수를 사용하여 크기가 조정된 이미지를 캐시하는 방법을 고려해 볼 수 있습니다.

예를 들어:

@State private var scaledTexture: Image?

var body: some View {
    ZStack {
        type.color
        scaledTexture?
            .resizable()
            .aspectRatio(contentMode: .fill)
            .frame(width: Device.width, height: Device.height)
    }
    .ignoresSafeArea()
    .onAppear {
        if scaledTexture == nil {
            scaledTexture = DesignCore.Images.bgTexture.image
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: Device.width, height: Device.height)
                .clipped()
                .snapshot()
        }
    }
}

extension View {
    func snapshot() -> Image {
        let controller = UIHostingController(rootView: self)
        let view = controller.view
        let targetSize = controller.view.intrinsicContentSize
        view?.bounds = CGRect(origin: .zero, size: targetSize)
        view?.backgroundColor = .clear

        let renderer = UIGraphicsImageRenderer(size: targetSize)
        return Image(uiImage: renderer.image { _ in
            view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true)
        })
    }
}

이 방식을 사용하면 이미지 크기 조정 작업을 한 번만 수행하고 결과를 재사용할 수 있습니다.


68-70: 프리뷰 추가가 유용합니다.

BackgroundTextureView에 대한 프리뷰를 추가한 것은 좋은 접근입니다. 이를 통해 개발 중에 뷰의 모습을 빠르게 확인할 수 있습니다.

다양한 ColorType에 대한 프리뷰를 추가하면 더욱 유용할 것 같습니다. 예를 들어:

#Preview("Default") {
    BackgroundTextureView(.default)
}

#Preview("Splash Brown") {
    BackgroundTextureView(.splashBrown)
}

#Preview("Splash Green") {
    BackgroundTextureView(.splashGreen)
}

#Preview("Splash Purple") {
    BackgroundTextureView(.splashPurple)
}

#Preview("Splash Pink") {
    BackgroundTextureView(.splashPink)
}

이렇게 하면 모든 색상 옵션을 한 눈에 비교하고 확인할 수 있습니다.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ba3f674 and d5e52d8.

Files selected for processing (1)
  • Projects/DesignSystem/DesignCore/Sources/BackgroundTextureView.swift (1 hunks)
Additional comments not posted (2)
Projects/DesignSystem/DesignCore/Sources/BackgroundTextureView.swift (2)

30-34: BackgroundTextureView 초기화 구현이 적절합니다.

ColorType을 매개변수로 받는 새로운 초기화 메서드가 잘 구현되었습니다. type 프로퍼티의 추가로 다양한 배경색 옵션을 지원할 수 있게 되었습니다.


51-65: BackgroundTextureViewModifierView 확장의 변경사항이 적절합니다.

BackgroundTextureViewModifierView 확장의 변경사항이 새로운 ColorType 구현과 잘 통합되어 있습니다. colorType 매개변수를 추가한 것은 적절한 변경입니다.

이전 리뷰에서 제안된 private 접근 제어자 사용이 적용되어 SwiftLint 경고가 해결되었습니다. 이는 코드의 가독성과 유지보수성을 향상시킵니다.

@jisu15-kim jisu15-kim merged commit 1040074 into develop Sep 24, 2024
2 checks passed
@jisu15-kim jisu15-kim deleted the feature/WEAV-65 branch September 24, 2024 14:33
@coderabbitai coderabbitai bot mentioned this pull request Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant