-
Notifications
You must be signed in to change notification settings - Fork 2
[FEAT/#77] 스티커를 선택할 수 있는 기능을 구현합니다. #81
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
Conversation
- tapPublisher에 대한 구독은 StickerView에서 관리할 수 있도록 탈출 클로저 구현 - StickerView는 쉽게 생성/삭제가 가능하므로 EditPhotoViewController에서 cancellables에서 관리하기에는 무리가 있었음.
- StickerEntity는 struct이므로 변경을 위해 mutating 메서드 구현 - StickerEntity는 매우 자주 참조 되어 변경될 수 있어 class로 두는 것을 고려했지만, 그만큼 상태관리에 매우 큰 어려움이 있기 때문에 불변성을 위해 struct를 유지하였음. - StickerView를 업데이트 하는 것을 ViewController가 직접 변경하는 것이 아닌 StickerView에게 요청하도록 책임을 분리 - StickerView는 이전 StickerEntity를 통해 이전 상태를 파악하여 변경이 없다면 업데이트하지 않도록 구현 - StickerView에 StickerEntity를 두어 메모리는 추가되었지만, 이전 상태를 알고 불필요한 업데이트를 하지 않는 것이 더 리소스가 적다고 판단하였음. - 또한 StickerEntity 하나의 데이터는 상대적으로 매우 작기 때문에 이러한 방식이 적합하다고 판단함.
- SticekrView를 탭하는 이벤트 추가
- unlock을 위해서는 EventHub에서 해당 Sticker의 unlock을 요청하는 owner와 기존 owner를 비교할 수 있어야했으나 이 기능이 없었음.
- 기존 코드는 EventHub로부터 stickerList를 받았을 때 변경이 없는 경우 무시하는 코드였음 - 하지만 이를 비교하는 로직은 StickerEntity의 id만으로 같은 지 확인하기 때문에 예상한 동작이 일어나지 않았음. - StickerView 단에서 변경사항을 파악하여 업데이트 여부를 결정하기 때문에 제거하였음.
- 임시 값으로써 추후 ConnectionClient에서 User를 구분하는 기능이 추가될 시 제거 예정
### Flow 1. 선택할 수 있는 객체인지 확인함 (owner가 nil이거나, 자신이거나) 2. 자신이 선택하는 객체는 유일함. 따라서 기존에 선택했던 객체가 있다면 unlock을 하고 이를 EventHub에 반영을 요청. 3. 선택한 객체를 lock하고 EventHub에 반영을 요청 ### Extension - 코드 중복을 방지하기 위해 자주 사용하는 StickerEntity 배열을 확장하였음. - `isOwned(id: UUID, owner: String) -> Bool` : 해당 `id`와 `owner`를 통해 해당 `id`의 `StickerEntity`가 내가 소유할 수 있는 지 확인하는 메서드 - `lockedSticker(by owner: String) -> StickerEntity?` : 자신이 소유하고 있는 `StickerEntity`를 반환하는 메서드 - `unlock(by owner: String)` : 내가 소유하고 있는 `StickerEntity`를 unlock하는 메서드 - `lock(by id: UUID, owner: String) -> StickerEntity?` : 해당 `id`의 `StickerEntity`를 자신이 소유하도록 요청하는 메서드
lock을 확인하거나, lock을 하거나, 선택가능한 지 확인 하는 것은 모두 재활용이 가능함
- queue가 비었을 때는 popPublisher가 false를 방출해야함. - queue가 보낼 게 있을 때만 true여야 함.
Kiyoung-Kim-57
left a comment
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.
우와...설계부터 구현까지 엄청 복잡하네요!! 고생하셨습니다!
...er/PresentationLayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/View/StickerView.swift
Outdated
Show resolved
Hide resolved
...er/PresentationLayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/View/StickerView.swift
Show resolved
Hide resolved
...ayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/EditPhotoRoomGuestViewController.swift
Outdated
Show resolved
Hide resolved
...ayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/EditPhotoRoomGuestViewController.swift
Show resolved
Hide resolved
...Layer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/EditPhotoRoomHostViewController.swift
Show resolved
Hide resolved
- Combine 제거 및 Delegate로 구현 - StickerView에서 불필요하게 Subject 인스턴스를 가지지 않아도 됨
PhotoGether/DomainLayer/PhotoGetherDomain/PhotoGetherDomainInterface/Entity/StickerEntity.swift
Outdated
Show resolved
Hide resolved
0Hooni
left a comment
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.
LGTM 💯
수고 많으셨습니다!
PhotoGether/DomainLayer/PhotoGetherDomain/PhotoGetherDomainInterface/Entity/StickerEntity.swift
Show resolved
Hide resolved
...er/PresentationLayer/EditPhotoRoomFeature/EditPhotoRoomFeature/Source/View/StickerView.swift
Show resolved
Hide resolved
PhotoGether/DomainLayer/PhotoGetherDomain/PhotoGetherDomainInterface/Entity/StickerEntity.swift
Outdated
Show resolved
Hide resolved
youn9k
left a comment
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.
고생하셨습니다! 손이 빠른 구현 고수..
Co-authored-by: Youngkyu Song <ace_lephant@naver.com>
커밋단위로 리뷰하는게 가장 편하십니다.
🤔 배경
owner를 표기하기 위해커스텀 UIImageView가 필요했습니다.EventHub를 거쳐Host,Guest간 통신에 문제가 없었어야 했습니다.📃 작업 내역
StickerView구현:StickerViewUI와tapPublisher를 통한 탭 이벤트 처리 구현StickerView업데이트 최적화:StickerEntity상태 비교를 통해 불필요한 업데이트 방지StickerView의tap시unlock/lock및EventHub반영 처리.StickerEntity배열 확장:owner확인,unlock/lock로직 재사용을 위한 유틸리티 메서드 추가Host/Guest구분 기능 추가: 임시적으로 사용자 역할을 구분합니다.private let owner = "GUEST" + UUID().uuidString.prefix(4)UUID를 이용해 각Guest들의owner를 유니크하게 구분할 수 있습니다.✅ 리뷰 노트
StickerView에서 tap관련 cancellable 관리
// StickerView.swift func tapHandler(_ completion: @escaping (UUID) -> Void) { tapPublisher .sink { [weak self] _ in guard let self else { return } completion(sticker.id) } .store(in: &cancellables) } // EditPhotoRoomViewController.swift private func addNewSticker(to sticker: StickerEntity, isLocal: Bool) { registerSticker(for: sticker) let stickerView = StickerView(sticker: sticker) stickerView.tapHandler { [weak self] stickerID in self?.input.send(.stickerViewDidTap(stickerID)) } canvasScrollView.imageView.addSubview(stickerView) stickerView.update(with: sticker) input.send(.createSticker(sticker)) }가장 큰 이유는
StickerView가 자주 생성되고 삭제된다는 점에 있었습니다.같은 값일 때 불필요한 할당 방지
StickerView또한ViewModel을 두어removeDuplicate()를 통해 관리할 수도 있었지만,이 방식을 택하였습니다.
SitckerView 탭 이벤트 처리 비즈니스 로직 구현
🎨 스크린샷
🚀 테스트 방법