Skip to content

Commit

Permalink
Merge pull request #522 from wakmusic/521-refactor-search
Browse files Browse the repository at this point in the history
🔀 :: (#521) 서치 퓨처를 ReactorKit으로 리팩합니다.
  • Loading branch information
yongbeomkwak authored May 10, 2024
2 parents 8cd7ea3 + 5d13622 commit f2874a1
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 220 deletions.
5 changes: 0 additions & 5 deletions Projects/App/Sources/Application/AppComponent+Playlist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ import PlayListDomain
import PlayListDomainInterface
import PlaylistFeature
import PlaylistFeatureInterface
import SearchFeature
import StorageFeature

// MARK: 변수명 주의
// AppComponent 내 변수 == Dependency 내 변수 이름 같아야함

public extension AppComponent {
var beforeSearchComponent: BeforeSearchComponent {
BeforeSearchComponent(parent: self)
}

var playlistDetailFactory: any PlaylistDetailFactory {
PlayListDetailComponent(parent: self)
}
Expand Down
21 changes: 21 additions & 0 deletions Projects/App/Sources/Application/AppComponent+Search.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation
import SearchFeature
import SearchFeatureInterface

extension AppComponent {
var searchFactory: any SearchFactory {
SearchComponent(parent: self)
}

var beforeSearchComponent: BeforeSearchComponent {
BeforeSearchComponent(parent: self)
}

var afterSearchComponent: AfterSearchComponent {
AfterSearchComponent(parent: self)
}

var afterSearchContentComponent: AfterSearchContentComponent {
AfterSearchContentComponent(parent: self)
}
}
21 changes: 0 additions & 21 deletions Projects/App/Sources/Application/AppComponent+Songs.swift
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
//
// AppComponent+Search.swift
// WaktaverseMusic
//
// Created by yongbeomkwak on 2023/02/07.
// Copyright © 2023 yongbeomkwak. All rights reserved.
//

import BaseFeature
import HomeFeature
import SearchFeature
import SongsDomain
import SongsDomainInterface

public extension AppComponent {
var searchComponent: SearchComponent {
SearchComponent(parent: self)
}

var afterSearchComponent: AfterSearchComponent {
AfterSearchComponent(parent: self)
}

var afterSearchContentComponent: AfterSearchContentComponent {
AfterSearchContentComponent(parent: self)
}

var homeComponent: HomeComponent {
HomeComponent(parent: self)
}
Expand Down
11 changes: 4 additions & 7 deletions Projects/App/Sources/Application/NeedleGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import PlaylistFeature
import PlaylistFeatureInterface
import RootFeature
import SearchFeature
import SearchFeatureInterface
import SignInFeature
import SignInFeatureInterface
import SongsDomain
Expand Down Expand Up @@ -170,8 +171,8 @@ private class MainTabBarDependencycd05b79389a6a7a6c20fProvider: MainTabBarDepend
var chartComponent: ChartComponent {
return appComponent.chartComponent
}
var searchComponent: SearchComponent {
return appComponent.searchComponent
var searchFactory: any SearchFactory {
return appComponent.searchFactory
}
var artistComponent: ArtistComponent {
return appComponent.artistComponent
Expand Down Expand Up @@ -788,9 +789,6 @@ extension AppComponent: Registration {
public func registerItems() {

localTable["keychain-any Keychain"] = { [unowned self] in self.keychain as Any }
localTable["searchComponent-SearchComponent"] = { [unowned self] in self.searchComponent as Any }
localTable["afterSearchComponent-AfterSearchComponent"] = { [unowned self] in self.afterSearchComponent as Any }
localTable["afterSearchContentComponent-AfterSearchContentComponent"] = { [unowned self] in self.afterSearchContentComponent as Any }
localTable["homeComponent-HomeComponent"] = { [unowned self] in self.homeComponent as Any }
localTable["newSongsComponent-NewSongsComponent"] = { [unowned self] in self.newSongsComponent as Any }
localTable["newSongsContentComponent-NewSongsContentComponent"] = { [unowned self] in self.newSongsContentComponent as Any }
Expand All @@ -815,7 +813,6 @@ extension AppComponent: Registration {
localTable["fetchLikeNumOfSongUseCase-any FetchLikeNumOfSongUseCase"] = { [unowned self] in self.fetchLikeNumOfSongUseCase as Any }
localTable["addLikeSongUseCase-any AddLikeSongUseCase"] = { [unowned self] in self.addLikeSongUseCase as Any }
localTable["cancelLikeSongUseCase-any CancelLikeSongUseCase"] = { [unowned self] in self.cancelLikeSongUseCase as Any }
localTable["beforeSearchComponent-BeforeSearchComponent"] = { [unowned self] in self.beforeSearchComponent as Any }
localTable["playlistDetailFactory-any PlaylistDetailFactory"] = { [unowned self] in self.playlistDetailFactory as Any }
localTable["myPlayListComponent-MyPlayListComponent"] = { [unowned self] in self.myPlayListComponent as Any }
localTable["remotePlayListDataSource-any RemotePlayListDataSource"] = { [unowned self] in self.remotePlayListDataSource as Any }
Expand Down Expand Up @@ -931,7 +928,7 @@ extension MainTabBarComponent: Registration {
keyPathToName[\MainTabBarDependency.fetchNoticeUseCase] = "fetchNoticeUseCase-any FetchNoticeUseCase"
keyPathToName[\MainTabBarDependency.homeComponent] = "homeComponent-HomeComponent"
keyPathToName[\MainTabBarDependency.chartComponent] = "chartComponent-ChartComponent"
keyPathToName[\MainTabBarDependency.searchComponent] = "searchComponent-SearchComponent"
keyPathToName[\MainTabBarDependency.searchFactory] = "searchFactory-any SearchFactory"
keyPathToName[\MainTabBarDependency.artistComponent] = "artistComponent-ArtistComponent"
keyPathToName[\MainTabBarDependency.storageComponent] = "storageComponent-StorageComponent"
keyPathToName[\MainTabBarDependency.myInfoComponent] = "myInfoComponent-MyInfoComponent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ open class BaseStoryboardReactorViewController<R: Reactor>: UIViewController, St
ViewControllerFromStoryBoard {
public var disposeBag = DisposeBag()

// @available(*, unavailable)
// public required init?(coder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }

override open func viewDidLoad() {
super.viewDidLoad()
configureUI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import MyInfoFeature
import NeedleFoundation
import NoticeDomainInterface
import SearchFeature
import SearchFeatureInterface
import StorageFeature

public protocol MainTabBarDependency: Dependency {
var fetchNoticeUseCase: any FetchNoticeUseCase { get }
var homeComponent: HomeComponent { get }
var chartComponent: ChartComponent { get }
var searchComponent: SearchComponent { get }
var searchFactory: any SearchFactory { get }
var artistComponent: ArtistComponent { get }
var storageComponent: StorageComponent { get }
var myInfoComponent: MyInfoComponent { get }
Expand All @@ -30,7 +31,7 @@ public final class MainTabBarComponent: Component<MainTabBarDependency> {
),
homeComponent: self.dependency.homeComponent,
chartComponent: self.dependency.chartComponent,
searchComponent: self.dependency.searchComponent,
searchFactory: self.dependency.searchFactory,
artistComponent: self.dependency.artistComponent,
storageCompoent: self.dependency.storageComponent,
myInfoComponent: self.dependency.myInfoComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import NoticeDomainInterface
import RxCocoa
import RxSwift
import SearchFeature
import SearchFeatureInterface
import SnapKit
import StorageFeature
import UIKit
Expand All @@ -20,7 +21,7 @@ public final class MainTabBarViewController: BaseViewController, ViewControllerF
return [
homeComponent.makeView().wrapNavigationController,
chartComponent.makeView().wrapNavigationController,
searchComponent.makeView().wrapNavigationController,
searchFactory.makeView().wrapNavigationController,
artistComponent.makeView().wrapNavigationController,
storageComponent.makeView().wrapNavigationController,
myInfoComponent.makeView().wrapNavigationController
Expand All @@ -34,7 +35,7 @@ public final class MainTabBarViewController: BaseViewController, ViewControllerF

private var homeComponent: HomeComponent!
private var chartComponent: ChartComponent!
private var searchComponent: SearchComponent!
private var searchFactory: SearchFactory!
private var artistComponent: ArtistComponent!
private var storageComponent: StorageComponent!
private var myInfoComponent: MyInfoComponent!
Expand Down Expand Up @@ -62,7 +63,7 @@ public final class MainTabBarViewController: BaseViewController, ViewControllerF
viewModel: MainTabBarViewModel,
homeComponent: HomeComponent,
chartComponent: ChartComponent,
searchComponent: SearchComponent,
searchFactory: SearchFactory,
artistComponent: ArtistComponent,
storageCompoent: StorageComponent,
myInfoComponent: MyInfoComponent,
Expand All @@ -74,7 +75,7 @@ public final class MainTabBarViewController: BaseViewController, ViewControllerF
viewController.viewModel = viewModel
viewController.homeComponent = homeComponent
viewController.chartComponent = chartComponent
viewController.searchComponent = searchComponent
viewController.searchFactory = searchFactory
viewController.artistComponent = artistComponent
viewController.storageComponent = storageCompoent
viewController.myInfoComponent = myInfoComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ internal class PlayListDetailViewController: BaseStoryboardReactorViewController
override public func bindState(reactor: PlaylistDetailReactor) {
super.bindState(reactor: reactor)

let currentState = reactor.state.share(replay: 4)
let sharedState = reactor.state.share(replay: 4)

currentState.map(\.dataSource)
sharedState.map(\.dataSource)
.withUnretained(self)
.do(onNext: { owner, model in

Expand All @@ -158,15 +158,15 @@ internal class PlayListDetailViewController: BaseStoryboardReactorViewController
.bind(to: tableView.rx.items(dataSource: createDatasources()))
.disposed(by: disposeBag)

currentState.map(\.header)
sharedState.map(\.header)
.withUnretained(self)
.do(onNext: { owner, model in

let imageHeight: CGFloat = (140.0 * APP_WIDTH()) / 375.0
let newFrame: CGRect = CGRect(x: 0, y: 0, width: APP_WIDTH(), height: imageHeight + 20)
owner.tableView.tableHeaderView?.frame = newFrame
})
.bind(onNext: { owner, model in
.bind { owner, model in

guard let type = owner.reactor?.type else { return }

Expand All @@ -182,13 +182,12 @@ internal class PlayListDetailViewController: BaseStoryboardReactorViewController
owner.playListCountLabel.text = model.songCount
owner.playListNameLabel.text = model.title
owner.editPlayListNameButton.setImage(DesignSystemAsset.Storage.storageEdit.image, for: .normal)

})
}
.disposed(by: disposeBag)

currentState.map(\.selectedItemCount)
sharedState.map(\.selectedItemCount)
.withUnretained(self)
.bind(onNext: { owner, count in
.bind { owner, count in
guard let type = owner.reactor?.type else {
return
}
Expand All @@ -210,13 +209,12 @@ internal class PlayListDetailViewController: BaseStoryboardReactorViewController
owner.songCartView?.delegate = owner
}
}

})
}
.disposed(by: disposeBag)

currentState.map(\.isEditing)
sharedState.map(\.isEditing)
.withUnretained(self)
.bind(onNext: { owner, flag in
.bind { owner, flag in
owner.navigationController?.interactivePopGestureRecognizer?.delegate = flag ? owner : nil
owner.moreButton.isHidden = flag
owner.editPlayListNameButton.isHidden = !flag
Expand All @@ -225,8 +223,7 @@ internal class PlayListDetailViewController: BaseStoryboardReactorViewController

owner.tableView.isEditing = flag
owner.tableView.reloadData()

})
}
.disposed(by: disposeBag)
}

Expand Down
6 changes: 6 additions & 0 deletions Projects/Features/SearchFeature/Interface/SearchFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import BaseFeatureInterface
import UIKit

public protocol SearchFactory {
func makeView() -> UIViewController
}
4 changes: 4 additions & 0 deletions Projects/Features/SearchFeature/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import ProjectDescriptionHelpers
let project = Project.module(
name: ModulePaths.Feature.SearchFeature.rawValue,
targets: [
.interface(module: .feature(.SearchFeature), dependencies: [
.feature(target: .BaseFeature, type: .interface)
]),
.implements(
module: .feature(.SearchFeature),
product: .staticFramework,
spec: .init(
resources: ["Resources/**"],
dependencies: [
.feature(target: .PlayerFeature),
.feature(target: .SearchFeature, type: .interface),
.feature(target: .PlaylistFeature, type: .interface),
.domain(target: .SongsDomain, type: .interface),
]
Expand Down
Loading

0 comments on commit f2874a1

Please sign in to comment.