Created
February 25, 2020 15:00
-
-
Save MickaelCruzDB/37297c7bf7201ddd657cbda12a6cbef7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
// Working with functions categories collection view | |
if collectionView == self.functionsCategoriesCollectionView { | |
let cell = collectionView.cellForItem(at: indexPath) as! DevicePageFunctionsCategoriesCVCell | |
cell.isHidden = false | |
cell.cellView.isHidden = false | |
cell.isSelected = true | |
cell.cellView.clipsToBounds = true | |
cell.cellView.layer.cornerRadius = 25 | |
cell.cellView.addGradiant(colors: [UIColor(red: 127.0/255.0, green: 127.0/255.0, blue: 127.0/255.0, alpha: 1.0).cgColor, UIColor(red: 47.0/255.0, green: 47.0/255.0, blue: 47.0/255.0, alpha: 1.0).cgColor], angle: 45) | |
if cellSelectionIndexPath == indexPath { | |
// it was already selected | |
cellSelectionIndexPath = nil | |
collectionView.deselectItem(at: indexPath, animated: true) | |
cell.cellView.addGradiant(colors: [UIColor.clear.cgColor, UIColor.clear.cgColor], angle: 0) | |
self.filtered = GlobalVariables.currentProduct.functions.filter { _ in | |
return true | |
} | |
self.functionsCollectionView.reloadData() | |
} else { | |
// wasn't yet selected, so let's remember it | |
cellSelectionIndexPath = indexPath | |
// Filter with seletec category name | |
let cellCategoryName = ICDatabase.objects(FunctionCategory.self)[indexPath.row] | |
self.filtered = GlobalVariables.currentProduct.functions.filter { function in | |
return function.functionCategory.contains(cellCategoryName) | |
} | |
self.functionsCollectionView.reloadData() | |
} | |
} | |
} | |
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { | |
if collectionView == self.functionsCategoriesCollectionView { | |
if let cellToDeselect = collectionView.cellForItem(at: self.cellSelectionIndexPath) as? DevicePageFunctionsCategoriesCVCell { | |
cellToDeselect.isSelected = false | |
collectionView.deselectItem(at: self.cellSelectionIndexPath, animated: true) | |
cellToDeselect.cellView.addGradiant(colors: [UIColor.clear.cgColor, UIColor.clear.cgColor], angle: 0) | |
self.cellSelectionIndexPath = nil | |
// Get all functions | |
self.filtered = GlobalVariables.currentProduct.functions.filter { _ in | |
return true | |
} | |
self.functionsCollectionView.reloadData() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment