|
|
@ -15,6 +15,7 @@ struct MenuNotificationName { |
|
|
|
static let trackYourTransfer = "trackYourTransfer" |
|
|
|
static let transactionStatement = "transactionStatement" |
|
|
|
static let walletToWallet = "walletToWallet" |
|
|
|
static let collectionHeight = "height_height" |
|
|
|
} |
|
|
|
|
|
|
|
class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlowLayout { |
|
|
@ -38,6 +39,7 @@ class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlow |
|
|
|
|
|
|
|
|
|
|
|
func setup() { |
|
|
|
collectionView.addObserver(self, forKeyPath: "contentSize", options: NSKeyValueObservingOptions.old, context: nil) |
|
|
|
self.configureMenu() |
|
|
|
self.collectionView.delegate = self |
|
|
|
self.collectionView.dataSource = self |
|
|
@ -77,19 +79,38 @@ class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlow |
|
|
|
self.menus = [sendMoneyMenu, mobileRechargeMenu, toadaysRateMenu, trackTransferMenu, transactionStatementMenu, walletToWalletMenu] |
|
|
|
} |
|
|
|
|
|
|
|
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { |
|
|
|
if let observedObject = object as? UICollectionView, observedObject == collectionView { |
|
|
|
let height = self.collectionView.contentSize.height |
|
|
|
let finalHeight = height + CGFloat(20) |
|
|
|
NotificationCenter.default.post(name: self.getCollectionHeightNotificationName(), object: nil, userInfo: [MenuNotificationName.collectionHeight : finalHeight]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { |
|
|
|
let itemsPerRow: CGFloat = 2 |
|
|
|
let paddingSpace: CGFloat = CGFloat(20 * (itemsPerRow + 1)) |
|
|
|
let availableWidth = frame.width - paddingSpace |
|
|
|
let widthPerItem = availableWidth / itemsPerRow |
|
|
|
|
|
|
|
return CGSize(width: widthPerItem, height: widthPerItem) |
|
|
|
return CGSize(width: widthPerItem, height: widthPerItem * 1.2) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
extension HomeCollectionTableViewCell: UICollectionViewDataSource { |
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
|
|
|
return menus?.count ?? 0 |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
|
|
|
let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: "HomeCollectionCollectionViewCell", for: indexPath) as! HomeCollectionCollectionViewCell |
|
|
|
cell.model = self.menus?.elementAt(index: indexPath.row) |
|
|
|
cell.setup() |
|
|
|
return cell |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
extension HomeCollectionTableViewCell: UICollectionViewDelegate { |
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
|
|
|
guard let index = self.menus?.elementAt(index: indexPath.row)?.index else {return} |
|
|
@ -133,22 +154,9 @@ extension HomeCollectionTableViewCell: UICollectionViewDelegate { |
|
|
|
func getWalletToWalletNotificationName() -> Notification.Name { |
|
|
|
return Notification.Name.init(rawValue: MenuNotificationName.walletToWallet) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
extension HomeCollectionTableViewCell: UICollectionViewDataSource { |
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { |
|
|
|
return menus?.count ?? 0 |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { |
|
|
|
let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: "HomeCollectionCollectionViewCell", for: indexPath) as! HomeCollectionCollectionViewCell |
|
|
|
cell.model = self.menus?.elementAt(index: indexPath.row) |
|
|
|
cell.setup() |
|
|
|
return cell |
|
|
|
func getCollectionHeightNotificationName() -> Notification.Name { |
|
|
|
return Notification.Name.init(rawValue: MenuNotificationName.collectionHeight) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|