ChandanAppdesk

FullFilterVC

Feb 26th, 2024
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 6.18 KB | Source Code | 0 0
  1. //
  2. // FullFilterVC.swift
  3. // hubble-ios
  4. //
  5. // Created by Appdesk Services PVT. LTD. on 23/02/24.
  6. // Copyright (c) 2023 hubble-ios. All rights reserved.
  7. //
  8.  
  9.  
  10. import UIKit
  11.  
  12. class FullFilterVC: HubbleBaseVC {
  13.  
  14.     // navigation bar
  15.     lazy var backButton: UIButton = {
  16.         let button = UIButton()
  17.         button.accessibilityElement(id: AccessIdentifier.backButton, label: AccessLabel.backButton)
  18.         button.backgroundColor = .colorWhiteAlpha1
  19.         button.tintColor = .white
  20.         button.corner(cornerRadius: 10)
  21.         button.setImage(.backButton, for: .normal)
  22.         button.hubbleAction(forControlEvents: .touchUpInside) {
  23.             self.popVC()
  24.         }
  25.         return button
  26.     }()
  27.     lazy var pageTitleLabel: UILabel = {
  28.         let label = UILabel()
  29.         label.text = "full_filter_vc_page_title".myLocalizedString
  30.         label.font = .fontBold20
  31.         return label
  32.     }()
  33.     lazy var filterOptionCollection: UICollectionView = {
  34.         let layout = UICollectionViewFlowLayout()
  35.         layout.scrollDirection = .vertical
  36.         let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)
  37.         collection.backgroundColor = .clear
  38.         collection.delegate = self
  39.         collection.dataSource = self
  40.         collection.allowsMultipleSelection = true
  41.         collection.showsHorizontalScrollIndicator = false
  42.         collection.showsVerticalScrollIndicator = false
  43.         collection.register(FullFilterCVC.self, forCellWithReuseIdentifier: FullFilterCVC.reuseId)
  44.         return collection
  45.     }()
  46.  
  47.     // bottom Button
  48.     lazy var bottomButton: (container: UIView, rejact: UIButton, accept: UIButton) = {
  49.         let view = UIView()
  50.         view.corner(cornerRadius: 16, borderWidth: 1, .white)
  51.         let clearAllButton = UIButton()
  52.         clearAllButton.setTitle("full_filter_vc_clear_all_button".myLocalizedString, for: .normal)
  53.         clearAllButton.setTitleColor(.white, for: .normal)
  54.         clearAllButton.titleLabel?.font = .fontRegular18
  55.         clearAllButton.backgroundColor = .clear
  56.         clearAllButton.hubbleAction(forControlEvents: .touchUpInside) {
  57.             self.clearAllButtonTapped()
  58.         }
  59.         clearAllButton.corner(cornerRadius: 12, borderWidth: 1, .white)
  60.         let searchButton = UIButton()
  61.         searchButton.setTitle("full_filter_vc_search_button".myLocalizedString, for: .normal)
  62.         searchButton.setTitleColor(.primaryDarkColor, for: .normal)
  63.         searchButton.titleLabel?.font = .fontBold18
  64.         searchButton.backgroundColor = .white
  65.         searchButton.hubbleAction(forControlEvents: .touchUpInside) {
  66.             self.searchButtonTapped()
  67.         }
  68.         searchButton.corner(cornerRadius: 12)
  69.         let stack = UIStackView(arrangedSubviews: [clearAllButton, searchButton])
  70.         stack.axis = .horizontal
  71.         stack.spacing = 16
  72.         stack.alignment = .fill
  73.         stack.distribution = .fillEqually
  74.         view.addSubview(stack)
  75.         stack.snp.makeConstraints { make in
  76.             make.left.top.equalTo(view).offset(12)
  77.             make.right.bottom.equalTo(view).inset(12)
  78.         }
  79.         return (view, clearAllButton, searchButton)
  80.     }()
  81.  
  82.     override func viewDidLoad() {
  83.         super.viewDidLoad()
  84.         super.isSwipeToBackActive = true
  85.         setupUi()
  86.     }
  87.     var selectedIndexes: [SelectedIndex] = []
  88.     func clearAllButtonTapped() {
  89.         selectedIndexes.forEach { index in
  90.             self.filterOptionCollection.deselectItem(at: index.indexPath, animated: true)
  91.         }
  92.         selectedIndexes.removeAll()
  93.     }
  94.     func searchButtonTapped() {
  95.         dump(selectedIndexes)
  96.     }
  97.    
  98.     func setupUi() {
  99.         self.view.addSubview(backButton)
  100.         self.view.addSubview(pageTitleLabel)
  101.         self.view.addSubview(filterOptionCollection)
  102.         self.view.addSubview(bottomButton.container)
  103.         backButton.snp.makeConstraints { make in
  104.             make.top.equalTo(self.view.safeAreaLayoutGuide)
  105.             make.left.equalTo(self.view).offset(leftOffset)
  106.             make.height.width.equalTo(40)
  107.         }
  108.         pageTitleLabel.snp.makeConstraints { make in
  109.             make.top.equalTo(backButton.bottom).offset(topOffset)
  110.             make.left.equalTo(backButton.left)
  111.         }
  112.         filterOptionCollection.snp.makeConstraints { make in
  113.             make.left.equalTo(self.view).offset(leftOffset)
  114.             make.right.equalTo(self.view).inset(rightInset)
  115.             make.top.equalTo(pageTitleLabel.bottom).offset(8)
  116.             make.bottom.equalTo(bottomButton.container.top).inset(-4)
  117.         }
  118.         bottomButton.container.snp.makeConstraints { make in
  119.             make.bottom.left.right.equalTo(self.view.safeAreaLayoutGuide)
  120.             make.height.equalTo(90)
  121.         }
  122.     }
  123. }
  124.  
  125. // MARK: - UICollectionViewDataSource
  126. extension FullFilterVC: UICollectionViewDataSource {
  127.     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  128.         return 100
  129.     }
  130.    
  131.     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  132.         if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FullFilterCVC.reuseId, for: indexPath) as? FullFilterCVC {
  133.             return cell
  134.         }
  135.         return UICollectionViewCell()
  136.     }
  137.  
  138.     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  139.         print("Selected Index:- \(indexPath.item)")
  140.         selectedIndexes.append(.init(indexPath: indexPath, indexData: "Rock"))
  141.     }
  142.  
  143.     func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
  144.         print("Un Selected Index:- \(indexPath.item)")
  145.         selectedIndexes.removeAll { index in
  146.             return index.indexPath == indexPath
  147.         }
  148.     }
  149. }
  150.  
  151. // MARK: - UICollectionViewDelegateFlowLayout
  152. extension FullFilterVC: UICollectionViewDelegateFlowLayout {
  153.     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  154.         return .init(width: collectionView.width, height: 60)
  155.     }
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment