From af370934cad75d63d20e44b3029fe6200456b044 Mon Sep 17 00:00:00 2001 From: wenlei Date: Thu, 25 Jan 2024 16:03:12 +0800 Subject: [PATCH] add popoverMenu --- .../IndieMusic.xcodeproj/project.pbxproj | 4 + .../IndieMusic/Managers/LibsManager.swift | 2 +- IndieMusic/IndieMusic/Models/Message.swift | 39 ++++++-- .../IndieMusic/Models/PopoverMenu.swift | 26 +++++ .../JournalDetail/JournalDetailView.swift | 1 + .../Message/MessageViewController.swift | 94 +++++++++++++++---- .../Modules/Message/MessageViewModel.swift | 16 ++-- 7 files changed, 151 insertions(+), 31 deletions(-) create mode 100644 IndieMusic/IndieMusic/Models/PopoverMenu.swift diff --git a/IndieMusic/IndieMusic.xcodeproj/project.pbxproj b/IndieMusic/IndieMusic.xcodeproj/project.pbxproj index 91a4dbb..ced9af9 100644 --- a/IndieMusic/IndieMusic.xcodeproj/project.pbxproj +++ b/IndieMusic/IndieMusic.xcodeproj/project.pbxproj @@ -39,6 +39,7 @@ 774A18142B07329600F56DF1 /* MultiUserAvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 774A18132B07329600F56DF1 /* MultiUserAvatarView.swift */; }; 7751009A2B62050C00F46109 /* UIImageView+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 775100992B62050C00F46109 /* UIImageView+Rx.swift */; }; 7751009C2B62065800F46109 /* Date+IndieMusic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7751009B2B62065800F46109 /* Date+IndieMusic.swift */; }; + 7751009E2B62330900F46109 /* PopoverMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7751009D2B62330900F46109 /* PopoverMenu.swift */; }; 7751D3502B42ABBF00F1F2BD /* SettingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7751D34F2B42ABBF00F1F2BD /* SettingViewController.swift */; }; 7751D3522B42AC2B00F1F2BD /* SettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7751D3512B42AC2B00F1F2BD /* SettingView.swift */; }; 7751D3542B42AE0E00F1F2BD /* SettingViewMdel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7751D3532B42AE0E00F1F2BD /* SettingViewMdel.swift */; }; @@ -256,6 +257,7 @@ 774A18132B07329600F56DF1 /* MultiUserAvatarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiUserAvatarView.swift; sourceTree = ""; }; 775100992B62050C00F46109 /* UIImageView+Rx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Rx.swift"; sourceTree = ""; }; 7751009B2B62065800F46109 /* Date+IndieMusic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+IndieMusic.swift"; sourceTree = ""; }; + 7751009D2B62330900F46109 /* PopoverMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopoverMenu.swift; sourceTree = ""; }; 7751D34F2B42ABBF00F1F2BD /* SettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewController.swift; sourceTree = ""; }; 7751D3512B42AC2B00F1F2BD /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = ""; }; 7751D3532B42AE0E00F1F2BD /* SettingViewMdel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewMdel.swift; sourceTree = ""; }; @@ -698,6 +700,7 @@ 77C9B9EA2B4BE7E50006C83F /* Comment.swift */, 770228E82B55169C00E07F7A /* InternationalNumber.swift */, 770228EC2B55284F00E07F7A /* Login.swift */, + 7751009D2B62330900F46109 /* PopoverMenu.swift */, ); path = Models; sourceTree = ""; @@ -1229,6 +1232,7 @@ 770228F72B5A224500E07F7A /* SliderControlValuePublisher.swift in Sources */, 774399A82AFE28BA006F8EEA /* BlurEffectView.swift in Sources */, 778B8A852AF8ECE50034AFD4 /* SearchViewController.swift in Sources */, + 7751009E2B62330900F46109 /* PopoverMenu.swift in Sources */, 770228E92B55169C00E07F7A /* InternationalNumber.swift in Sources */, 7751009C2B62065800F46109 /* Date+IndieMusic.swift in Sources */, 7751D3802B45271600F1F2BD /* BindPhoneViewModel.swift in Sources */, diff --git a/IndieMusic/IndieMusic/Managers/LibsManager.swift b/IndieMusic/IndieMusic/Managers/LibsManager.swift index dbfe706..527ea69 100644 --- a/IndieMusic/IndieMusic/Managers/LibsManager.swift +++ b/IndieMusic/IndieMusic/Managers/LibsManager.swift @@ -34,7 +34,7 @@ class LibsManager: NSObject { libsManager.setupSwiftDate() libsManager.setupSVProgressHUD() - libsManager.setupKeyBoard() +// libsManager.setupKeyBoard() // libsManager.setupDorameonKit() // libsManager.setupBugly() diff --git a/IndieMusic/IndieMusic/Models/Message.swift b/IndieMusic/IndieMusic/Models/Message.swift index 1aebe16..45d45c1 100644 --- a/IndieMusic/IndieMusic/Models/Message.swift +++ b/IndieMusic/IndieMusic/Models/Message.swift @@ -15,16 +15,43 @@ struct Message: Codable { let isShowBadge: Bool let date: Int } +// +//struct MessageSection { +// var items: [Message] +//} + +enum MessageSection { + case message(items: [MessageSectionItem]) + case activities(items: [MessageSectionItem]) +} -struct MessageSection { - var items: [Message] +enum MessageSectionItem { + case messageItem(model: Message) + case activitiesItem(model: Message) + } + + extension MessageSection: SectionModelType { - typealias Item = Message + typealias Item = MessageSectionItem - init(original: MessageSection, items: [Item]) { - self = original - self.items = items + var items: [MessageSectionItem] { + switch self { + case .message(let items): + return items.map { $0 } + case .activities(let items): + return items.map { $0 } + } + } + + init(original: MessageSection, items: [MessageSectionItem]) { + switch original { + case .message(let items): + self = .message(items: items) + case .activities(let items): + self = .activities(items: items) + } } + } diff --git a/IndieMusic/IndieMusic/Models/PopoverMenu.swift b/IndieMusic/IndieMusic/Models/PopoverMenu.swift new file mode 100644 index 0000000..2fd53db --- /dev/null +++ b/IndieMusic/IndieMusic/Models/PopoverMenu.swift @@ -0,0 +1,26 @@ +// +// PopoverMenu.swift +// IndieMusic +// +// Created by WenLei on 2024/1/25. +// + +import Foundation + +enum PopoverMenu { + case blockList //黑名单 + case delete //删除 + case save //保存 + + + var title: String { + switch self { + case .blockList: + return "加入黑名单" + case .delete: + return "删除" + case .save: + return "保存" + } + } +} diff --git a/IndieMusic/IndieMusic/Modules/JournalDetail/JournalDetailView.swift b/IndieMusic/IndieMusic/Modules/JournalDetail/JournalDetailView.swift index e582e90..b584744 100644 --- a/IndieMusic/IndieMusic/Modules/JournalDetail/JournalDetailView.swift +++ b/IndieMusic/IndieMusic/Modules/JournalDetail/JournalDetailView.swift @@ -144,6 +144,7 @@ class JournalAudioHeaderView: UICollectionReusableView { let popoverView = FSPopoverView.init() popoverView.showsArrow = false popoverView.borderWidth = 0 + popoverView.transitioningDelegate = nil return popoverView }() diff --git a/IndieMusic/IndieMusic/Modules/Message/MessageViewController.swift b/IndieMusic/IndieMusic/Modules/Message/MessageViewController.swift index 4527d17..60f03e3 100644 --- a/IndieMusic/IndieMusic/Modules/Message/MessageViewController.swift +++ b/IndieMusic/IndieMusic/Modules/Message/MessageViewController.swift @@ -9,6 +9,7 @@ import UIKit import RxSwift import RxCocoa import RxDataSources +import FSPopoverView class MessageViewController: ViewController, UIScrollViewDelegate { @@ -21,7 +22,8 @@ class MessageViewController: ViewController, UIScrollViewDelegate { var tableView: UITableView = { let tableView = UITableView.init() tableView.register(MessageCellView.self, forCellReuseIdentifier: "MessageCellView") - + tableView.register(MessageActivitiesViewCell.self, forCellReuseIdentifier: "MessageActivitiesViewCell") + return tableView }() @@ -34,22 +36,65 @@ class MessageViewController: ViewController, UIScrollViewDelegate { }() + private let menuView: FSPopoverListView = { + let menuView = FSPopoverListView.init(scrollDirection: .horizontal) + do { + let features: [PopoverMenu] = [.blockList, .delete] + let items: [FSPopoverListItem] = features.map { feature in + let item = FSPopoverListTextItem(scrollDirection: .horizontal) + item.title = feature.title + item.titleFont = UIFont.systemFont(ofSize: 12) + item.isSeparatorHidden = false + item.titleColor = .white + item.contentInset = .init(top: 9, left: 15, bottom: 9, right: 15) + item.selectedHandler = { item in + guard let item = item as? FSPopoverListTextItem else { + return + } + print(item.title ?? "") + } + item.updateLayout() + return item + } + items.last?.isSeparatorHidden = true + menuView.shadowOpacity = 0 + menuView.shadowRadius = 0 + menuView.shadowColor = .clear + menuView.items = items + menuView.cornerRadius = 3 + menuView.transitioningDelegate = nil + + menuView.arrowSize = CGSize.init(width: 18, height: 5) + menuView.backgroundColor = .primaryText() + } + + return menuView + }() + override func viewDidLoad() { super.viewDidLoad() - // Do any additional setup after loading the view. + } override func makeUI() { super.makeUI() + + self.navigationItem.title = "消息列表" tableView.rx.setDelegate(self).disposed(by: rx.disposeBag) + view.addSubview(messageTopView) view.addSubview(tableView) view.addSubview(noDataView) + + + + + } override func bindViewModel() { @@ -70,7 +115,32 @@ class MessageViewController: ViewController, UIScrollViewDelegate { let output = viewModel.transform(input: input) - let dataSource = MessageViewController.tableViewDataSource() + let dataSource = RxTableViewSectionedReloadDataSource( + configureCell: { dataSource, tableView, indexPath, item in + + switch dataSource[indexPath] { + case .messageItem(let message): + let cell: MessageCellView = tableView.dequeueReusableCell(withIdentifier: "MessageCellView", for: indexPath) as! MessageCellView + cell.message = message + + cell.rx.longPressGesture().when(.recognized) + .subscribe { longPress in + + self.menuView.present(fromView: cell.nameLabel, displayIn: self.view) + }.disposed(by: self.rx.disposeBag) + + + return cell + + + case .activitiesItem(let message): + let cell: MessageActivitiesViewCell = tableView.dequeueReusableCell(withIdentifier: "MessageActivitiesViewCell", for: indexPath) as! MessageActivitiesViewCell + + return cell + + } + } + ) output.tableViewItems.bind(to: tableView.rx.items(dataSource: dataSource)).disposed(by: rx.disposeBag) @@ -81,6 +151,7 @@ class MessageViewController: ViewController, UIScrollViewDelegate { self?.navigator.show(segue: .commentList(viewModel: commentListViewModel), sender: self) + }.disposed(by: rx.disposeBag) @@ -115,23 +186,10 @@ class MessageViewController: ViewController, UIScrollViewDelegate { } - } -extension MessageViewController { - //TODO - static func tableViewDataSource() -> RxTableViewSectionedReloadDataSource { - return RxTableViewSectionedReloadDataSource( - configureCell: { dataSource, tableView, indexPath, item in - let cell: MessageCellView = tableView.dequeueReusableCell(withIdentifier: "MessageCellView", for: indexPath) as! MessageCellView - cell.message = item - - return cell - } - ) - } -} + @@ -386,6 +444,8 @@ class MessageActivitiesViewCell: UITableViewCell { }() + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) diff --git a/IndieMusic/IndieMusic/Modules/Message/MessageViewModel.swift b/IndieMusic/IndieMusic/Modules/Message/MessageViewModel.swift index 0f479c0..74da45f 100644 --- a/IndieMusic/IndieMusic/Modules/Message/MessageViewModel.swift +++ b/IndieMusic/IndieMusic/Modules/Message/MessageViewModel.swift @@ -24,27 +24,29 @@ class MessageViewModel: ViewModel, ViewModelType { let tableViewItems: BehaviorRelay<[MessageSection]> let collectionViewItems: BehaviorRelay<[MessageSection]> - let tableViewItemSelected: PublishSubject - let collectionViewItemSelected: PublishSubject + let tableViewItemSelected: PublishSubject + let collectionViewItemSelected: PublishSubject } let tableViewItems = BehaviorRelay<[MessageSection]>.init(value: []) let collectionViewItemstems = BehaviorRelay<[MessageSection]>.init(value: []) - let tableViewSelection = PublishSubject() - let collectionViewSelection = PublishSubject() + let tableViewSelection = PublishSubject() + let collectionViewSelection = PublishSubject() func transform(input: Input) -> Output { - let item = Message.init(icon: "", title: "评论", detail: "Mkle 回复了你的评论", isShowBadge: true, date: 1000000) + let message = Message.init(icon: "", title: "评论", detail: "Mkle 回复了你的评论", isShowBadge: true, date: 1000000) + let item = MessageSectionItem.messageItem(model: message) + let section = MessageSection.message(items: [item, item, item]) - tableViewItems.accept([MessageSection.init(items: [item, item, item, item])]) + tableViewItems.accept([section]) - collectionViewItemstems.accept([MessageSection.init(items: [item, item, item, item])]) +// collectionViewItemstems.accept([MessageSection.init(items: [item, item, item, item])]) input.collectionViewSelection.drive { indexPath in