add popoverMenu

dev
wenlei 10 months ago
parent 88cdaf5be3
commit af370934ca

@ -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 = "<group>"; };
775100992B62050C00F46109 /* UIImageView+Rx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+Rx.swift"; sourceTree = "<group>"; };
7751009B2B62065800F46109 /* Date+IndieMusic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+IndieMusic.swift"; sourceTree = "<group>"; };
7751009D2B62330900F46109 /* PopoverMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopoverMenu.swift; sourceTree = "<group>"; };
7751D34F2B42ABBF00F1F2BD /* SettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewController.swift; sourceTree = "<group>"; };
7751D3512B42AC2B00F1F2BD /* SettingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingView.swift; sourceTree = "<group>"; };
7751D3532B42AE0E00F1F2BD /* SettingViewMdel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewMdel.swift; sourceTree = "<group>"; };
@ -698,6 +700,7 @@
77C9B9EA2B4BE7E50006C83F /* Comment.swift */,
770228E82B55169C00E07F7A /* InternationalNumber.swift */,
770228EC2B55284F00E07F7A /* Login.swift */,
7751009D2B62330900F46109 /* PopoverMenu.swift */,
);
path = Models;
sourceTree = "<group>";
@ -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 */,

@ -34,7 +34,7 @@ class LibsManager: NSObject {
libsManager.setupSwiftDate()
libsManager.setupSVProgressHUD()
libsManager.setupKeyBoard()
// libsManager.setupKeyBoard()
// libsManager.setupDorameonKit()
// libsManager.setupBugly()

@ -15,16 +15,43 @@ struct Message: Codable {
let isShowBadge: Bool
let date: Int
}
//
//struct MessageSection {
// var items: [Message]
//}
struct MessageSection {
var items: [Message]
enum MessageSection {
case message(items: [MessageSectionItem])
case activities(items: [MessageSectionItem])
}
enum MessageSectionItem {
case messageItem(model: Message)
case activitiesItem(model: Message)
}
extension MessageSection: SectionModelType {
typealias Item = Message
typealias Item = MessageSectionItem
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: [Item]) {
self = original
self.items = items
init(original: MessageSection, items: [MessageSectionItem]) {
switch original {
case .message(let items):
self = .message(items: items)
case .activities(let items):
self = .activities(items: items)
}
}
}

@ -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 "保存"
}
}
}

@ -144,6 +144,7 @@ class JournalAudioHeaderView: UICollectionReusableView {
let popoverView = FSPopoverView.init()
popoverView.showsArrow = false
popoverView.borderWidth = 0
popoverView.transitioningDelegate = nil
return popoverView
}()

@ -9,6 +9,7 @@ import UIKit
import RxSwift
import RxCocoa
import RxDataSources
import FSPopoverView
class MessageViewController: ViewController, UIScrollViewDelegate {
@ -21,6 +22,7 @@ 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<MessageSection>(
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)
@ -116,22 +187,9 @@ class MessageViewController: ViewController, UIScrollViewDelegate {
}
}
extension MessageViewController {
//TODO
static func tableViewDataSource() -> RxTableViewSectionedReloadDataSource<MessageSection> {
return RxTableViewSectionedReloadDataSource<MessageSection>(
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)

@ -24,27 +24,29 @@ class MessageViewModel: ViewModel, ViewModelType {
let tableViewItems: BehaviorRelay<[MessageSection]>
let collectionViewItems: BehaviorRelay<[MessageSection]>
let tableViewItemSelected: PublishSubject<Message>
let collectionViewItemSelected: PublishSubject<Message>
let tableViewItemSelected: PublishSubject<MessageSectionItem>
let collectionViewItemSelected: PublishSubject<MessageSectionItem>
}
let tableViewItems = BehaviorRelay<[MessageSection]>.init(value: [])
let collectionViewItemstems = BehaviorRelay<[MessageSection]>.init(value: [])
let tableViewSelection = PublishSubject<Message>()
let collectionViewSelection = PublishSubject<Message>()
let tableViewSelection = PublishSubject<MessageSectionItem>()
let collectionViewSelection = PublishSubject<MessageSectionItem>()
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

Loading…
Cancel
Save