Skip to content

Commit

Permalink
Access control improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
PimCoumans committed Aug 19, 2022
1 parent a3b963b commit 3f46120
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
48 changes: 25 additions & 23 deletions Sources/PanelPresenter/PanelPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PanelPresenter: NSObject {
}

/// Default scrollView used to display contents
private(set) lazy var panelScrollView: PanelScrollView = {
public private(set) lazy var panelScrollView: PanelScrollView = {
let scrollView = PanelScrollView()
scrollView.alwaysBounceVertical = true
scrollView.canCancelContentTouches = true
Expand All @@ -52,7 +52,30 @@ public class PanelPresenter: NSObject {
return scrollView
}()

/// Immediatley updates panel height when content has changed. When `animated` is set to `true`, this just wraps ``layoutIfNeeded()`` in a spring-based animation.
/// View to disply shadow right below headerContentView
private(set) lazy var headerShadowView: UIView = {
let view = PanelHeaderShadowView()
view.isUserInteractionEnabled = false
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .black.withAlphaComponent(headerShadowOpactity)
view.alpha = 0
return view
}()

/// View used behind content and header
private(set) lazy var backgroundView: UIView = {
let view = PanelBackgroundView(effect: backgroundViewEffect)

let cornerRadius = headerViewHeight / 2
view.layer.cornerRadius = cornerRadius
view.layer.cornerCurve = .continuous
view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
view.layer.masksToBounds = true
view.contentMode = .redraw
return view
}()

/// Immediately updates panel height when content has changed. When `animated` is set to `true`, this just wraps ``layoutIfNeeded()`` in a spring-based animation.
/// - Parameter animated: Wether the height change should be animated
public func updatePanelHeight(animated: Bool = true) {
if animated {
Expand Down Expand Up @@ -154,27 +177,6 @@ public class PanelPresenter: NSObject {
view.directionalLayoutMargins.trailing = headerViewHeight * 0.4
return view
}()

private(set) lazy var headerShadowView: UIView = {
let view = PanelHeaderShadowView()
view.isUserInteractionEnabled = false
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .black.withAlphaComponent(headerShadowOpactity)
view.alpha = 0
return view
}()

private(set) lazy var backgroundView: UIView = {
let view = PanelBackgroundView(effect: backgroundViewEffect)

let cornerRadius = headerViewHeight / 2
view.layer.cornerRadius = cornerRadius
view.layer.cornerCurve = .continuous
view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
view.layer.masksToBounds = true
view.contentMode = .redraw
return view
}()
}

// MARK: Custom class names (mostly for view inspection)
Expand Down
6 changes: 3 additions & 3 deletions Sources/PanelPresenter/ScrollView/PanelScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import UIKit
/// Custom scrollView that can forces touch cancellation, even in `UIControl`s
/// Also available from my [TouchCancellingScrollView.swift gist](https://gist.github.com/PimCoumans/6e82ca50a27df1d768b40fd9a73940fb).
/// - Note: Make sure to set `canCancelContentTouches` to `true`
class PanelScrollView: UIScrollView {
public class PanelScrollView: UIScrollView {

/// Set to `false` to allow drags in`UIControls`
var canCancelControlContentTouches: Bool = true
public var canCancelControlContentTouches: Bool = true

/// Cancels all touches, even when touch is in a `UIControl`.
/// Set `alwaysCancelsContentTouches` to `false` to not use this behaviour
override func touchesShouldCancel(in view: UIView) -> Bool {
public override func touchesShouldCancel(in view: UIView) -> Bool {
if canCancelContentTouches && canCancelControlContentTouches && view is UIControl {
return true
}
Expand Down

0 comments on commit 3f46120

Please sign in to comment.