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

[Feat/#24] CapsuleButton Component #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jaminleee
Copy link
Collaborator

๐Ÿ”ฅ Issue

close #


๐Ÿ”ฅ ๋ณ€๊ฒฝ๋œ ๋‚ด์šฉ

expand๋Š” ๋„ˆ๋น„๊ฐ€ ํ† ๊ธ€๋˜๋ฉด์„œ ๋ฐ”๋€Œ๋Š” ๋…€์„, normal์€ ํ‰๋ฒ”ํ•œ ์บก์Š ๋ฒ„ํŠผ
UIImage(systemName: "plus") ์ด ๋ถ€๋ถ„๋„ defaultTitle๊ณผ ๊ฐ™์ด ์ดˆ๊ธฐํ™” ๋•Œ ๋ฐ›์€ ์•„์ด์ฝ˜์œผ๋กœ ํ† ๊ธ€๋˜๊ฒŒ ๋ฐ”๊ฟ”์ค˜์•ผํ•˜๋Š”๋ฐ ์ผ๋‹จ ๋” ์ˆ˜์ •ํ•˜๊ฒ ์Œ..
๋จธ๋ฆฌ๊ฐ€ ์ž˜ ์•ˆ๋Œ์•„๊ฐ€์„œ ๋งŽ์€ ํ”ผ๋“œ๋ฐฑ ๋ถ€ํƒ......ใ…œใ…œ
๋‹ค ํ•œ๊ฑฐ ์•„๋‹ˆ๊ณ  ๋‚ผ ๋” ์ถ”๊ฐ€ํ•˜๊ฒ ์‚ผ ใ… ใ… 

๐Ÿ”ฅ PR Point

// CapsuleButton
    private func updateButton(isExpanded: Bool) {
        let title = isExpanded ? "" : defaultTitle
        let icon = isExpanded ? UIImage(systemName: "xmark") : UIImage(systemName: "plus")
        configure(title: title, icon: icon)
        
        self.backgroundColor = isExpanded ? .appBlue50 : .appBlack
        self.setTitleColor(isExpanded ? .appBlack : .appWhite, for: .normal)
        self.tintColor = isExpanded ? .appBlack : .appWhite
        
        let newWidth = isExpanded ? 50 : 100
        self.widthConstraint?.update(offset: newWidth)
        UIView.animate(withDuration: 0.3) {
            self.superview?.layoutIfNeeded()
        }
    }
    
    // MARK: - Actions
    @objc private func buttonTapped() {
        switch capsuleButtonType {
        case .expand(let isExpanded):
            let newState = !isExpanded
            capsuleButtonType = .expand(isExpanded: newState)
            updateButton(isExpanded: newState)
            action?()
        case .normal:
            action?()
        }
    }

์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉ

        let groupButton = CapsuleButton(
            type: .expand(isExpanded: false),
            title: "๊ทธ๋ฃน์ถ”๊ฐ€",
            icon: UIImage(systemName: "plus")
        ) {
            print("๊ทธ๋ฃน ๋ฒ„ํŠผ์ด ๋ˆŒ๋ ธ์Šต๋‹ˆ๋‹ค.")
        }
        
        let appointmentButton = CapsuleButton(type: .normal, title: "์•ฝ์†์ถ”๊ฐ€", icon: UIImage(systemName: "plus")) {
            print("์•ฝ์† ๋ฒ„ํŠผ ๋ˆŒ๋ฆผ")
        }

๐Ÿ”ฅ ScreenShot

Simulator Screen Recording - iPhone 16 Pro - 2025-01-11 at 04 53 00


๐Ÿ”ฅ Reference


@jaminleee jaminleee added the Feat ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ๊ตฌํ˜„ label Jan 10, 2025
@jaminleee jaminleee self-assigned this Jan 10, 2025

// MARK: - Initializer
init(type: CapsuleButtonType, title: String, icon: UIImage?, action: (() -> Void)? = nil) {
self.defaultTitle = title
Copy link
Collaborator

Choose a reason for hiding this comment

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

CapsuleType์ด ๋‘ ๊ฐœ๋ฐ–์— ์—†๋Š” ๊ฑฐ ๊ฐ™์€๋ฐ, ์—ฌ๊ธฐ์„œ title์„ ๋”ฐ๋กœ ๋ฐ›์ง€ ๋ง๊ณ  ๊ฐ case๋งˆ๋‹ค ๋ฒ„ํŠผ ํƒ€์ดํ‹€์„ ์ถ”๊ฐ€ํ•˜๋Š”๊ฑด ์–ด๋–ต๊ฐ€์š”?

super.init(frame: .zero)
setupUI()
configure(title: title, icon: icon)
addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
Copy link
Collaborator

Choose a reason for hiding this comment

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

rx ํ•œ์†์œผ๋กœ ๋Œ๋ ค์ฃผ์„ธ์š”

Copy link
Collaborator

Choose a reason for hiding this comment

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

ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹๋Œ๋ ค์ฃผ์„ธ์š”


private func updateButton(isExpanded: Bool) {
let title = isExpanded ? "" : defaultTitle
let icon = isExpanded ? UIImage(systemName: "xmark") : UIImage(systemName: "plus")
Copy link
Collaborator

Choose a reason for hiding this comment

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

์•„์ด์ฝ˜์€ ์•ž์— ic_ ๋ถ™์—ฌ์ฃผ์‚ผ

Comment on lines +65 to +67
private func updateWidth(isExpanded: Bool) {

}
Copy link
Contributor

Choose a reason for hiding this comment

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

์ด๊ฑด ๋ญ”๊ฐ€์š”?

Comment on lines +80 to +82
UIView.animate(withDuration: 0.3) {
self.superview?.layoutIfNeeded()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

์ด ์ฝ”๋“œ๋Š” ๋ญํ•˜๋Š” ์ฝ”๋“œ ์ธ๊ฐ€์š”??

Copy link
Collaborator

@FpRaArNkK FpRaArNkK left a comment

Choose a reason for hiding this comment

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

๊ณ ์ƒ ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค! ๋ช‡๊ฐ€์ง€ ์ˆ˜์ •์‚ฌํ•ญ์ด ๋ณด์ด๋Š”๋ฐ ์ด๋ฏธ ๋‹ค๋ฅธ๋ถ„๋“ค์ด ์ž˜ ๋‚จ๊ฒจ์ฃผ์…”์„œ ์ถ”๊ฐ€ ๋ฉ˜ํŠธ๋งŒ ์ž‘์„ฑํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค

super.init(frame: .zero)
setupUI()
configure(title: title, icon: icon)
addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹๋Œ๋ ค์ฃผ์„ธ์š”

Comment on lines +17 to +20
enum CapsuleButtonType {
case expand(isExpanded: Bool)
case normal
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nested Type์ธ ๊ฒฝ์šฐ
CapsuleButton.CapsuleButtonType ์œผ๋กœ ์ ‘๊ทผ๋˜๋‹ˆ
์ƒ์œ„ ํƒ€์ž…๊ณผ ๊ฒน์น˜๋Š” ๋„ค์ด๋ฐ์€ ์ง€์–‘ํ•˜์‹œ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค!

Comment on lines +44 to +54
private func setupUI() {
self.do {
$0.backgroundColor = .appBlack
$0.layer.cornerRadius = 25
}

self.snp.makeConstraints {
$0.height.equalTo(50)
self.widthConstraint = $0.width.equalTo(100).constraint
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

ํŒ€ ์ฝ”๋“œ ์ปจ๋ฒค์…˜ ๋งž์ถฐ์ฃผ์‹ญ์‡ผ!

let newState = !isExpanded
capsuleButtonType = .expand(isExpanded: newState)
updateButton(isExpanded: newState)
action?()
Copy link
Collaborator

Choose a reason for hiding this comment

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

์ด๊ฑด ์–ด๋–ค ์˜๋„๋กœ ์ž‘์„ฑํ•˜์‹ ๊ฑธ๊นŒ์š”?

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.

4 participants