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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "2bf301bf9fd919e75217c11fc235058bcb75449e4e49796ae197776eed1f67e9",
"originHash" : "97e93c6a85ff0eeec04ba971696cf26844bdef130e04bc6c043da321aa0a1aa2",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -58,7 +58,7 @@
{
"identity" : "rxswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/ReactiveX/RxSwift.git",
"location" : "https://github.com/ReactiveX/RxSwift",
"state" : {
"revision" : "c7c7d2cf50a3211fe2843f76869c698e4e417930",
"version" : "6.8.0"
Expand Down
98 changes: 98 additions & 0 deletions Noostak_iOS/Noostak_iOS/Global/Components/CapsuleButton.swift
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
}
Comment on lines +17 to +20
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 ์œผ๋กœ ์ ‘๊ทผ๋˜๋‹ˆ
์ƒ์œ„ ํƒ€์ž…๊ณผ ๊ฒน์น˜๋Š” ๋„ค์ด๋ฐ์€ ์ง€์–‘ํ•˜์‹œ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค!


// 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
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๋งˆ๋‹ค ๋ฒ„ํŠผ ํƒ€์ดํ‹€์„ ์ถ”๊ฐ€ํ•˜๋Š”๊ฑด ์–ด๋–ต๊ฐ€์š”?

self.capsuleButtonType = type
self.action = action
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.

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

}

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
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 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
Copy link
Contributor

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_ ๋ถ™์—ฌ์ฃผ์‚ผ

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
Copy link
Contributor

Choose a reason for hiding this comment

The 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?()
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

case .normal:
action?()
}
}

}
14 changes: 14 additions & 0 deletions Noostak_iOS/Noostak_iOS/Global/Components/FloatingMenuView.swift
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 {

}