Skip to content

Commit

Permalink
#297: Share Extension에서 재검색 화면의 원하는 테이블뷰 셀 클릭 시, 클릭한 셀의 음악 정보 이전 화면의…
Browse files Browse the repository at this point in the history
… 정보로 기입
  • Loading branch information
joseph704 committed Aug 19, 2024
1 parent f3e6367 commit c7f72b0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import RxRelay
import SnapKit

final class ReSearchingMusicForSharingView: UIView {
private let reSearchingEventRelay: PublishRelay<String> = .init()
// View -> ViewController
private let reSearchingEventRelay: PublishRelay<String> = .init()
var reSearchingEvent: Observable<String> {
reSearchingEventRelay.asObservable()
}
private let selectedMusicEventRelay: PublishRelay<Music> = .init()
var selectedMusicEvent: Observable<Music> {
selectedMusicEventRelay.asObservable()
}

// ViewController -> View
let settingMusicDataRelay: PublishRelay<[Music]> = .init()
private let disposeBag: DisposeBag = .init()
Expand Down Expand Up @@ -128,6 +133,10 @@ private extension ReSearchingMusicForSharingView {
.compactMap { [weak self] in self?.searchTextField.text ?? "" }
.bind(to: reSearchingEventRelay)
.disposed(by: disposeBag)

tableView.rx.modelSelected(Music.self)
.bind(to: selectedMusicEventRelay)
.disposed(by: disposeBag)
}

func bindData() {
Expand Down
14 changes: 14 additions & 0 deletions StreetDrop/ShareExtension/View/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ private extension ShareViewController {
}
.disposed(by: disposeBag)

reSearchingMusicForSharingView.selectedMusicEvent
.bind(with: self) { owner, music in
owner.viewModel.selectedMusic = music
owner.albumCoverImageView.kf.setImage(with: URL(string: music.albumImage))
owner.songNameLabel.text = music.songName
owner.artistNameLabel.text = music.artistName
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { [weak self] in
guard let self = self else { return }
containerView.isHidden = false
reSearchingMusicForSharingView.isHidden = true
view.layoutIfNeeded()
})
}
.disposed(by: disposeBag)
}

func bindViewModel() {
Expand Down
2 changes: 2 additions & 0 deletions StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class ShareViewModel: NSObject, ShareViewModelType {
private let searchMusicUsecase: SearchMusicUsecase
private let disposeBag: DisposeBag = .init()
var sharedSongName: String = ""
var selectedMusic: Music?

init(searchMusicUsecase: SearchMusicUsecase = DefaultSearchingMusicUsecase()) {
self.searchMusicUsecase = searchMusicUsecase
Expand Down Expand Up @@ -69,6 +70,7 @@ final class ShareViewModel: NSObject, ShareViewModelType {
return
}
owner.output.showSearchedMusicRelay.accept(firstMusic)
owner.selectedMusic = firstMusic
} onFailure: { owner, error in

}
Expand Down

0 comments on commit c7f72b0

Please sign in to comment.