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

[#8] chipViewController 생성 #15

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

[#8] chipViewController 생성 #15

wants to merge 9 commits into from

Conversation

jysuhr
Copy link

@jysuhr jysuhr commented Aug 2, 2024

📌 Summary

  • chip 상태에 따른 색상 변경 (enable / disable)
  • chip isSelected에 따른 색상 변경
  • chip Size에 따라 height 값 차이 구현 (large / small)
  • chip 에 작성되는 글자수 10자로 제한

✍️ Description

💡 PR Point

  • chip size와 통일하여, chip의 상태를 지정할 때 변수의 이름을 state로 지정하고 싶었지만 UIControl에서 state를 사용중이어서 chipState로 지정하였습니다.
  • icon 은 figma에서 icon을 PNG파일로 Export하여 사용했습니다.

📚 Reference

🔥 Test

스크린샷 2024-09-03 오후 11 46 35

사용방법

// enabled 상태(기본), Large(기본), isSelected X
let unTappedLargeChip: HandyChip = {
    let chip = HandyChip()
    chip.chipState = HandyChip.ChipState(type: .enabled)
    chip.size = HandyChip.ChipSize(type: .large)
    chip.isSelected = false
    chip.text = "Label"
    chip.leftIcon = UIImage(named: "icInfoCircle")
    chip.rightIcon = UIImage(named: "icClose")
    chip.addTarget(self, action: #selector(firstChip), for: .touchUpInside)
    chip.translatesAutoresizingMaskIntoConstraints = false
    return chip
}()

@jysuhr jysuhr added the feat 💜 새로운 기능 구현 label Aug 2, 2024
@jysuhr jysuhr self-assigned this Aug 2, 2024
Copy link

@kimsoomin20221789 kimsoomin20221789 left a comment

Choose a reason for hiding this comment

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

첫 이슈! 수고하셨습니다!

Handy/Handy-Storybook/Atom/ChipViewController.swift Outdated Show resolved Hide resolved
Handy/Handy-Storybook/Atom/ChipViewController.swift Outdated Show resolved Hide resolved
Handy/Handy-Storybook/Atom/ChipViewController.swift Outdated Show resolved Hide resolved
@jysuhr jysuhr changed the title Feature/#8 [#8] chipViewController 생성 Aug 12, 2024
Copy link
Contributor

@hye0njuoo hye0njuoo left a comment

Choose a reason for hiding this comment

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

수고하셨습니다.
몇가지 추가되어야 할부분이 있는 것 같아요

  • icon 추가
  • 좌우 icon on/off 기능 추가

Handy/Handy/Source/Atom/HandyChip.swift Outdated Show resolved Hide resolved
Comment on lines +15 to +25
@Invalidating(wrappedValue: nil, .layout) public var text: String? {
didSet {
if let text = text, text.count > 10 {
self.text = String(text.prefix(10))
}
setNeedsLayout()
}
}

@Invalidating(wrappedValue: nil, .layout) public var leftIcon: UIImage?
@Invalidating(wrappedValue: nil, .layout) public var rightIcon: UIImage?
Copy link
Member

Choose a reason for hiding this comment

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

@Invalidating을 사용한 이유가 궁금합니다!

Copy link
Author

Choose a reason for hiding this comment

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

@Invalidating을 통해 HandyChip의 text와 leftIcon, rightIcon 프로퍼티를 선언함으로서 HandyChip에서 해당 프로퍼티를 지정했을 때 HandyChip 레이아웃을 다시 그리도록 하기 위해 사용했습니다. 프로퍼티 값이 변경되었을 때 setNeedsLayout()을 직접 호출하지 않아도 되어서 코드를 간결화할 수 있었습니다.

Comment on lines +91 to +98
override func setViewHierarchies() {
view.addSubview(unTappedLargeChip)
view.addSubview(unTappedSmallChip)
view.addSubview(tappedLargeChip)
view.addSubview(tappedSmallChip)
view.addSubview(disabledLargeChip)
view.addSubview(disabledSmallChip)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
override func setViewHierarchies() {
view.addSubview(unTappedLargeChip)
view.addSubview(unTappedSmallChip)
view.addSubview(tappedLargeChip)
view.addSubview(tappedSmallChip)
view.addSubview(disabledLargeChip)
view.addSubview(disabledSmallChip)
}
override func setViewHierarchies() {
[unTappedLargeChip,
unTappedSmallChip,
tappedLargeChip,
tappedSmallChip,
disabledLargeChip,
disabledSmallChip
].forEach {
view.addSubview($0)
}
}

view.addSubviews(unTappedLargeChip, unTappedSmallChip, tappedLargeChip, tappedSmallChip, disabledLargeChip, disabledSmallChip) 이런식으로도 사용하실 수 있어요~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat 💜 새로운 기능 구현
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants