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

πŸ”€ :: (#1114) 마이 νŽ˜μ΄μ§€ ν”„λ‘œν•„ λ²„νŠΌ bouncy μ΄νŽ™νŠΈ μΆ”κ°€ #1134

Merged
merged 1 commit into from
Aug 14, 2024
Merged
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
40 changes: 35 additions & 5 deletions Projects/Features/MyInfoFeature/Sources/Views/ProfileView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import DesignSystem
import Kingfisher
import RxCocoa
import RxGesture
import RxSwift
import SnapKit
import Then
Expand All @@ -22,6 +23,7 @@ final class ProfileView: UIView {
$0.contentMode = .scaleAspectFill
$0.layer.cornerRadius = 92 / 2.0
$0.clipsToBounds = true
$0.isUserInteractionEnabled = true
}

private let nameLabel = WMLabel(
Expand All @@ -48,10 +50,15 @@ final class ProfileView: UIView {
$0.numberOfLines = .zero
}

fileprivate let didTapProfileImageSubject = PublishSubject<Void>()
private let scaleDownTransform = CGAffineTransform(scaleX: 0.9, y: 0.9)
private let disposeBag = DisposeBag()

init() {
super.init(frame: .zero)
addView()
setLayout()
registerGesture()
}

@available(*, unavailable)
Expand All @@ -77,7 +84,7 @@ final class ProfileView: UIView {
}
}

extension ProfileView {
private extension ProfileView {
func addView() {
self.addSubview(imageView)
self.addSubview(nameLabel)
Expand All @@ -103,6 +110,31 @@ extension ProfileView {
$0.centerX.equalToSuperview()
}
}

func registerGesture() {
imageView.rx.longPressGesture(configuration: { gestureRecognizer, delegate in
gestureRecognizer.minimumPressDuration = 0.0
delegate.selfFailureRequirementPolicy = .always
})
.bind(with: self) { owner, gesture in
switch gesture.state {
case .began:
UIViewPropertyAnimator(duration: 0.1, curve: .easeInOut) {
owner.imageView.transform = owner.scaleDownTransform
}
.startAnimation()
case .ended, .cancelled:
let animator = UIViewPropertyAnimator(duration: 0.3, dampingRatio: 0.5, animations: {
owner.imageView.transform = .identity
})
animator.startAnimation()
owner.didTapProfileImageSubject.onNext(())
default:
break
}
}
.disposed(by: disposeBag)
}
}

extension ProfileView: ProfileStateProtocol {
Expand Down Expand Up @@ -140,9 +172,7 @@ extension ProfileView: ProfileStateProtocol {

extension Reactive: ProfileActionProtocol where Base: ProfileView {
var profileImageDidTap: Observable<Void> {
let tapGestureRecognizer = UITapGestureRecognizer()
base.imageView.addGestureRecognizer(tapGestureRecognizer)
base.imageView.isUserInteractionEnabled = true
return tapGestureRecognizer.rx.event.map { _ in }.asObservable()
return base.didTapProfileImageSubject.asObserver()
.throttle(.milliseconds(500), latest: false, scheduler: MainScheduler.asyncInstance)
}
}
Loading