Browse Source

height adjusted according to the menu height

pull/1/head
gme_2 6 years ago
parent
commit
241f8c9395
  1. 42
      GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift
  2. 6
      GMERemittance/Module/Home/User Interface/View/Home.storyboard
  3. 30
      GMERemittance/Module/Home/User Interface/View/HomeViewController.swift

42
GMERemittance/Module/Home/User Interface/View/Cell/HomeCollectionTableViewCell.swift

@ -15,6 +15,7 @@ struct MenuNotificationName {
static let trackYourTransfer = "trackYourTransfer" static let trackYourTransfer = "trackYourTransfer"
static let transactionStatement = "transactionStatement" static let transactionStatement = "transactionStatement"
static let walletToWallet = "walletToWallet" static let walletToWallet = "walletToWallet"
static let collectionHeight = "height_height"
} }
class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlowLayout { class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlowLayout {
@ -38,6 +39,7 @@ class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlow
func setup() { func setup() {
collectionView.addObserver(self, forKeyPath: "contentSize", options: NSKeyValueObservingOptions.old, context: nil)
self.configureMenu() self.configureMenu()
self.collectionView.delegate = self self.collectionView.delegate = self
self.collectionView.dataSource = self self.collectionView.dataSource = self
@ -77,19 +79,38 @@ class HomeCollectionTableViewCell: UITableViewCell, UICollectionViewDelegateFlow
self.menus = [sendMoneyMenu, mobileRechargeMenu, toadaysRateMenu, trackTransferMenu, transactionStatementMenu, walletToWalletMenu] 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 { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemsPerRow: CGFloat = 2 let itemsPerRow: CGFloat = 2
let paddingSpace: CGFloat = CGFloat(20 * (itemsPerRow + 1)) let paddingSpace: CGFloat = CGFloat(20 * (itemsPerRow + 1))
let availableWidth = frame.width - paddingSpace let availableWidth = frame.width - paddingSpace
let widthPerItem = availableWidth / itemsPerRow 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 { extension HomeCollectionTableViewCell: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let index = self.menus?.elementAt(index: indexPath.row)?.index else {return} guard let index = self.menus?.elementAt(index: indexPath.row)?.index else {return}
@ -133,22 +154,9 @@ extension HomeCollectionTableViewCell: UICollectionViewDelegate {
func getWalletToWalletNotificationName() -> Notification.Name { func getWalletToWalletNotificationName() -> Notification.Name {
return Notification.Name.init(rawValue: MenuNotificationName.walletToWallet) 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)
} }
} }

6
GMERemittance/Module/Home/User Interface/View/Home.storyboard

@ -35,11 +35,11 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="wXh-zk-jWw">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="wXh-zk-jWw">
<rect key="frame" x="0.0" y="20" width="375" height="598"/> <rect key="frame" x="0.0" y="20" width="375" height="598"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes> <prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="HomeRemainingLimitTableViewCell" rowHeight="115" id="rcn-u6-1gx" customClass="HomeRemainingLimitTableViewCell" customModule="GMERemittance" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="HomeRemainingLimitTableViewCell" rowHeight="115" id="rcn-u6-1gx" customClass="HomeRemainingLimitTableViewCell" customModule="GMERemittance" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="375" height="115"/> <rect key="frame" x="0.0" y="28" width="375" height="115"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="rcn-u6-1gx" id="ekT-Zr-ohe"> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="rcn-u6-1gx" id="ekT-Zr-ohe">
@ -152,7 +152,7 @@
<outlet property="userNameLabel" destination="HSv-Iz-JvY" id="aE5-dT-TQa"/> <outlet property="userNameLabel" destination="HSv-Iz-JvY" id="aE5-dT-TQa"/>
</connections> </connections>
</tableViewCell> </tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="HomeCollectionTableViewCell" rowHeight="250" id="va0-Yj-PKZ" userLabel="CollectionTableCell" customClass="HomeCollectionTableViewCell" customModule="GMERemittance" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" selectionStyle="none" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="HomeCollectionTableViewCell" rowHeight="250" id="va0-Yj-PKZ" userLabel="CollectionTableCell" customClass="HomeCollectionTableViewCell" customModule="GMERemittance" customModuleProvider="target">
<rect key="frame" x="0.0" y="143" width="375" height="250"/> <rect key="frame" x="0.0" y="143" width="375" height="250"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="va0-Yj-PKZ" id="UgU-Jo-DQf"> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="va0-Yj-PKZ" id="UgU-Jo-DQf">

30
GMERemittance/Module/Home/User Interface/View/HomeViewController.swift

@ -25,7 +25,11 @@ class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout {
var presenter: HomeModuleInterface? var presenter: HomeModuleInterface?
var sections: [Sections] = [.balance, .collection] var sections: [Sections] = [.balance, .collection]
var menuHeight: CGFloat? {
didSet {
self.tableView.reloadData()
}
}
// MARK: VC's Life cycle // MARK: VC's Life cycle
override func viewDidLoad() { override func viewDidLoad() {
@ -50,10 +54,11 @@ class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout {
setupDelegates() setupDelegates()
configureViews() configureViews()
setupNotifications() setupNotifications()
self.setupPicturedNavBar() self.setupPicturedNavBar()
} }
private func setupNotifications() { private func setupNotifications() {
let center = NotificationCenter.default let center = NotificationCenter.default
center.addObserver(self, selector: #selector(self.showSendMoney), name: self.getSendMoneyNotificationName(), object: nil) center.addObserver(self, selector: #selector(self.showSendMoney), name: self.getSendMoneyNotificationName(), object: nil)
@ -62,6 +67,7 @@ class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout {
center.addObserver(self, selector: #selector(self.showTrackYourTransfer), name: self.getTrackYourTransferNotificationName(), object: nil) center.addObserver(self, selector: #selector(self.showTrackYourTransfer), name: self.getTrackYourTransferNotificationName(), object: nil)
center.addObserver(self, selector: #selector(self.showTransactionStatement), name: self.getTransactionStatementNotificationName(), object: nil) center.addObserver(self, selector: #selector(self.showTransactionStatement), name: self.getTransactionStatementNotificationName(), object: nil)
center.addObserver(self, selector: #selector(self.showWalletToWallet), name: self.getWalletToWalletNotificationName(), object: nil) center.addObserver(self, selector: #selector(self.showWalletToWallet), name: self.getWalletToWalletNotificationName(), object: nil)
center.addObserver(self, selector: #selector(self.setupHeight(sender:)), name: self.getCollectionHeightNotificationName(), object: nil)
} }
private func setupDelegates() { private func setupDelegates() {
@ -82,9 +88,17 @@ class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout {
self.verificationNoticeView.isHidden = true self.verificationNoticeView.isHidden = true
self.verificationNoticeView.alpha = 0 self.verificationNoticeView.alpha = 0
showUnverifiedNotice() showUnverifiedNotice()
setNavBar()
} }
func setNavBar() {
let selector = #selector(self.showSideMenu)
self.setupPicturedNavBar(sideMenuAction: selector)
}
@objc func showSideMenu() {
sideMenuController?.showLeftViewAnimated()
}
private func isUserVerified() -> Bool { private func isUserVerified() -> Bool {
return false return false
@ -132,6 +146,12 @@ class HomeViewController: UIViewController, UICollectionViewDelegateFlowLayout {
@objc private func showWalletToWallet() { @objc private func showWalletToWallet() {
self.alert(message: "This feature is coming soon") self.alert(message: "This feature is coming soon")
} }
@objc private func setupHeight(sender: Notification) {
if let height = sender.userInfo?[MenuNotificationName.collectionHeight] as? CGFloat {
self.menuHeight = height
}
}
} }
// MARK: HomeViewInterface // MARK: HomeViewInterface
@ -152,7 +172,7 @@ extension HomeViewController: UITableViewDelegate {
let totalHeight = view.frame.height let totalHeight = view.frame.height
let ramainingBalanceCellHeight: CGFloat = 100 let ramainingBalanceCellHeight: CGFloat = 100
let finalHeight = totalHeight - ramainingBalanceCellHeight let finalHeight = totalHeight - ramainingBalanceCellHeight
return finalHeight
return self.menuHeight ?? finalHeight
} }
} }
} }
@ -215,4 +235,8 @@ extension HomeViewController {
func getWalletToWalletNotificationName() -> Notification.Name { func getWalletToWalletNotificationName() -> Notification.Name {
return Notification.Name.init(rawValue: MenuNotificationName.walletToWallet) return Notification.Name.init(rawValue: MenuNotificationName.walletToWallet)
} }
func getCollectionHeightNotificationName() -> Notification.Name {
return Notification.Name.init(rawValue: MenuNotificationName.collectionHeight)
}
} }
Loading…
Cancel
Save