Skip to content

Commit

Permalink
Merge pull request #24 from naveen-c/master
Browse files Browse the repository at this point in the history
Scroll behaviour handling
  • Loading branch information
rajatgupta26 authored Jul 30, 2018
2 parents 72acb1d + 5e483c5 commit f4b93f0
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 48 deletions.
56 changes: 56 additions & 0 deletions ContentSheet/Classes/ContentHeader.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// ContentHeader.swift
// ContentSheet
//
// Created by Naveen Chaudhary on 30/07/18.
//

public class ContentHeaderView: UIView {

public override init(frame: CGRect) {
super.init(frame: frame)
self.isTranslucent = true
}

public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.isTranslucent = true
}

public var isTranslucent: Bool = true {
didSet {
if isTranslucent {
self._setBlurrEffect(true)
} else {
self._setBlurrEffect(false)
}
}
}

fileprivate var _blurEffectView: UIVisualEffectView?

private func _setBlurrEffect(_ add: Bool) {
let onView = self
if add {
let blurEffectStyle: UIBlurEffectStyle
if #available(iOS 10.0, *) {
blurEffectStyle = .regular
} else {
blurEffectStyle = .light
}
let blurEffect = UIBlurEffect(style: blurEffectStyle)
_blurEffectView = UIVisualEffectView(effect: blurEffect)
if let blurEffectView = _blurEffectView {
blurEffectView.backgroundColor = UIColor.clear
blurEffectView.frame = onView.bounds
onView.insertSubview(blurEffectView, at: 0)
}
} else {
onView.alpha = 1
if let blurEffectView = _blurEffectView {
blurEffectView.removeFromSuperview()
}
_blurEffectView = nil
}
}
}
47 changes: 8 additions & 39 deletions ContentSheet/Classes/ContentSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public class ContentSheet: UIViewController {
}
}

private var _contentHeader: UIView?
private var _contentHeader: ContentHeaderView?

public var contentHeader: UIView? {
get {
Expand All @@ -260,7 +260,7 @@ public class ContentSheet: UIViewController {
}


private func _defaultHeader() -> UIView {
private func _defaultHeader() -> ContentHeaderView {

var frame = self.view.frame
frame.size.height = 44.0;
Expand All @@ -270,7 +270,7 @@ public class ContentSheet: UIViewController {

_navigationBar = navigationBar

let header = UIView(frame: frame)
let header = ContentHeaderView(frame: frame)
header.tintColor = navigationBar.tintColor
header.backgroundColor = UIColor(white: 1.0, alpha: 0.7)

Expand All @@ -281,30 +281,9 @@ public class ContentSheet: UIViewController {

header.addSubview(navigationBar)

_setBlurrEffect(true, on: header)

return header
}

fileprivate var _blurEffectView: UIVisualEffectView?
private func _setBlurrEffect(_ add: Bool, on view: UIView?) {
if let onView = view ?? self.contentHeader {
if add {
let blurEffect = UIBlurEffect(style: .extraLight)
_blurEffectView = UIVisualEffectView(effect: blurEffect)
if let blurEffectView = _blurEffectView {
blurEffectView.frame = onView.bounds
onView.insertSubview(blurEffectView, at: 0)
}
} else {
onView.alpha = 1
if let blurEffectView = _blurEffectView {
blurEffectView.removeFromSuperview()
}
_blurEffectView = nil
}
}
}

//Gesture
fileprivate lazy var _panGesture: UIPanGestureRecognizer = {
Expand Down Expand Up @@ -594,7 +573,7 @@ public class ContentSheet: UIViewController {
self._oldCollapsedHeight = self.collapsedHeight
self._oldExpandedHeight = self.expandedHeight

let maxHeight = maxExpandableHeight();
let maxHeight = expandedHeight;

resetContentSheetHeight(collapsedHeight: min(maxHeight, self._oldCollapsedHeight + keyboardHeight), expandedHeight: min(maxHeight, self._oldExpandedHeight + keyboardHeight))
}
Expand Down Expand Up @@ -656,7 +635,7 @@ public class ContentSheet: UIViewController {
keyboardHeight = self._keyboardFrame?.height ?? keyboardHeight
}

let maxHeight = maxExpandableHeight();
let maxHeight = expandedHeight;

resetContentSheetHeight(collapsedHeight: min(maxHeight, self.collapsedHeight + keyboardHeight), expandedHeight: min(maxHeight, self.expandedHeight + keyboardHeight))
}
Expand Down Expand Up @@ -793,7 +772,7 @@ extension ContentSheet {
strong._scrollviewToObserve?.isScrollEnabled = true
break;
case .collapsed:
strong._scrollviewToObserve?.isScrollEnabled = strong.collapsedHeight < strong.maxExpandableHeight() ? false : true
strong._scrollviewToObserve?.isScrollEnabled = strong.collapsedHeight < strong.expandedHeight ? false : true
strong._layoutContentSubviews()
break;
// case .minimised:
Expand Down Expand Up @@ -839,8 +818,7 @@ extension ContentSheet {
contentView.frame = subviewFrame
}

if let navigationBar = self.contentNavigationBar, let blurView = self._blurEffectView {
blurView.frame = header.bounds
if let navigationBar = self.contentNavigationBar {
navigationBar.frame = CGRect(x: navigationBar.frame.origin.x,
y: header.bounds.height - navigationBar.frame.height,
width: navigationBar.frame.width,
Expand Down Expand Up @@ -952,7 +930,7 @@ extension ContentSheet: UIGestureRecognizerDelegate {

if (collapsedHeight <= expandedHeight)
&&
(((_state == .expanded) && (scrollView.contentOffset.y + scrollView.contentInset.top == 0) && (direction == .down)) || (_state == .collapsed && collapsedHeight < self.maxExpandableHeight())) {
(((scrollView.contentOffset.y + scrollView.contentInset.top == 0) && (direction == .down)) || (_state == .collapsed && collapsedHeight < expandedHeight)) {
scrollView.isScrollEnabled = false
} else {
scrollView.isScrollEnabled = true
Expand Down Expand Up @@ -1113,15 +1091,6 @@ extension UIView: ContentSheetContentProtocol {
}
}

extension ContentSheet {

func maxExpandableHeight() -> CGFloat {
return view.frame.size.height
}

}


extension UIView {
public var firstResponder: UIView? {
guard !isFirstResponder else { return self }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
20 changes: 11 additions & 9 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f4b93f0

Please sign in to comment.