12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //
- // TSTTPInputVC+Col.swift
- // AIEmoji
- //
- // Created by 100Years on 2025/5/7.
- //
-
- extension TSTTPInputVC {
- func creatCollectionComponent()->TSCollectionViewComponent {
- let layout = UICollectionViewFlowLayout()
- let cp = TSCollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [ :])
- cp.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
- cp.collectionView.isScrollEnabled = false
- cp.sectionActionHandler = { [weak self] cellCp, indexPath in
- guard let self = self else { return }
- if let cmd = cellCp as? String, cmd == "delete" {
- showCustomAlert(message: "Are you sure to delete".localized, deleteHandler: {
- self.viewModel.removeAllHistoryList()
- self.updateListDataView()
- })
- }
- }
-
- cp.itemDidSelectedHandler = { [weak self] (object, indexPath) in
- guard let self = self else { return }
- if indexPath.section == 0{
- if let sections = viewModel.colDataArray.safeObj(At: indexPath.section) as? TSGenmojiCoLSectionModel{
- var dataModelArray:[TSActionInfoModel] = []
- for itemModel in sections.items {
- dataModelArray.append(itemModel.dataModel)
- }
-
- let browseVC = TSAIPhotoBrowseVC()
- browseVC.dataModelArray = dataModelArray
- browseVC.currentIndex = indexPath.item
- browseVC.deleteComplete = { [weak self] deleteModel in
- guard let self = self else { return }
- TSRMShared.ttpDBHistory.deleteListModel(id: deleteModel.id)
- updateListDataView()
- }
- kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
- }
- }
- }
- return cp
- }
-
-
- func observerCollectionView(){
- //监听collectionView 的 contentSize
- collectionViewObserver = CollectionViewObserver(collectionView: collectionComponent.collectionView)
- collectionViewObserver.onContentSizeChange = {[weak self] size in
- guard let self = self else { return }
- print("collectionViewObserver 内容大小变化: \(size)")
- self.collectionComponent.collectionView.snp.updateConstraints { make in
- make.height.equalTo(size.height)
- }
- }
- }
-
- func updateListDataView(){
- viewModel.updateRecentData {[weak self] in
- guard let self = self else { return }
- updateListView()
- }
- }
-
- func updateListView(){
- self.collectionComponent.clear()
- self.collectionComponent.reloadView(with: self.viewModel.colDataArray)
- }
-
- }
|