Skip to content

Conversation

@0Hooni
Copy link
Collaborator

@0Hooni 0Hooni commented Dec 1, 2024

🤔 배경

  • 동시 편집에서 활용될 스티커 확대/축소 기능이 필요했다.

📃 작업 내역

  • 로컬에서 드래그 제스처로 스티커를 확대/축소 할 수 있게 하였습니다.
  • 소유권을 가질 수 있는 스티커만 확대/축소 되게 하였습니다.

✅ 리뷰 노트

StickerView.swift

  • StickerView는 다음과 같은 이벤트를 전달해줍니다
protocol StickerViewActionDelegate: AnyObject {
    func stickerView(_ stickerView: StickerView, willBeginResizing sticker: StickerEntity)
    func stickerView(_ stickerView: StickerView, didResize sticker: StickerEntity)
    func stickerView(_ stickerView: StickerView, didEndResize sticker: StickerEntity)
}

CanvasScrollView.swift

  • StickerView의 이벤트를 전달 받습니다.
  • EditPhotoRoomViewController로 전달해줍니다.
extension CanvasScrollView: StickerViewActionDelegate {
   ...

    func stickerView(_ stickerView: StickerView, willBeginResizing sticker: StickerEntity) {
        canvasScrollViewDelegate?.canvasScrollView(self, didBeginResize: sticker)
    }
    
    ...
}

EditPhotoRoomViewController.swift

  • CanvasScrollView로 부터 받은 이벤트를 ViewModel에게 전달해줍니다.
extension EditPhotoRoomGuestViewController: CanvasScrollViewDelegate {
    ...

    func canvasScrollView(_ canvasScrollView: CanvasScrollView, didBeginResize sticker: StickerEntity) {
        input.send(.resizeSticker(sticker, .began))
    }
    
    ...
}

로컬 확대/축소 선반영

StickerView.swift

  • 선반영을 빠르게 구현하기 위해서 현재 구현된 상태로는 단방향을 어긴 상황입니다 🥲
  • 확대/축소의 최대 최소값을 정해주었습니다.(최대 - 128, 최소 - 48)
  • 확대/축소가 시작하고 끝나기 전까지는 사용자의 이벤트를 즉각 반영해줍니다.
  • 확대/축소가 끝나면 SoT를 반영하기 위해 ViewModel을 다녀온 뒤 최종 Frame을 반영해주도록 하였습니다.
@objc private func handleResizePanGesture(_ gesture: UIPanGestureRecognizer) {
    ...
    
    resizePanGestureRecognizer.setTranslation(.zero, in: resizeButton)
    let newFrame = CGRect(origin: sticker.frame.origin, size: traslationStickerSize)
    
    switch gesture.state {
    case .began:
        updateFrame(to: newFrame)
        delegate?.stickerView(self, willBeginResizing: sticker)
    case .changed:
        updateFrame(to: newFrame)
        delegate?.stickerView(self, didResize: sticker)
    case .ended:
        delegate?.stickerView(self, didEndResize: sticker)
    default: break
    }
}

선반영 이후 SoT 적용

StickerView.swift

  • 이벤트허브로부터 이벤트를 전달받아도 만약 확대/축소 중이라면 해당 스티커의 반영을 무시하게 했습니다.
  • 사용자의 확대/축소 이벤트는 정상적으로 이벤트 허브에 전달됩니다.
  • 이벤트허브로부터 다시 돌아온 자신의 이벤트는 부자연스러운 동작을 제공해주기에 블락해줍니다.
func update(with sticker: StickerEntity) {
    switch panGestureRecognizer.state {
    case .began, .changed: return
    default: 
        updateOwner(to: sticker.owner)
        if sticker.owner != user { updateFrame(to: sticker.frame) }
    }
}

EditPhotoRoomViewModel.swift

canInteractWithSticker(id: ): 해당 스티커를 소유할 수 있는지 확인해줍니다.
mutateSticker(EventHub/Local): 해당 스티커를 이벤트 허브나 로컬에 반영해준다.

  • 아래 두개의 이벤트는 이미 Tap을 했을 때 반영되기에 확대/축소에서는 드래그와 다르게 따로 반영해주지 않습니다\

unlockPreviousSticker(stickerId: ): 이전에 소유하던 스티커의 Lock을 해제해줍니다.
lockTappedSticker(id: ): 스티커의 소유권을 나로 변경하고 Lock을 걸어준다.

private func handleResizeBegan(sticker: StickerEntity) {
    guard canInteractWithSticker(id: sticker.id) else { return }
    
    mutateStickerEventHub(type: .update, with: sticker)
}

private func handleResizeChanged(sticker: StickerEntity) {
    guard canInteractWithSticker(id: sticker.id) else { return }
    
    mutateStickerEventHub(type: .update, with: sticker)
}

private func handleResizeEnded(sticker: StickerEntity) {
    mutateStickerLocal(type: .update, sticker: sticker)
    
    guard canInteractWithSticker(id: sticker.id) else { return }
    
    mutateStickerEventHub(type: .update, with: sticker)
}

🎨 스크린샷

동시 확대 축소
확대:축소

🚀 테스트 방법

  • 두개의 시뮬레이터에 EditPhotoRoomFeatureDemo를 실행해줍니다.
  • 한개의 기기에서 SendOffer를 해줍니다.
  • 각각 Host/Guest로 접속합니다
  • 다양한 이벤트를 발생해봅니다.

hsw1920 and others added 8 commits December 1, 2024 21:05
최대 줌 스케일 3->2 배로 변경
이모지 기본 사이즈 64->72로 변경

Co-Authored-By: YeongHoon Song <37678646+0Hooni@users.noreply.github.com>
스티커뷰 서브뷰의 버튼이 프레임에 따라 변경되지 않고 고정사이즈 20으로 변경

Co-Authored-By: YeongHoon Song <37678646+0Hooni@users.noreply.github.com>
Co-Authored-By: YeongHoon Song <37678646+0Hooni@users.noreply.github.com>
드래그 제스처 recognizer를 명확하게 보이도록 변수명 변경

Co-Authored-By: YeongHoon Song <37678646+0Hooni@users.noreply.github.com>
Co-Authored-By: seuhong <66902876+hsw1920@users.noreply.github.com>
Co-Authored-By: seuhong <66902876+hsw1920@users.noreply.github.com>
Co-Authored-By: seuhong <66902876+hsw1920@users.noreply.github.com>
Co-Authored-By: seuhong <66902876+hsw1920@users.noreply.github.com>
@0Hooni 0Hooni added the ✨ feat 새로운 기능 추가 label Dec 1, 2024
@0Hooni 0Hooni linked an issue Dec 1, 2024 that may be closed by this pull request
5 tasks
@hsw1920 hsw1920 changed the base branch from develop to fix/#144-sticker-view-repair December 1, 2024 16:39
@hsw1920 hsw1920 changed the title [FEAT/#148] 스타커 사이즈 조절 기능 추가 [FEAT/#148] 스티커 사이즈 조절 기능 추가 Dec 1, 2024
@hsw1920
Copy link
Collaborator

hsw1920 commented Dec 1, 2024

리뷰에 불필요한 diff가 많아서 develop이 아니라 파생 브랜치에 머지하도록 수정했습니다.
그리고 스타커 사이즈 조절 기능 추가 제목 변경했어요!

Base automatically changed from fix/#144-sticker-view-repair to develop December 1, 2024 17:10
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.

비율 맞춰 사이즈 조절까지!! 너무 좋아요!!👍👍👍

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.

메소드들이 단일 책임만 하고 있는 것 같아 가독성도 좋고 유지보수하기 편할 것 같습니다!! 고생하셨어요!!

@hsw1920 hsw1920 merged commit d1f6f3d into develop Dec 2, 2024
@hsw1920 hsw1920 deleted the feat/#148-resize-sticker branch December 2, 2024 00:53
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.

스티커를 리사이즈 할 수 있다

5 participants