Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // FullFilterVC.swift
- // hubble-ios
- //
- // Created by Appdesk Services PVT. LTD. on 23/02/24.
- // Copyright (c) 2023 hubble-ios. All rights reserved.
- //
- import UIKit
- class FullFilterVC: HubbleBaseVC {
- // navigation bar
- lazy var backButton: UIButton = {
- let button = UIButton()
- button.accessibilityElement(id: AccessIdentifier.backButton, label: AccessLabel.backButton)
- button.backgroundColor = .colorWhiteAlpha1
- button.tintColor = .white
- button.corner(cornerRadius: 10)
- button.setImage(.backButton, for: .normal)
- button.hubbleAction(forControlEvents: .touchUpInside) {
- self.popVC()
- }
- return button
- }()
- lazy var pageTitleLabel: UILabel = {
- let label = UILabel()
- label.text = "full_filter_vc_page_title".myLocalizedString
- label.font = .fontBold20
- return label
- }()
- lazy var filterOptionCollection: UICollectionView = {
- let layout = UICollectionViewFlowLayout()
- layout.scrollDirection = .vertical
- let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)
- collection.backgroundColor = .clear
- collection.delegate = self
- collection.dataSource = self
- collection.allowsMultipleSelection = true
- collection.showsHorizontalScrollIndicator = false
- collection.showsVerticalScrollIndicator = false
- collection.register(FullFilterCVC.self, forCellWithReuseIdentifier: FullFilterCVC.reuseId)
- return collection
- }()
- // bottom Button
- lazy var bottomButton: (container: UIView, rejact: UIButton, accept: UIButton) = {
- let view = UIView()
- view.corner(cornerRadius: 16, borderWidth: 1, .white)
- let clearAllButton = UIButton()
- clearAllButton.setTitle("full_filter_vc_clear_all_button".myLocalizedString, for: .normal)
- clearAllButton.setTitleColor(.white, for: .normal)
- clearAllButton.titleLabel?.font = .fontRegular18
- clearAllButton.backgroundColor = .clear
- clearAllButton.hubbleAction(forControlEvents: .touchUpInside) {
- self.clearAllButtonTapped()
- }
- clearAllButton.corner(cornerRadius: 12, borderWidth: 1, .white)
- let searchButton = UIButton()
- searchButton.setTitle("full_filter_vc_search_button".myLocalizedString, for: .normal)
- searchButton.setTitleColor(.primaryDarkColor, for: .normal)
- searchButton.titleLabel?.font = .fontBold18
- searchButton.backgroundColor = .white
- searchButton.hubbleAction(forControlEvents: .touchUpInside) {
- self.searchButtonTapped()
- }
- searchButton.corner(cornerRadius: 12)
- let stack = UIStackView(arrangedSubviews: [clearAllButton, searchButton])
- stack.axis = .horizontal
- stack.spacing = 16
- stack.alignment = .fill
- stack.distribution = .fillEqually
- view.addSubview(stack)
- stack.snp.makeConstraints { make in
- make.left.top.equalTo(view).offset(12)
- make.right.bottom.equalTo(view).inset(12)
- }
- return (view, clearAllButton, searchButton)
- }()
- override func viewDidLoad() {
- super.viewDidLoad()
- super.isSwipeToBackActive = true
- setupUi()
- }
- var selectedIndexes: [SelectedIndex] = []
- func clearAllButtonTapped() {
- selectedIndexes.forEach { index in
- self.filterOptionCollection.deselectItem(at: index.indexPath, animated: true)
- }
- selectedIndexes.removeAll()
- }
- func searchButtonTapped() {
- dump(selectedIndexes)
- }
- func setupUi() {
- self.view.addSubview(backButton)
- self.view.addSubview(pageTitleLabel)
- self.view.addSubview(filterOptionCollection)
- self.view.addSubview(bottomButton.container)
- backButton.snp.makeConstraints { make in
- make.top.equalTo(self.view.safeAreaLayoutGuide)
- make.left.equalTo(self.view).offset(leftOffset)
- make.height.width.equalTo(40)
- }
- pageTitleLabel.snp.makeConstraints { make in
- make.top.equalTo(backButton.bottom).offset(topOffset)
- make.left.equalTo(backButton.left)
- }
- filterOptionCollection.snp.makeConstraints { make in
- make.left.equalTo(self.view).offset(leftOffset)
- make.right.equalTo(self.view).inset(rightInset)
- make.top.equalTo(pageTitleLabel.bottom).offset(8)
- make.bottom.equalTo(bottomButton.container.top).inset(-4)
- }
- bottomButton.container.snp.makeConstraints { make in
- make.bottom.left.right.equalTo(self.view.safeAreaLayoutGuide)
- make.height.equalTo(90)
- }
- }
- }
- // MARK: - UICollectionViewDataSource
- extension FullFilterVC: UICollectionViewDataSource {
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return 100
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FullFilterCVC.reuseId, for: indexPath) as? FullFilterCVC {
- return cell
- }
- return UICollectionViewCell()
- }
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- print("Selected Index:- \(indexPath.item)")
- selectedIndexes.append(.init(indexPath: indexPath, indexData: "Rock"))
- }
- func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
- print("Un Selected Index:- \(indexPath.item)")
- selectedIndexes.removeAll { index in
- return index.indexPath == indexPath
- }
- }
- }
- // MARK: - UICollectionViewDelegateFlowLayout
- extension FullFilterVC: UICollectionViewDelegateFlowLayout {
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return .init(width: collectionView.width, height: 60)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment