-
Notifications
You must be signed in to change notification settings - Fork 6
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] #231 - 스파크 보내기 시 햅틱 구현 #236
Conversation
- argument 를 사용하지 않고 열거형을 매칭시킬때 생략가능하다.
- StatusButton 으로 의미전달이 잘되지 않던 부분을 SendSparkButton 클래스를 만들고, 어떤 버튼이 눌렸는지는 identifier 를 설정해서 판단할 수 있도록 함. - switch 문으로 같은 코드가 반복되는 것을 forEach 구문에서 조건문을 통해서 구현함. - 해당 선택된 메시지를 저장하고 넘겨줬던 전역변수 selectedMessage 를 없애고 지역변수로 설정해서 스파크 보내기전에는 불필요한 메모리를 차지하지 않도록 함.
- 코드로 오토레이아웃을 잡아주던 부분을 맨 밑으로 이동시켜 가독성을 오림 - 접근제어자 추가
- 버튼 메시지를 상수로 빼서 관리가 용이하게 함.
- sendSparkButton 클래스 생성
- identifier 를 tag 로 대체 - 타이틀과 버튼 선택시 ui 가 변하는 것을 SendSparkButton 에 포함
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.
멋있습니다... 리팩... 배운게 넘흐 많아여!
private func setUI(_ type: SendSparkStatus) { | ||
self.layer.borderColor = UIColor.sparkLightPinkred.cgColor | ||
self.layer.cornerRadius = 2 | ||
self.layer.borderWidth = 1 | ||
self.setTitleColor(.sparkLightPinkred, for: .normal) | ||
self.titleLabel?.font = .krMediumFont(ofSize: 14) |
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.
이렇게 type을 받아서 공통적인 부분과 독립적인 부분을 구분해서 setUI를 해주니 훨씬 직관적이고 코드도 간결해지네요...! 최고선배...잘 배워갑니다.
[firstButton, secondButton, thirdButton, fourthButton].forEach { | ||
if $0.tag == sender.tag { | ||
$0.isSelected(true) | ||
} else { | ||
// 통신실패 시에도 다시금 deselected 되야하니 필요함. | ||
$0.isSelected(false) |
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.
앱잼기간에 코드를 구현할 당시에는 tag를 사용할 줄 몰라서 버튼에 status 프로퍼티를 넣었던 것인데, 추후에 tag에 대해서 알고 tag를 통해서 같은 기능을 구현할 수 있겠다는 생각이 들었었는데요...... 이렇게 또 깔끔하게 보여주시니 감사합니다 헤헿ㅎ
} | ||
} | ||
|
||
sendSparkWithAPI() | ||
let selectedMessage = sender.titleLabel?.text ?? "" |
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.
아...이렇게 해주면 더 메모리 효율적이네요..! 👍
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.
얼마 차이나지는 않겠지만! 지역변수와 전역변수의 역할을 생각해보고 지역변수의 장점을 살리려고했어요!
// MARK: - Layout | ||
|
||
extension SendSparkVC { | ||
private func setLayout() { |
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.
확실히 레이아웃을 밑으로 내리니 보기 좋은 것 같습니다. 코드를 볼 때 레이아웃보다는 기능이 먼저 궁금했던 것 같아서요! 꿀팁 게또...
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.
리펙단계에서 뭔가... 레이아웃에 대한 리펙은 거의 없을듯해서 맨 아래로 보냈습니당.. 수빈선배 몇개 뷰컨이 그렇더라구여 그래서 저도 해봤는데 괜찮은거 같아여
코드베이스로 진행하게되면 레이아웃을 잡는 코드로 뷰컨이 굉장히 무거워지기 때문에 최대한 구분되도록 주석을 통해서 구분해봤어여
private func setFeedbackGenerator() { | ||
selectionFeedbackGenerator = UISelectionFeedbackGenerator() | ||
selectionFeedbackGenerator?.selectionChanged() | ||
} |
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.
음..혹시 이 친구는 뷰 안의 어떤 객체이든간에 selection이 변하는 것이 있으면 다 적용되는건가요?? 만약 햅틱을 적용하고 싶지 않은 버튼이 섞여있다면 범위를 제한하는 방법이 있을까요?
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.
아뇽 그건 아니구 버튼이 눌릴때 호출해주면 됩니당! 그러게요 뭔가 의미상 네이밍이 조금... 이상해진거 같아서 수정보구 정리해둘게요!
public func isSelected(_ isSelected: Bool) { | ||
if isSelected { | ||
self.setTitleColor(.sparkDarkPinkred, for: .normal) | ||
self.backgroundColor = .sparkMostLightPinkred | ||
self.titleLabel?.backgroundColor = .sparkMostLightPinkred | ||
self.layer.borderColor = UIColor.sparkDarkPinkred.cgColor | ||
} else { | ||
self.setTitleColor(.sparkLightPinkred, for: .normal) | ||
self.backgroundColor = .sparkWhite | ||
self.titleLabel?.backgroundColor = .sparkWhite | ||
self.layer.borderColor = UIColor.sparkLightPinkred.cgColor | ||
} | ||
} |
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.
이렇게 하니까 반복이 훨씬 줄어드네요...멋져요!
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.
굉장히 깔꼼하고 배울게 많은 코드들이네요.. 감사합니다람쥐
|
||
import UIKit | ||
|
||
final class SendSparkButton: UIButton { |
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.
좋네요... 굉장히 깔꼼하고... 본받아야겠고...
private var firstButton = SendSparkButton(type: .first) | ||
private var secondButton = SendSparkButton(type: .second) | ||
private var thirdButton = SendSparkButton(type: .third) | ||
private var fourthButton = SendSparkButton(type: .fourth) |
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.
키야...
코드 컨밴션에서 |
🌴 PR 요약
🌱 작업한 브랜치
🌱 작업한 내용
SendSparkVC
와SendSparkButton
커스텀 클래스를 리펙토링.Refactor
empty_enum_arguments
swiftLint 따라 리펙토링public init(type: SendSparkStatus)
를 통해서 오버로딩 개념으로 UI 를 설정.isSelected()
함수를 통해서 UI 를 바꿔주도록 했다.📮 관련 이슈