Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

[Refactor] CollectionView Self-Sizing Cell 구현 #135

Open
ChoiysApple opened this issue Aug 19, 2024 · 0 comments
Open

[Refactor] CollectionView Self-Sizing Cell 구현 #135

ChoiysApple opened this issue Aug 19, 2024 · 0 comments
Labels
♻️ Refactor 리팩토링

Comments

@ChoiysApple
Copy link
Member

Describe

  • 현재 대부분의 UICollectionView의 item 크기가 fixed 또는, figma 가이드를 보고 상수를 넣어 계산하는 방식으로 되어있음

Existing

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

    let label = SPLabel(KRFont.B1_regular).then {
        $0.setText(string)
        $0.sizeToFit()
    }
    let size = label.frame.size
    let maxWidth = UIScreen.main.bounds.width - 32
    let additionalWidth: CGFloat = 24 + 14 + 8
    let width = min(maxWidth, additionalWidth + size.width)
    return CGSize(width: width, height: 40)
}
  • 이런 방식의 코드는 이슈 발생하기 쉬움
  • Cell UI 변경되면 엄청나게 열받는 상황 발생

Benefits

  • UI 구조 변경에 대응 가능

Reference

Additional context

@ChoiysApple ChoiysApple added the ♻️ Refactor 리팩토링 label Aug 19, 2024
@ChoiysApple ChoiysApple added this to the 1차 리팩토링 milestone Aug 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
♻️ Refactor 리팩토링
Projects
None yet
Development

No branches or pull requests

1 participant