Filter module interface adjustment

dev
wenlei 11 months ago
parent ad0e7b17c7
commit 483c8d36c2

@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
3C955224FAC6473657A027C3 /* Pods_IndieMusicTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42CE866330C1741ADEC950B2 /* Pods_IndieMusicTests.framework */; };
49330FC1492387B5155757F6 /* Pods_IndieMusic_IndieMusicUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA03C869C12FEE5FB3D835C2 /* Pods_IndieMusic_IndieMusicUITests.framework */; };
77165D742B464493002AE0A5 /* BarButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77165D732B464493002AE0A5 /* BarButtonItem.swift */; };
7743999E2AFA18C3006F8EEA /* PlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7743999D2AFA18C3006F8EEA /* PlayerViewController.swift */; };
774399A02AFA1968006F8EEA /* PlayerTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7743999F2AFA1968006F8EEA /* PlayerTabBar.swift */; };
774399A62AFE036A006F8EEA /* PlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 774399A52AFE036A006F8EEA /* PlayerView.swift */; };
@ -162,6 +163,7 @@
3BA421D41748C113CCE36A32 /* Pods_IndieMusic.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_IndieMusic.framework; sourceTree = BUILT_PRODUCTS_DIR; };
42CE866330C1741ADEC950B2 /* Pods_IndieMusicTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_IndieMusicTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
69F724137B8F9C1F7E51080D /* Pods-IndieMusicTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-IndieMusicTests.release.xcconfig"; path = "Target Support Files/Pods-IndieMusicTests/Pods-IndieMusicTests.release.xcconfig"; sourceTree = "<group>"; };
77165D732B464493002AE0A5 /* BarButtonItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarButtonItem.swift; sourceTree = "<group>"; };
7743999D2AFA18C3006F8EEA /* PlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerViewController.swift; sourceTree = "<group>"; };
7743999F2AFA1968006F8EEA /* PlayerTabBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerTabBar.swift; sourceTree = "<group>"; };
774399A52AFE036A006F8EEA /* PlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerView.swift; sourceTree = "<group>"; };
@ -443,6 +445,7 @@
778B8ABA2AF8ED280034AFD4 /* TabViewController.swift */,
778B8AB42AF8ED280034AFD4 /* View.swift */,
778B8AB72AF8ED280034AFD4 /* ViewController.swift */,
77165D732B464493002AE0A5 /* BarButtonItem.swift */,
778B8AB52AF8ED280034AFD4 /* ViewModel.swift */,
778B8AB22AF8ED270034AFD4 /* WebViewController.swift */,
774399A72AFE28BA006F8EEA /* BlurEffectView.swift */,
@ -1047,6 +1050,7 @@
778B8A6E2AF8ECD30034AFD4 /* RestApi.swift in Sources */,
778B8ABC2AF8ED280034AFD4 /* PresentationController.swift in Sources */,
77FA0B3E2B0C573600404C5E /* Filter.swift in Sources */,
77165D742B464493002AE0A5 /* BarButtonItem.swift in Sources */,
7751D3662B42BE7F00F1F2BD /* FeedbackViewController.swift in Sources */,
774A18142B07329600F56DF1 /* MultiUserAvatarView.swift in Sources */,
778B8AAA2AF8ED0E0034AFD4 /* AVPlayer.swift in Sources */,

@ -17,7 +17,7 @@ final class Application: NSObject {
let navigator: Navigator
let authManager: AuthManager
let launchADManager: LaunchADManager
private override init() {
authManager = AuthManager.shared

@ -22,7 +22,9 @@ class Navigator {
case tabs(viewModel: HomeTabBarViewModel)
case search(viewModel: HomeTabBarViewModel)
case journalDetail(viewModel: JournalDetailViewModel)
case filter(viewModel: FilterViewModel)
case test
case safari(URL)
case safariController(URL)
case webController(URL)
@ -59,7 +61,13 @@ class Navigator {
case .search(let viewModel): return SearchViewController(viewModel: viewModel, navigator: self)
case .journalDetail(viewModel: let viewModel):
return JournalDetailController.init(viewModel: viewModel, navigator: self)
case .filter(viewModel: let viewModel):
return FilterViewController.init(viewModel: viewModel, navigator: self)
case .test:
let test = UIViewController.init()
test.view.backgroundColor = .red
return test
case .safari(let url):
UIApplication.shared.open(url, options: [:], completionHandler: nil)
@ -111,27 +119,31 @@ class Navigator {
}
if let nav = sender as? UINavigationController {
// push root controller on navigation stack
nav.pushViewController(target, animated: false)
return
}
switch transition {
case .navigationPresent(let type):
case .navigationPush:
if let nav = sender.navigationController {
// push controller to navigation stack
nav.pushViewController(target, animated: true)
}
case .navigationPresent(let type):
// present modally with custom animation
DispatchQueue.main.async {
let nav = NavigationController(rootViewController: target)
nav.modalPresentationStyle = .custom
if let target = target as? any UIViewControllerTransitioningDelegate {
nav.transitioningDelegate = target
}
nav.setNavigationBarHidden(true, animated: true)
sender.present(nav, animated: true, completion: nil)
}
case .modal:
// present modally
DispatchQueue.main.async {
let nav = NavigationController(rootViewController: target)
nav.setNavigationBarHidden(true, animated: true)
sender.present(nav, animated: true, completion: nil)
}
case .detail:

@ -0,0 +1,12 @@
//
// BarButtonItem.swift
// IndieMusic
//
// Created by WenLei on 2024/1/4.
//
import UIKit
class BarButtonItem: UIBarButtonItem {
}

@ -8,17 +8,13 @@
import UIKit
enum PresentationViewType {
case datePicker
case share
case tips(Bool)
case evaluation
case member
case sheetNav
case filter
}
class PresentationController: UIPresentationController {
var viewType: PresentationViewType = .datePicker
var viewType: PresentationViewType = .tips(false)
private var calculatedFrameOfPresentedViewInContainerView = CGRect.zero
private var shouldSetFrameWhenAccessingPresentedView = false
@ -58,26 +54,11 @@ class CardPresentationController: PresentationController {
guard let containerView = containerView else { return .zero }
switch viewType {
case .datePicker:
case .filter:
return containerView.bounds
.inset(by: UIEdgeInsets(top: containerView.bounds.height - 425, left: 0, bottom: 0, right: 0))
case .share:
return containerView.bounds
.inset(by: UIEdgeInsets(top: containerView.bounds.height - 130, left: 0, bottom: 0, right: 0))
.inset(by: UIEdgeInsets(top: containerView.bounds.height - 474 - BaseDimensions.bottomHeight, left: 0, bottom: 0, right: 0))
case .tips:
return containerView.bounds
case .evaluation:
// return containerView.bounds
return containerView.bounds
.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0))
case .member:
return containerView.bounds
case .sheetNav:
return containerView.bounds
.inset(by: UIEdgeInsets(top: BaseDimensions.topHeight, left: 0, bottom: 0, right: 0))
}
}
@ -104,18 +85,11 @@ class CardPresentationController: PresentationController {
if let coordinator = presentingViewController.transitionCoordinator {
switch viewType {
case .datePicker:
case .filter:
coordinator.animate(alongsideTransition: { [weak self] _ in
self?.containerView?.backgroundColor = UIColor.black.withAlphaComponent(0.8)
}, completion: nil)
case .share:
coordinator.animate(alongsideTransition: { [weak self] _ in
self?.containerView?.backgroundColor = UIColor.black.withAlphaComponent(0.8)
}, completion: nil)
let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(dismiss))
self.containerView?.addGestureRecognizer(tapGes)
case .tips(let isTapDismiss):
coordinator.animate(alongsideTransition: { [weak self] _ in
@ -125,28 +99,6 @@ class CardPresentationController: PresentationController {
let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(dismiss))
self.containerView?.addGestureRecognizer(tapGes)
}
case .member:
presentedView?.layer.cornerRadius = 0
coordinator.animate(alongsideTransition: { [weak self] _ in
}, completion: nil)
case .evaluation:
coordinator.animate(alongsideTransition: { [weak self] _ in
self?.containerView?.backgroundColor = UIColor.black.withAlphaComponent(0.8)
}, completion: nil)
// let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(dismiss))
// self.containerView?.addGestureRecognizer(tapGes)
case .sheetNav:
coordinator.animate(alongsideTransition: { [weak self] _ in
self?.containerView?.backgroundColor = UIColor.black.withAlphaComponent(0.8)
}, completion: nil)
}
}
}

@ -8,12 +8,14 @@
import UIKit
import RxSwift
import RxCocoa
import DZNEmptyDataSet
import SVProgressHUD
class ViewController: UIViewController, Navigatable {
var viewModel: ViewModel?
var navigator: Navigator!
init(viewModel: ViewModel?, navigator: Navigator) {
self.viewModel = viewModel
self.navigator = navigator
@ -23,13 +25,10 @@ class ViewController: UIViewController, Navigatable {
required init?(coder aDecoder: NSCoder) {
super.init(nibName: nil, bundle: nil)
}
// let isLoading = BehaviorRelay(value: false)
// let error = PublishSubject<ApiError>()
let isLoading = BehaviorRelay(value: false)
let error = PublishSubject<ApiError>()
var automaticallyAdjustsLeftBarButtonItem = true
var canOpenFlex = true
@ -41,31 +40,40 @@ class ViewController: UIViewController, Navigatable {
let spaceBarButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
lazy var backBarButton: UIBarButtonItem = {
let button = UIButton.init()
button.imageEdgeInsets = UIEdgeInsets.init(top: 0, left: -10, bottom: 0, right: 0)
button.setTitleColor(UIColor(red: 0.25, green: 0.25, blue: 0.25, alpha: 1.00), for: .normal)
button.setImage(UIImage(named:"nav_back_btn"), for: .normal)
button.addTarget(self, action: #selector(backAction), for: .touchUpInside)
let leftBarBtn = UIBarButtonItem(customView: button)
return leftBarBtn
}()
let emptyDataSetButtonTap = PublishSubject<Void>()
var emptyDataSetTitle = ""
var emptyDataSetDescription = ""
var emptyDataSetImage = UIImage.init(named: "")
var emptyDataSetImageTintColor = BehaviorRelay<UIColor?>(value: nil)
let languageChanged = BehaviorRelay<Void>(value: ())
let orientationEvent = PublishSubject<Void>()
let motionShakeEvent = PublishSubject<Void>()
lazy var backBarButton: BarButtonItem = {
let view = BarButtonItem()
view.title = ""
return view
}()
lazy var closeBarButton: BarButtonItem = {
let view = BarButtonItem(image: UIImage.init(named: ""),
style: .plain,
target: self,
action: nil)
return view
}()
lazy var contentView: View = {
let view = View()
// view.hero.id = "CententView"
self.view.addSubview(view)
view.snp.makeConstraints { (make) in
make.edges.equalTo(self.view)
make.edges.equalTo(self.view.safeAreaLayoutGuide)
}
return view
}()
override public func viewDidLoad() {
super.viewDidLoad()
@ -74,9 +82,18 @@ class ViewController: UIViewController, Navigatable {
makeUI()
bindViewModel()
// Observe device orientation change
closeBarButton.rx.tap.asObservable().subscribe(onNext: { [weak self] () in
self?.navigator.dismiss(sender: self)
}).disposed(by: rx.disposeBag)
NotificationCenter.default
.rx.notification(UIDevice.orientationDidChangeNotification).mapToVoid()
.bind(to: orientationEvent).disposed(by: rx.disposeBag)
orientationEvent.subscribe { [weak self] (event) in
self?.orientationChanged()
}.disposed(by: rx.disposeBag)
// Observe application did become active notification
NotificationCenter.default
.rx.notification(UIApplication.didBecomeActiveNotification)
.subscribe { [weak self] (event) in
@ -86,7 +103,7 @@ class ViewController: UIViewController, Navigatable {
NotificationCenter.default
.rx.notification(UIAccessibility.reduceMotionStatusDidChangeNotification)
.subscribe(onNext: { (event) in
// logDebug("Motion Status changed")
logDebug("Motion Status changed")
}).disposed(by: rx.disposeBag)
@ -94,63 +111,91 @@ class ViewController: UIViewController, Navigatable {
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if automaticallyAdjustsLeftBarButtonItem {
adjustLeftBarButtonItem()
}
updateUI()
}
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
updateUI()
logResourcesCount()
}
deinit {
logDebug("\(type(of: self)): Deinited")
logResourcesCount()
}
override public func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
logDebug("\(type(of: self)): Received Memory Warning")
}
func makeUI() {
//
// let spacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil,
// action: nil)
// spacer.width = -10
// self.navigationItem.leftBarButtonItems = [spacer, backBarButton]
view.backgroundColor = .white
// navigationItem.leftBarButtonItem = backBarButton
navigationItem.backBarButtonItem = backBarButton
updateUI()
}
func bindViewModel() {
// viewModel?.loading.asObservable().bind(to: isLoading).disposed(by: rx.disposeBag)
viewModel?.parsedError.asObservable().bind(to: error).disposed(by: rx.disposeBag)
languageChanged.subscribe(onNext: { [weak self] () in
self?.emptyDataSetTitle = ""
}).disposed(by: rx.disposeBag)
isLoading.subscribe(onNext: { isLoading in
// UIApplication.shared.isNetworkActivityIndicatorVisible = isLoading
}).disposed(by: rx.disposeBag)
}
func updateUI() {
}
func startAnimating() {
SVProgressHUD.show()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
func stopAnimating() {
SVProgressHUD.dismiss()
}
override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
if motion == .motionShake {
motionShakeEvent.onNext(())
}
}
func orientationChanged() {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.updateUI()
}
}
func didBecomeActive() {
self.updateUI()
}
// MARK: Adjusting Navigation Item
func adjustLeftBarButtonItem() {
if self.navigationController?.viewControllers.count ?? 0 > 1 { // Pushed
self.navigationItem.leftBarButtonItem = nil
} else if self.presentingViewController != nil { // presented
self.navigationItem.leftBarButtonItem = closeBarButton
}
}
@objc func closeAction(sender: AnyObject) {
self.dismiss(animated: true, completion: nil)
}
@objc func backAction() {
self.navigationController?.popViewController(animated: true)
}
}
extension ViewController {
@ -167,14 +212,47 @@ extension ViewController {
return view
}
}
extension Reactive where Base: ViewController {
extension ViewController: DZNEmptyDataSetSource {
/// Bindable sink for `backgroundColor` property
var emptyDataSetImageTintColorBinder: Binder<UIColor?> {
return Binder(self.base) { view, attr in
// view.emptyDataSetImageTintColor.accept(attr)
}
func title(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
return NSAttributedString(string: emptyDataSetTitle)
}
func description(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
return NSAttributedString(string: emptyDataSetDescription)
}
func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage! {
return emptyDataSetImage
}
func imageTintColor(forEmptyDataSet scrollView: UIScrollView!) -> UIColor! {
return emptyDataSetImageTintColor.value
}
func backgroundColor(forEmptyDataSet scrollView: UIScrollView!) -> UIColor! {
return .clear
}
func verticalOffset(forEmptyDataSet scrollView: UIScrollView!) -> CGFloat {
return -60
}
}
extension ViewController: DZNEmptyDataSetDelegate {
func emptyDataSetShouldDisplay(_ scrollView: UIScrollView!) -> Bool {
return !isLoading.value
}
func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView!) -> Bool {
return true
}
func emptyDataSet(_ scrollView: UIScrollView!, didTap button: UIButton!) {
emptyDataSetButtonTap.onNext(())
}
}

@ -10,7 +10,7 @@ import RxSwift
import RxCocoa
import SnapKit
import SwiftDate
import SVProgressHUD
//import Bugly

@ -9,11 +9,14 @@ import Foundation
import RxDataSources
struct Filter: Codable {
let title: String
var isSelected: Bool
}
struct FilterSection {
var header: String
var items: [Filter]
}
@ -26,3 +29,17 @@ extension FilterSection: SectionModelType {
self.items = items
}
}
struct SectionType<T> {
var header: String
var items: [T]
}
extension SectionType: SectionModelType {
typealias Item = T
init(original: SectionType, items: [T]) {
self = original
self.items = items
}
}

@ -11,12 +11,31 @@ class FilterViewCell: UICollectionViewCell {
var titleLabel: UILabel = {
let titleLabel = UILabel.init()
titleLabel.font = UIFont.systemFont(ofSize: 12)
titleLabel.backgroundColor = .red
titleLabel.text = "rtest"
titleLabel.textColor = .secondaryText()
// titleLabel.backgroundColor = .red
titleLabel.textAlignment = .center
return titleLabel
}()
override var isSelected: Bool {
didSet {
}
}
var filter: Filter? {
didSet {
guard let filter = filter else { return }
contentView.layer.borderColor = filter.isSelected ? UIColor.black.cgColor : UIColor.clear.cgColor
contentView.layer.borderWidth = filter.isSelected ? 1 : 0
print("选择 \(titleLabel.text) \(isSelected)")
}
}
override init(frame: CGRect) {
super.init(frame: frame)
@ -30,17 +49,109 @@ class FilterViewCell: UICollectionViewCell {
func makeUI() {
addSubview(titleLabel)
// layer.cornerRadius = 14
// layer.borderColor = UIColor.yellow.cgColor
// layer.masksToBounds = true
// layer.borderWidth = 1
contentView.layer.cornerRadius = 14
contentView.layer.masksToBounds = true
contentView.addSubview(titleLabel)
contentView.backgroundColor = .white
titleLabel.snp.makeConstraints { make in
make.left.equalTo(contentView).offset(14)
make.right.equalTo(contentView).offset(-14)
make.top.equalTo(contentView).offset(8)
make.bottom.equalTo(contentView).offset(-8)
make.edges.equalTo(contentView)
}
}
}
class FilterHeaderView: UICollectionReusableView {
let titleLabel: UILabel = {
let titleLabel = UILabel.init()
titleLabel.font = UIFont.systemFont(ofSize: 17, weight: .medium)
titleLabel.text = "test"
return titleLabel
}()
override init(frame: CGRect) {
super.init(frame: frame)
makeUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func makeUI() {
addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalTo(self)
make.right.equalTo(self)
make.top.equalTo(self).offset(24)
make.bottom.equalTo(self).offset(-15)
}
}
}
class FilterBottomView: UIView {
let lineView: UIView = {
let lineView = UIView.init()
lineView.backgroundColor = .separator()
return lineView
}()
let titleLabel: UILabel = {
let titleLabel = UILabel.init()
titleLabel.font = UIFont.systemFont(ofSize: 15)
titleLabel.text = "恢复默认"
return titleLabel
}()
override init(frame: CGRect) {
super.init(frame: frame)
makeUI()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func makeUI() {
backgroundColor = .init(hex: 0xf3f3f4)
addSubview(lineView)
addSubview(titleLabel)
}
override func layoutSubviews() {
super.layoutSubviews()
lineView.snp.makeConstraints { make in
make.left.equalTo(self)
make.right.equalTo(self)
make.top.equalTo(self)
make.height.equalTo(1)
}
titleLabel.snp.makeConstraints { make in
make.centerX.equalTo(self)
make.top.equalTo(self).offset(19)
}
}
}

@ -11,18 +11,52 @@ import RxDataSources
class FilterViewController: ViewController {
var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 76, height: 28)
// layout.headerReferenceSize = CGSize(width: collectionView.frame.size.width, height: 50)
let layout = UICollectionViewCompositionalLayout { (sectionIndex, environment) -> NSCollectionLayoutSection? in
// Item
let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(76), heightDimension: .absolute(28))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
item.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 4.5, bottom: 0, trailing: 4.5)
//
let horizontalGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(0.5))
let horizontalGroup = NSCollectionLayoutGroup.horizontal(layoutSize: horizontalGroupSize, subitem: item, count: Int(BaseDimensions.screenWidth / 76))
//
let verticalGroupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .absolute(68))
let verticalGroup = NSCollectionLayoutGroup.vertical(layoutSize: verticalGroupSize, subitems: [horizontalGroup, horizontalGroup])
// Header
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(63))
let header = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: UICollectionView.elementKindSectionHeader, alignment: .top)
//
let section = NSCollectionLayoutSection(group: verticalGroup)
section.orthogonalScrollingBehavior = .paging
section.boundarySupplementaryItems = [header]
//
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15)
return section
}
let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: layout)
collectionView.register(FilterViewCell.self, forCellWithReuseIdentifier: "FilterViewCell")
collectionView.register(FilterHeaderView.self, forSupplementaryViewOfKind: "UICollectionElementKindSectionHeader", withReuseIdentifier: "FilterHeaderView")
collectionView.backgroundColor = .init(hex: 0xf3f3f4)
return collectionView
}()
let filterBottomView: FilterBottomView = {
let filterBottomView = FilterBottomView.init()
return filterBottomView
}()
override func viewDidLoad() {
super.viewDidLoad()
@ -33,7 +67,10 @@ class FilterViewController: ViewController {
override func makeUI() {
super.makeUI()
view.addSubview(collectionView)
view.addSubview(filterBottomView)
}
override func bindViewModel() {
@ -52,35 +89,70 @@ class FilterViewController: ViewController {
output.itemSelected.subscribe { sectionItem in
self.navigator.dismiss(sender: self)
}.disposed(by: rx.disposeBag)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
filterBottomView.snp.makeConstraints { make in
make.bottom.equalTo(view)
make.left.equalTo(view)
make.right.equalTo(view)
make.height.equalTo(BaseDimensions.bottomHeight + 49)
}
collectionView.snp.makeConstraints { make in
make.left.equalTo(view)
make.right.equalTo(view)
make.top.equalTo(view)
make.bottom.equalTo(view).offset(-BaseDimensions.bottomHeight)
make.bottom.equalTo(filterBottomView.snp.top)
}
}
}
extension FilterViewController {
static func dataSource() -> RxCollectionViewSectionedReloadDataSource<FilterSection> {
return RxCollectionViewSectionedReloadDataSource<FilterSection>(
static func dataSource() -> RxCollectionViewSectionedReloadDataSource<SectionType<Filter>> {
return RxCollectionViewSectionedReloadDataSource<SectionType<Filter>>(
configureCell: { dataSource, collectionView, indexPath, item in
// cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FilterViewCell", for: indexPath)
// cell
return cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "FilterViewCell", for: indexPath) as? FilterViewCell
cell?.titleLabel.text = item.title
cell?.isSelected = true
cell?.filter = item
return cell!
},
configureSupplementaryView: { dataSource, collectionView, kind, indexPath in
guard kind == UICollectionView.elementKindSectionHeader else {
return UICollectionReusableView()
}
let section = dataSource[indexPath.section]
let resuableView = collectionView.dequeueReusableSupplementaryView(ofKind: "UICollectionElementKindSectionHeader", withReuseIdentifier: "FilterHeaderView", for: indexPath) as! FilterHeaderView
resuableView.titleLabel.text = section.header
return resuableView
}
)
}
}
extension FilterViewController: UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
let carePresentationVC = CardPresentationController.init(presentedViewController: presented, presenting: presenting)
carePresentationVC.viewType = .filter
return carePresentationVC
}
}

@ -18,14 +18,14 @@ class FilterViewModel: ViewModel, ViewModelType {
}
struct Output {
let items: BehaviorRelay<[FilterSection]>
let items: BehaviorRelay<[SectionType<Filter>]>
let selection: Driver<IndexPath>
let itemSelected: PublishSubject<Filter>
}
let itemSelected = PublishSubject<Filter>()
let items = BehaviorRelay<[FilterSection]>.init(value: [])
let items = BehaviorRelay<[SectionType<Filter>]>.init(value: [])
func transform(input: Input) -> Output {
@ -33,14 +33,38 @@ class FilterViewModel: ViewModel, ViewModelType {
}.disposed(by: rx.disposeBag)
let share = Filter.init()
let filter0 = Filter.init(title: "test", isSelected: false)
let filter1 = Filter.init(title: "test123", isSelected: true)
let filter2 = Filter.init(title: "test", isSelected: false)
let filter3 = Filter.init(title: "test123", isSelected: true)
let filter4 = Filter.init(title: "test", isSelected: false)
let filter5 = Filter.init(title: "test123", isSelected: true)
let selection0 = SectionType<Filter>.init(header: "风格", items: [filter0, filter1])
let selection1 = SectionType<Filter>.init(header: "语言", items: [filter2, filter3])
let selection2 = SectionType<Filter>.init(header: "期刊", items: [filter4, filter5])
let selection = FilterSection.init(items: [share])
items.accept([selection])
items.accept([selection0, selection1, selection2])
input.selection.drive { indexPath in
guard let sectionItem = self.items.value.first?.items[indexPath.row] else { return }
self.itemSelected.onNext(sectionItem)
// guard var sectionItem = self.items.value.first?.items[indexPath.row] else { return }
var currentSections = self.items.value
if let section = currentSections.first, indexPath.row < section.items.count {
for i in 0..<section.items.count {
currentSections[0].items[i].isSelected = (i == indexPath.row)
}
self.items.accept(currentSections)
let selectedSectionItem = currentSections[0].items[indexPath.row]
self.itemSelected.onNext(selectedSectionItem)
}
}.disposed(by: rx.disposeBag)

@ -93,8 +93,15 @@ class HomeViewController: TableViewController {
default:
let journalDetailViewModel = JournalDetailViewModel.init(provider: viewModel.provider)
self.navigator.show(segue: .journalDetail(viewModel: journalDetailViewModel), sender: self)
let filterViewModel = FilterViewModel.init(provider: viewModel.provider)
let filter = FilterViewController.init(viewModel: filterViewModel, navigator: self.navigator)
// self.present(filter, animated: true)
self.navigator.show(segue: .filter(viewModel: filterViewModel), sender: self, transition: .navigationPresent(type: .filter))
// self.navigator.show(segue: .test, sender: self, transition: .modal)
// let journalDetailViewModel = JournalDetailViewModel.init(provider: viewModel.provider)
// self.navigator.show(segue: .journalDetail(viewModel: journalDetailViewModel), sender: self)
}

@ -19,6 +19,8 @@ target 'IndieMusic' do
pod 'WechatOpenSDK-XCFramework'
pod 'SwiftDate'
pod 'XHLaunchAd'
pod 'DZNEmptyDataSet'
pod 'SVProgressHUD', :git => 'https://github.com/SVProgressHUD/SVProgressHUD.git'
pod 'NSObject+Rx'

Loading…
Cancel
Save