Skip to content

Update ContainerController.swift #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions Sources/ContainerController/ContainerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ open class ContainerController: NSObject {

// MARK: - Positions Move

private var positionTop: CGFloat {
public var positionTop: CGFloat {
var top = layout.positions.top
if !isPortrait {
if let landscape = layout.landscapePositions {
Expand All @@ -127,8 +127,18 @@ open class ContainerController: NSObject {
}
return deviceHeight - middle
}

public var positionCustom: CGFloat {
var custom = layout.positions.custom ?? layout.positions.bottom
if !isPortrait {
if let landscape = layout.landscapePositions {
custom = landscape.custom ?? 0.0
}
}
return deviceHeight - custom
}

private var positionBottom: CGFloat {
public var positionBottom: CGFloat {
var bottom = layout.positions.bottom
if !isPortrait {
if let landscape = layout.landscapePositions {
Expand Down Expand Up @@ -178,7 +188,7 @@ open class ContainerController: NSObject {
self.controller = controller
set(layout: layout)

NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil)
// NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil)

createShadowButton()
createContainerView()
Expand Down Expand Up @@ -448,9 +458,29 @@ open class ContainerController: NSObject {
}

view.contentView?.addSubview(scrollView)
// scrollView.translatesAutoresizingMaskIntoConstraints = false
// scrollView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
// scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
// scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
// scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
calculationViews()

self.addRecognizerToScrollView(scrollView: scrollView)
}

func addRecognizerToScrollView(scrollView: UIScrollView) {
if let panGesture = panGesture {
print("didScroll addRecognizer")
scrollView.addGestureRecognizer(panGesture)
}
}

func removeRecognizerToScrollView(scrollView: UIScrollView) {
if let panGesture = panGesture {
print("didScroll removeRecognizer")
scrollView.removeGestureRecognizer(panGesture)
}
}
// MARK: - Pan Gesture

@objc private func handlePan(_ gesture: UIPanGestureRecognizer) {
Expand Down Expand Up @@ -496,6 +526,14 @@ open class ContainerController: NSObject {

move(type: type, animation: true, velocity: velocityY, from: .pan)

if type == .top && scrollView?.contentSize.height ?? 0.0 > (UIScreen.main.bounds.height * 0.95) {

if let scrollView = self.scrollView {
self.removeRecognizerToScrollView(scrollView: scrollView)

}
}

default: break
}
}
Expand Down Expand Up @@ -756,7 +794,7 @@ open class ContainerController: NSObject {
else { return positionMiddle }
case .bottom: return positionBottom
case .hide: return deviceHeight
case .custom: return 0.0
case .custom: return positionCustom
}
}

Expand Down Expand Up @@ -1266,6 +1304,10 @@ extension ContainerController: UIScrollViewDelegate {
let from: ContainerFromType = .scrollBorder
let animation = false

print("didScroll a \(position) \(type)")

self.addRecognizerToScrollView(scrollView: scrollView)

shadowLevelAlpha(position: position, animation: false)
changeFooterView(position: position)
calculationScrollViewHeight(from: from)
Expand Down Expand Up @@ -1301,12 +1343,16 @@ extension ContainerController: UIScrollViewDelegate {
let from: ContainerFromType = .scroll
let animation = false

print("didScroll b \(position) \(type)")

changeView(transform: scrollTransform)
shadowLevelAlpha(position: position, animation: false)
changeFooterView(position: position)
calculationScrollViewHeight(from: from)
changeMove(position: position, type: type, animation: animation)
}
} else {
print("didScroll false")
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/ContainerController/ContainerControllerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public protocol ContainerControllerDelegate {
/// Reports the changes current position of the container, after its use
func containerControllerMove(_ containerController: ContainerController, position: CGFloat, type: ContainerMoveType, animation: Bool)

func hideMenu(position: Double)

}

@available(iOS 13.0, *)
Expand All @@ -33,6 +35,9 @@ public extension ContainerControllerDelegate {
}

func containerControllerMove(_ containerController: ContainerController, position: CGFloat, type: ContainerMoveType, animation: Bool) {

hideMenu(position: position)

}
}

20 changes: 1 addition & 19 deletions Sources/ContainerController/ContainerDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,7 @@ open class ContainerDevice {
// MARK: - Orientation

class public var isPortrait: Bool {

var portrait: Bool = false

let size: CGSize = UIScreen.main.bounds.size
if size.width / size.height > 1 {
portrait = false
} else {
portrait = true
}

switch UIDevice.current.orientation {
case .landscapeLeft, .landscapeRight:
portrait = false
case .portrait:
portrait = true
default: break
}

return portrait
return true
}

class var statusBarOrientation: UIInterfaceOrientation? {
Expand Down
5 changes: 4 additions & 1 deletion Sources/ContainerController/ContainerLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ open class ContainerPosition {

static let zero = ContainerPosition(top: 0, bottom: 0)

public init(top: CGFloat, middle: CGFloat? = nil, bottom: CGFloat) {
public var custom: CGFloat?

public init(top: CGFloat, middle: CGFloat? = nil, bottom: CGFloat, custom: CGFloat? = nil) {
self.top = top
self.middle = middle
self.bottom = bottom
self.custom = custom
}
}

Expand Down