TSTTPInputVC+Col.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // TSTTPInputVC+Col.swift
  3. // AIEmoji
  4. //
  5. // Created by 100Years on 2025/5/7.
  6. //
  7. extension TSTTPInputVC {
  8. func creatCollectionComponent()->TSCollectionViewComponent {
  9. let layout = UICollectionViewFlowLayout()
  10. let cp = TSCollectionViewComponent(frame: CGRect.zero, layout: layout, attributes: [ :])
  11. cp.collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
  12. cp.collectionView.isScrollEnabled = false
  13. cp.sectionActionHandler = { [weak self] cellCp, indexPath in
  14. guard let self = self else { return }
  15. if let cmd = cellCp as? String, cmd == "delete" {
  16. showCustomAlert(message: "Are you sure to delete".localized, deleteHandler: {
  17. self.viewModel.removeAllHistoryList()
  18. self.updateListDataView()
  19. })
  20. }
  21. }
  22. cp.itemDidSelectedHandler = { [weak self] (object, indexPath) in
  23. guard let self = self else { return }
  24. if indexPath.section == 0{
  25. if let sections = viewModel.colDataArray.safeObj(At: indexPath.section) as? TSGenmojiCoLSectionModel{
  26. var dataModelArray:[TSActionInfoModel] = []
  27. for itemModel in sections.items {
  28. dataModelArray.append(itemModel.dataModel)
  29. }
  30. let browseVC = TSAIPhotoBrowseVC()
  31. browseVC.dataModelArray = dataModelArray
  32. browseVC.currentIndex = indexPath.item
  33. browseVC.deleteComplete = { [weak self] deleteModel in
  34. guard let self = self else { return }
  35. TSRMShared.ttpDBHistory.deleteListModel(id: deleteModel.id)
  36. updateListDataView()
  37. }
  38. kPresentModalVC(target: self, modelVC: browseVC,transitionStyle: .crossDissolve)
  39. }
  40. }
  41. }
  42. return cp
  43. }
  44. func observerCollectionView(){
  45. //监听collectionView 的 contentSize
  46. collectionViewObserver = CollectionViewObserver(collectionView: collectionComponent.collectionView)
  47. collectionViewObserver.onContentSizeChange = {[weak self] size in
  48. guard let self = self else { return }
  49. print("collectionViewObserver 内容大小变化: \(size)")
  50. self.collectionComponent.collectionView.snp.updateConstraints { make in
  51. make.height.equalTo(size.height)
  52. }
  53. }
  54. }
  55. func updateListDataView(){
  56. viewModel.updateRecentData {[weak self] in
  57. guard let self = self else { return }
  58. updateListView()
  59. }
  60. }
  61. func updateListView(){
  62. self.collectionComponent.clear()
  63. self.collectionComponent.reloadView(with: self.viewModel.colDataArray)
  64. }
  65. }