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] #231 - 스파크 보내기 시 햅틱 구현 #236

Merged
merged 11 commits into from
Feb 6, 2022

Conversation

hyun99999
Copy link
Member

@hyun99999 hyun99999 commented Feb 5, 2022

🌴 PR 요약

🌱 작업한 브랜치

🌱 작업한 내용

  • 스파크 보내기 시에 햅틱을 구현하면서 SendSparkVCSendSparkButton 커스텀 클래스를 리펙토링.

참고: https://zeddios.tistory.com/726
현재 selection feedback 인데 강도는 추후에 정해보자. 가장 약한 느낌.

Refactor

SendSparkVC

  • empty_enum_arguments swiftLint 따라 리펙토링
  • switch 문으로 같은 코드가 반복되는 것을 forEach 구문에서 조건문을 통해서 구현함.
  • 해당 선택된 메시지를 저장하고 넘겨줬던 전역변수 selectedMessage 를 없애고 지역변수로 설정해서 스파크 보내기전에는 불필요한 메모리를 차지하지 않도록 함.
  • 코드로 오토레이아웃을 잡아주던 부분을 맨 밑으로 이동시켜 가독성을 올림.
  • 접근제어자 추가.

SendSparkButton

  • final 키워드를 통해서 상속시키지 않을 클래스임을 밝힘.

이점? 여기참조해주세요! : https://velog.io/@ryan-son/Swift-final-키워드-왜-사용하는걸까

  • public init(type: SendSparkStatus) 를 통해서 오버로딩 개념으로 UI 를 설정.

참고: https://ios-development.tistory.com/44
참고: https://ios-development.tistory.com/43

  • StatusButton 으로 의미전달이 잘되지 않던 부분을 SendSparkButton 클래스를 만들고, 어떤 버튼이 눌렸는지는 tag 를 설정해서 판단할 수 있도록 함. SendSparkButton 클래스에서 액션까지 설정하고 싶었지만 서버통신과 햅틱을 지정해야해서 액션이 두개가 중첩되는 부분 발생. 그래서 isSelected() 함수를 통해서 UI 를 바꿔주도록 했다.

📮 관련 이슈

- argument 를 사용하지 않고 열거형을 매칭시킬때 생략가능하다.
- StatusButton 으로 의미전달이 잘되지 않던 부분을 SendSparkButton 클래스를 만들고, 어떤 버튼이 눌렸는지는 identifier 를 설정해서 판단할 수 있도록 함.
- switch 문으로 같은 코드가 반복되는 것을 forEach 구문에서 조건문을 통해서 구현함.
- 해당 선택된 메시지를 저장하고 넘겨줬던 전역변수 selectedMessage 를 없애고 지역변수로 설정해서 스파크 보내기전에는 불필요한 메모리를 차지하지 않도록 함.
- 코드로 오토레이아웃을 잡아주던 부분을 맨 밑으로 이동시켜 가독성을 오림
- 접근제어자 추가
- 버튼 메시지를 상수로 빼서 관리가 용이하게 함.
- sendSparkButton 클래스 생성
- identifier 를 tag 로 대체
- 타이틀과 버튼 선택시 ui 가 변하는 것을 SendSparkButton 에 포함
@hyun99999 hyun99999 added Feat 새로운 기능 구현 👷Refactor👷‍♂️ 동작변화없이 내부구조 변경 👼타락pOwEr천사현규 크로아서버 환영요 labels Feb 5, 2022
@hyun99999 hyun99999 self-assigned this Feb 5, 2022
Copy link
Member

@L-j-h-c L-j-h-c left a comment

Choose a reason for hiding this comment

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

멋있습니다... 리팩... 배운게 넘흐 많아여!

Comment on lines +41 to +46
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)
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 type을 받아서 공통적인 부분과 독립적인 부분을 구분해서 setUI를 해주니 훨씬 직관적이고 코드도 간결해지네요...! 최고선배...잘 배워갑니다.

Comment on lines +71 to +76
[firstButton, secondButton, thirdButton, fourthButton].forEach {
if $0.tag == sender.tag {
$0.isSelected(true)
} else {
// 통신실패 시에도 다시금 deselected 되야하니 필요함.
$0.isSelected(false)
Copy link
Member

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 ?? ""
Copy link
Member

Choose a reason for hiding this comment

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

아...이렇게 해주면 더 메모리 효율적이네요..! 👍

Copy link
Member Author

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() {
Copy link
Member

Choose a reason for hiding this comment

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

확실히 레이아웃을 밑으로 내리니 보기 좋은 것 같습니다. 코드를 볼 때 레이아웃보다는 기능이 먼저 궁금했던 것 같아서요! 꿀팁 게또...

Copy link
Member Author

Choose a reason for hiding this comment

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

리펙단계에서 뭔가... 레이아웃에 대한 리펙은 거의 없을듯해서 맨 아래로 보냈습니당.. 수빈선배 몇개 뷰컨이 그렇더라구여 그래서 저도 해봤는데 괜찮은거 같아여
코드베이스로 진행하게되면 레이아웃을 잡는 코드로 뷰컨이 굉장히 무거워지기 때문에 최대한 구분되도록 주석을 통해서 구분해봤어여

Comment on lines 60 to 63
private func setFeedbackGenerator() {
selectionFeedbackGenerator = UISelectionFeedbackGenerator()
selectionFeedbackGenerator?.selectionChanged()
}
Copy link
Member

Choose a reason for hiding this comment

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

음..혹시 이 친구는 뷰 안의 어떤 객체이든간에 selection이 변하는 것이 있으면 다 적용되는건가요?? 만약 햅틱을 적용하고 싶지 않은 버튼이 섞여있다면 범위를 제한하는 방법이 있을까요?

Copy link
Member Author

Choose a reason for hiding this comment

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

아뇽 그건 아니구 버튼이 눌릴때 호출해주면 됩니당! 그러게요 뭔가 의미상 네이밍이 조금... 이상해진거 같아서 수정보구 정리해둘게요!

Comment on lines +64 to +76
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
}
}
Copy link
Member

Choose a reason for hiding this comment

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

이렇게 하니까 반복이 훨씬 줄어드네요...멋져요!

Copy link
Member

@yangsubinn yangsubinn left a 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 {
Copy link
Member

Choose a reason for hiding this comment

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

좋네요... 굉장히 깔꼼하고... 본받아야겠고...

Comment on lines +18 to +21
private var firstButton = SendSparkButton(type: .first)
private var secondButton = SendSparkButton(type: .second)
private var thirdButton = SendSparkButton(type: .third)
private var fourthButton = SendSparkButton(type: .fourth)
Copy link
Member

Choose a reason for hiding this comment

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

키야...

@hyun99999
Copy link
Member Author

코드 컨밴션에서 setAddTargets() 에서는 버튼에 대한 액션을 부여했는데 SendSparkVC 에서 파라미터로 버튼들을 받고 받은 모든 버튼에 대해서 액션을 부여하니까 준호선배가 말한 질문이 나온거 같아여! 그래서 컨밴션에 맞게 setAddTargets() 메서드에서는 버튼들의 액션을 설정하는 역할에 집중을 해주었습니다!
파라미터에 UIButton... 과 같이 받는 형태 좋았는데 다른 곳에서 사용해보면 좋겠네여~

@hyun99999 hyun99999 merged commit 01596ef into TeamSparker:develop Feb 6, 2022
@hyun99999 hyun99999 deleted the feature/#231 branch February 6, 2022 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feat 새로운 기능 구현 👼타락pOwEr천사현규 크로아서버 환영요 👷Refactor👷‍♂️ 동작변화없이 내부구조 변경
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat] 스파크 보내기 시 햅틱 구현
3 participants