Skip to content

Commit

Permalink
[#27] HandyListItem Pressed 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJoEun-01 committed Jan 4, 2025
1 parent 0345d0d commit fd0d88d
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 34 deletions.
16 changes: 11 additions & 5 deletions Handy/Handy-Storybook/Atom/HandyListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,32 @@ final class HandyListViewController: BaseViewController {
}()

private var listItem2: HandyListItem = {
let listItem = HandyListItem()
listItem.title = "아이디 변경"
listItem.leadingIcon = .icUserLine
return listItem
}()

private var listItem3: HandyListItem = {
let listItem = HandyListItem()
listItem.title = "비밀번호 변경"
listItem.trailingIcon = .icArrowsChevronRightLine
return listItem
}()

private var listItem3: HandyListItem = {
private var listItem4: HandyListItem = {
let listItem = HandyListItem()
listItem.title = "이용약관"
listItem.listState = .disabled
return listItem
}()



override func viewDidLoad() {
super.viewDidLoad()
}

override func setViewHierarchies() {
list.addArrangedSubview(listItem1)
list.addArrangedSubview(listItem1, listItem2, listItem3, listItem4)

self.view.addSubview(list)

Expand All @@ -48,7 +54,7 @@ final class HandyListViewController: BaseViewController {
override func setViewLayouts() {
list.snp.makeConstraints {
$0.top.equalToSuperview().inset(100)
$0.leading.trailing.equalToSuperview()
$0.centerX.equalToSuperview()
}
}
}
1 change: 1 addition & 0 deletions Handy/Handy/Source/Atom/List/HandyList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ final public class HandyList: UIView {
private func setAutolayout() {
stackView.snp.makeConstraints {
$0.edges.equalToSuperview()
$0.width.equalTo(375)
}
}

Expand Down
107 changes: 78 additions & 29 deletions Handy/Handy/Source/Atom/List/HandyListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ final public class HandyListItem: UIView {
*/
@Invalidating(.display) public var listState: ListState = .enabled

private var isPressed: Bool = false

private var tapGesture: UILongPressGestureRecognizer?

public enum ListState {
case enabled
case disabled
Expand All @@ -49,13 +53,22 @@ final public class HandyListItem: UIView {
return HandySemantic.listDisabled
}
}

fileprivate var fgColor: UIColor {
switch self {
case .enabled:
return HandySemantic.textBasicPrimary
case .disabled:
return HandySemantic.textBasicDisabled
}
}
}

private var titleLabel: HandyLabel = {
let label = HandyLabel()
label.style = .B1Rg16
label.textColor = HandySemantic.textBasicPrimary
// label.alignment = .left
label.textAlignment = .left
label.numberOfLines = 1
return label
}()
Expand Down Expand Up @@ -108,57 +121,93 @@ final public class HandyListItem: UIView {
$0.height.equalTo(64)
}

leftIcon.snp.makeConstraints {
$0.leading.equalToSuperview().inset(16)
$0.size.equalTo(24)
$0.centerY.equalToSuperview()
}
if leadingIcon == nil {
leftIcon.isHidden = true

rightIcon.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(16)
$0.size.equalTo(24)
$0.centerY.equalToSuperview()
titleLabel.snp.makeConstraints {
$0.leading.equalToSuperview().inset(16)
$0.centerY.equalToSuperview()
}
} else {
leftIcon.isHidden = false

leftIcon.snp.makeConstraints {
$0.leading.equalToSuperview().inset(16)
$0.size.equalTo(24)
$0.centerY.equalToSuperview()
}

titleLabel.snp.remakeConstraints {
$0.leading.equalTo(leftIcon.snp.trailing).offset(16)
$0.centerY.equalToSuperview()
}
}

titleLabel.snp.makeConstraints {
$0.leading.equalTo(leftIcon.snp.trailing).offset(16)
$0.leading.equalToSuperview().inset(56)
$0.centerY.equalToSuperview()
if trailingIcon == nil {
rightIcon.isHidden = true
} else {
rightIcon.isHidden = false

rightIcon.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(16)
$0.size.equalTo(24)
$0.centerY.equalToSuperview()
}
}
print("=== setAutoLayout")
}

private func setIcon() {
leftIcon.image = leadingIcon?.withRenderingMode(.alwaysTemplate)
leftIcon.tintColor = listState.fgColor
rightIcon.image = trailingIcon?.withRenderingMode(.alwaysTemplate)

if trailingIcon == nil {
rightIcon.isHidden = true
}
if leadingIcon != nil && trailingIcon != nil {
leftIcon.isHidden = false
rightIcon.isHidden = false
}
print("=== setIcon")
rightIcon.tintColor = listState.fgColor
}

private func setLabel() {
titleLabel.text = title
titleLabel.textColor = listState.fgColor

if leadingIcon == nil {
leftIcon.isHidden = true
self.backgroundColor = listState.bgColor
}

titleLabel.snp.updateConstraints {
$0.leading.equalToSuperview().inset(16)
private func setupGestureRecognizer() {
if listState == ListState.enabled {
let gesture = UILongPressGestureRecognizer(target: self, action: #selector(pressedAction(_:)))
self.tapGesture = gesture
self.tapGesture?.minimumPressDuration = 0
if let tapGesture = self.tapGesture {
self.addGestureRecognizer(tapGesture)
}
self.isUserInteractionEnabled = true
}
}

@objc public func pressedAction(_ gesture: UILongPressGestureRecognizer) {
switch gesture.state {
case .began:
self.backgroundColor = HandySemantic.listPressed
case .ended, .cancelled, .failed:
self.backgroundColor = listState.bgColor
default:
break
}
print("=== setLabel")
}


public override func setNeedsLayout() {
setAutoLayout()

setIcon()
setLabel()
}

public override func setNeedsDisplay() {
if let gesture = tapGesture {
self.removeGestureRecognizer(gesture)
}
tapGesture = nil

setupGestureRecognizer()
}

}

0 comments on commit fd0d88d

Please sign in to comment.