-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// | ||
// CapsuleButton.swift | ||
// Noostak_iOS | ||
// | ||
// Created by ์ด์๋ฏผ on 1/9/25. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
import Then | ||
import RxSwift | ||
import RxCocoa | ||
|
||
final class CapsuleButton: UIButton { | ||
|
||
// MARK: - Enum | ||
enum CapsuleButtonType { | ||
case expand(isExpanded: Bool) | ||
case normal | ||
} | ||
|
||
// MARK: - Properties | ||
var capsuleButtonType: CapsuleButtonType | ||
private var action: (() -> Void)? | ||
private var widthConstraint: Constraint? | ||
private let defaultTitle: String | ||
|
||
// MARK: - Initializer | ||
init(type: CapsuleButtonType, title: String, icon: UIImage?, action: (() -> Void)? = nil) { | ||
self.defaultTitle = title | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CapsuleType์ด ๋ ๊ฐ๋ฐ์ ์๋ ๊ฑฐ ๊ฐ์๋ฐ, ์ฌ๊ธฐ์ title์ ๋ฐ๋ก ๋ฐ์ง ๋ง๊ณ ๊ฐ case๋ง๋ค ๋ฒํผ ํ์ดํ์ ์ถ๊ฐํ๋๊ฑด ์ด๋ต๊ฐ์? |
||
self.capsuleButtonType = type | ||
self.action = action | ||
super.init(frame: .zero) | ||
setupUI() | ||
configure(title: title, icon: icon) | ||
addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rx ํ์์ผ๋ก ๋๋ ค์ฃผ์ธ์ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ใ ๋๋ ค์ฃผ์ธ์ |
||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Setup UI | ||
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 | ||
} | ||
} | ||
Comment on lines
+44
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ํ ์ฝ๋ ์ปจ๋ฒค์ ๋ง์ถฐ์ฃผ์ญ์ผ! |
||
|
||
private func configure(title: String, icon: UIImage?) { | ||
self.setTitle(title, for: .normal) | ||
self.setTitleColor(.appWhite, for: .normal) | ||
self.titleLabel?.font = .PretendardStyle.b4_sb.font | ||
self.setImage(icon, for: .normal) | ||
self.tintColor = .appWhite | ||
self.imageView?.contentMode = .scaleAspectFit | ||
} | ||
|
||
private func updateWidth(isExpanded: Bool) { | ||
|
||
} | ||
Comment on lines
+65
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์์ด์ฝ์ ์์ ic_ ๋ถ์ฌ์ฃผ์ผ |
||
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() | ||
} | ||
Comment on lines
+80
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด ์ฝ๋๋ ๋ญํ๋ ์ฝ๋ ์ธ๊ฐ์?? |
||
} | ||
|
||
// MARK: - Actions | ||
@objc private func buttonTapped() { | ||
switch capsuleButtonType { | ||
case .expand(let isExpanded): | ||
let newState = !isExpanded | ||
capsuleButtonType = .expand(isExpanded: newState) | ||
updateButton(isExpanded: newState) | ||
action?() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด๊ฑด ์ด๋ค ์๋๋ก ์์ฑํ์ ๊ฑธ๊น์? |
||
case .normal: | ||
action?() | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// FloatingMenuView.swift | ||
// Noostak_iOS | ||
// | ||
// Created by ์ด์๋ฏผ on 1/11/25. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
import Then | ||
|
||
class FloatingMenuView: UIView { | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nested Type์ธ ๊ฒฝ์ฐ
CapsuleButton.CapsuleButtonType ์ผ๋ก ์ ๊ทผ๋๋
์์ ํ์ ๊ณผ ๊ฒน์น๋ ๋ค์ด๋ฐ์ ์ง์ํ์๋ฉด ์ข์ต๋๋ค!