Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Home Panel: dismiss keyboard + animations

  • Loading branch information
Tim Palade authored and mahmoud-adam85 committed May 11, 2018
1 parent bd6fabb commit e08ae96dc1075131f0fb146332702406bbcf286a
@@ -77,7 +77,7 @@ class FreshtabViewController: UIViewController, HomePanel {

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIView.animate(withDuration: 0.05, delay: 0.1, options: .allowAnimatedContent, animations: {
UIView.animate(withDuration: 0.1, delay: 0.1, options: .curveEaseIn, animations: {
self.normalModeView?.alpha = 1.0
}, completion: nil)
}
@@ -210,6 +210,12 @@ class FreshtabViewController: UIViewController, HomePanel {
self.normalModeView = UIView()
self.normalModeView?.backgroundColor = UIColor.clear
self.scrollView.addSubview(self.normalModeView!)

let tap = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
normalModeView?.addGestureRecognizer(tap)

let pan = UIPanGestureRecognizer(target: self, action: #selector(dismissKeyboard))
normalModeView?.addGestureRecognizer(pan)

self.topSitesViewController = TopSitesViewController(dataSource: self.topSitesDataSource)
self.topSitesViewController?.homePanelDelegate = self.homePanelDelegate
@@ -227,6 +233,10 @@ class FreshtabViewController: UIViewController, HomePanel {
}
}
}

func dismissKeyboard(_ sender: Any? = nil) {
view.window?.rootViewController?.view.endEditing(true)
}
}

extension FreshtabViewController: UIScrollViewDelegate {
@@ -57,9 +57,9 @@ class NewsViewCell: ClickableUITableViewCell {
let placeholder = LogoPlaceholder(logoInfo: logoInfo)
self.fakeLogoView = placeholder
}
self.logoImageView.alpha = 0.0
viewModel?.logo.asObservable().subscribe(onNext: { (img) in
self.logoImageView.image = img
self.logoImageView.alpha = 0.0
self.logoImageView.transform = CGAffineTransform.init(scaleX: 0.95, y: 0.95)
UIView.animate(withDuration: 0.2, animations: {
self.logoImageView.alpha = 1.0
@@ -183,6 +183,7 @@ extension TopSitesViewController: UICollectionViewDataSource, UICollectionViewDe

cell.tag = indexPath.row
let url = topSite.url
cell.logoContainerView.alpha = 0.0
LogoLoader.loadLogo(url, completionBlock: { (img, logoInfo, error) in
if cell.tag == indexPath.row {
if let img = img {
@@ -198,6 +199,9 @@ extension TopSitesViewController: UICollectionViewDataSource, UICollectionViewDe
}
cell.logoHostLabel.text = logoInfo?.hostName
}
UIView.animate(withDuration: 0.1, animations: {
cell.logoContainerView.alpha = 1.0
})
})
}
if cell.gestureRecognizers == nil {
@@ -118,7 +118,8 @@ class CliqzHistoryPanel: HistoryPanel {
if let site = siteForIndexPath(indexPath), let cell = cell as? CliqzSiteTableViewCell {
cell.setLines(site.title, detailText: site.url)
cell.tag = indexPath.row

cell.imageShadowView.alpha = 0.0
cell.imageShadowView.transform = CGAffineTransform.init(scaleX: 0.8, y: 0.8)
LogoLoader.loadLogo(site.tileURL.absoluteString, completionBlock: { (img, logoInfo, error) in
if cell.tag == indexPath.row {
if let img = img {
@@ -129,6 +130,10 @@ class CliqzHistoryPanel: HistoryPanel {
cell.fakeIt(placeholder)
}
}
UIView.animate(withDuration: 0.15, animations: {
cell.imageShadowView.alpha = 1.0
cell.imageShadowView.transform = CGAffineTransform.identity
})
})
}
return cell
@@ -172,26 +177,14 @@ class CliqzSiteTableViewCell: SiteTableViewCell {
super.init(style: style, reuseIdentifier: reuseIdentifier)

separatorInset = UIEdgeInsets(top: 0, left: CliqzHistoryPanelUX.separatorLeftInset, bottom: 0, right: 0)
contentView.addSubview(customImageView)
contentView.addSubview(imageShadowView)
imageShadowView.addSubview(customImageView)
customImageView.layer.cornerRadius = CliqzHistoryPanelUX.iconCornerRadius
customImageView.clipsToBounds = true

contentView.addSubview(imageShadowView)
setupImageShadow()
setUpLabels()
}

override func updateConstraints() {

customImageView.snp.remakeConstraints { (make) in
make.size.equalTo(CliqzHistoryPanelUX.iconSize)
make.centerY.equalToSuperview()
make.leading.equalToSuperview().offset(8)
}

super.updateConstraints()
}

override func setHighlighted(_ highlighted: Bool, animated: Bool) {
if highlighted {
self.backgroundColor = UIColor.white.withAlphaComponent(0.2)
@@ -216,6 +209,7 @@ class CliqzSiteTableViewCell: SiteTableViewCell {
setupImageShadow()
setUpLabels()
fakeView = nil
customImageView.image = nil
}

func fakeIt(_ view: UIView) {
@@ -235,13 +229,18 @@ class CliqzSiteTableViewCell: SiteTableViewCell {
private func setupImageShadow() {

imageShadowView.clipsToBounds = false
imageShadowView.backgroundColor = .white
imageShadowView.backgroundColor = UIColor.cliqzURLBarColor
contentView.sendSubview(toBack: imageShadowView)
contentView.bringSubview(toFront: customImageView)

customImageView.snp.remakeConstraints { (make) in
make.edges.equalToSuperview()
}

imageShadowView.snp.remakeConstraints { (make) in
make.size.equalTo(CliqzHistoryPanelUX.iconSize)
make.center.equalTo(customImageView.snp.center)
make.centerY.equalToSuperview()
make.leading.equalToSuperview().offset(8)
}

imageShadowView.layer.cornerRadius = CliqzHistoryPanelUX.iconCornerRadius
@@ -116,11 +116,15 @@ class CliqzHomePanelViewController: UIViewController, UITextFieldDelegate {
backgroundView.image = UIImage.cliqzBackgroundImage()//?.applyBlur(withRadius: 5, blurType: BOXFILTER, tintColor: UIColor.black.withAlphaComponent(0.1), saturationDeltaFactor: 1.8, maskImage: nil)
}

func dismissKeyboard(_ sender: Any? = nil) {
view.window?.rootViewController?.view.endEditing(true)
}
}

extension CliqzHomePanelViewController {

@objc func segmentedControlValueChanged(control: UISegmentedControl) {
self.dismissKeyboard()
selectedPanel = HomePanelType(rawValue: control.selectedSegmentIndex) //control.selectedSegmentIndex must be between 0 and 3
}

0 comments on commit e08ae96

Please sign in to comment.