Skip to content

Conversation

@hsw1920
Copy link
Collaborator

@hsw1920 hsw1920 commented Nov 11, 2024

🤔 배경

  • 많은 화면에서 재활용되는 마이크 버튼 공통 컴포넌트가 필요했습니다.
  • tap 하여 토글되었을 때 이벤트를 감지할 수 있도록 Combine에서 따로 지원하지 않는 TapPublisher도 필요했습니다.
image

📃 작업 내역

  • UIControlcontrolPublisher() 구현
  • UIControlEvent.touchUpInside를 감지하는 tapPublisherUIButton에 확장
  • PTGMicButton 구현

✅ 리뷰 노트

  1. PTGMicButton은 기본적으로 아래와 같은 프로퍼티와 메서드를 갖습니다.
public final class PTGMicButton: UIButton {
    ...
    private var micState: PTGMicState

    public func toggleMicState() { }
    ...
}
  • micStateon/off 상태를 가지며 toggleMicState()를 통해 각 state에 맞게 적절한 UI를 변경할 수 있습니다.
  1. tapPublisher를 구현하였습니다.
        button.tapPublisher
            .sink { [weak self] _ in
                self?.button.toggleMicState()
            }.store(in: &cancellables)
  • 위 예시처럼 사용가능합니다.
  1. controlPublisher()를 통해 UIControl.Event를 구독할 수 있습니다.
        button.controlPublisher(for: .touchDown)
            .map { _ in }
            .eraseToAnyPublisher()
            .sink { [weak self] _ in
                print("touchDown")
            }.store(in: &cancellables)
        
        button.controlPublisher(for: .touchUpOutside)
            .map { _ in }
            .eraseToAnyPublisher()
            .sink { [weak self] _ in
                print("touchUpOutSide")
            }.store(in: &cancellables)
  • UIControl.Event의 경우 범용적으로 많이 사용될 가능성이 있어 public으로 열어뒀습니다.

🎨 스크린샷

마이크 버튼 토글
마이크버튼

🚀 테스트 방법

  • 위 스크린샷은 데모를 통해 임의로 구현된 예시입니다.
  • 테스트하려면 DesignSystem의 PTGMicButton 인스턴스를 선언하여 테스트 부탁드립니다.

hsw1920 and others added 2 commits November 11, 2024 21:31
Co-Authored-By: YeongHoon Song <37678646+0Hooni@users.noreply.github.com>
- UIControl을 상속받는 객체 또한 controlPublihser를 통해서 UIControl.Event에 대한 모든 퍼블리셔를 만들 수 있습니다.
- UIButton을 상속받는 모든 객체는 tapPublisher를 확장하여 사용할 수 있습니다.

Co-Authored-By: YeongHoon Song <37678646+0Hooni@users.noreply.github.com>
@hsw1920 hsw1920 added the ✨ feat 새로운 기능 추가 label Nov 11, 2024
@hsw1920 hsw1920 linked an issue Nov 11, 2024 that may be closed by this pull request
2 tasks
Copy link
Member

@youn9k youn9k left a comment

Choose a reason for hiding this comment

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

Publisher 들 구현해둔 게 엄청 편할 것 같아요! 익스텐션은 FeatureUtility 모듈에 두기로 했었는데 이렇게 보니 굳이 두개의 모듈로 쪼갤 필요가 있나 싶어서 지금처럼 BaseFeature에 두고, FeatureUtility모듈을 없애는 것도 좋아보입니다ㅎㅎ

Copy link
Member

@Kiyoung-Kim-57 Kiyoung-Kim-57 left a comment

Choose a reason for hiding this comment

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

Combine에 대한 이해가 부족해서 읽는데 오래걸렸습니다! 확실히 Publisher로 탭 이벤트를 관리하니 사용하기 훨씬 편해보이는 것 같습니다!! 고생하셨습니다!

@0Hooni 0Hooni merged commit 67aee30 into develop Nov 11, 2024
@0Hooni 0Hooni deleted the feat/#12-create-mic-button branch November 11, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ feat 새로운 기능 추가

Projects

None yet

Development

Successfully merging this pull request may close these issues.

마이크 UI 버튼을 구현한다

5 participants