diff --git a/StreetDrop/ShareExtension/View/ReSearchingMusic/ReSearchingMusicForSharingView.swift b/StreetDrop/ShareExtension/View/ReSearchingMusic/ReSearchingMusicForSharingView.swift index 92b4e70..2db63a5 100644 --- a/StreetDrop/ShareExtension/View/ReSearchingMusic/ReSearchingMusicForSharingView.swift +++ b/StreetDrop/ShareExtension/View/ReSearchingMusic/ReSearchingMusicForSharingView.swift @@ -12,11 +12,16 @@ import RxRelay import SnapKit final class ReSearchingMusicForSharingView: UIView { - private let reSearchingEventRelay: PublishRelay = .init() // View -> ViewController + private let reSearchingEventRelay: PublishRelay = .init() var reSearchingEvent: Observable { reSearchingEventRelay.asObservable() } + private let selectedMusicEventRelay: PublishRelay = .init() + var selectedMusicEvent: Observable { + selectedMusicEventRelay.asObservable() + } + // ViewController -> View let settingMusicDataRelay: PublishRelay<[Music]> = .init() private let disposeBag: DisposeBag = .init() @@ -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() { diff --git a/StreetDrop/ShareExtension/View/ShareViewController.swift b/StreetDrop/ShareExtension/View/ShareViewController.swift index dabc922..8bc18a9 100644 --- a/StreetDrop/ShareExtension/View/ShareViewController.swift +++ b/StreetDrop/ShareExtension/View/ShareViewController.swift @@ -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() { diff --git a/StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift b/StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift index 5cf881d..8d69d85 100644 --- a/StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift +++ b/StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift @@ -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 @@ -69,6 +70,7 @@ final class ShareViewModel: NSObject, ShareViewModelType { return } owner.output.showSearchedMusicRelay.accept(firstMusic) + owner.selectedMusic = firstMusic } onFailure: { owner, error in }