Skip to content

Commit

Permalink
Bottom sheets fixes (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
almazrafi authored Aug 30, 2023
1 parent 28f419c commit 3ed118d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 60 deletions.
125 changes: 67 additions & 58 deletions Sources/Addons/BottomSheet/BottomSheetTransitionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ internal final class BottomSheetTransitionView: UIView {
private let containerView = UIView()
private let cardShadowView = UIView()
private let cardView = UIView()
private let cardContentView = UIView()
private let grabberView = UIView()

internal private(set) weak var contentView: UIView?
Expand Down Expand Up @@ -45,6 +46,7 @@ internal final class BottomSheetTransitionView: UIView {
setupContainerView()
setupCardShadowView()
setupCardView()
setupCardContentView()
setupContentView()
setupGrabberView()
}
Expand All @@ -65,24 +67,52 @@ internal final class BottomSheetTransitionView: UIView {
]
}

private func layoutContainerView() {
containerView.frame = bounds.inset(by: contentInsets)
}

private func setupContainerView() {
addSubview(containerView)

containerView.clipsToBounds = false
}

private func updateCardShadowView() {
let shadow = card?.shadow ?? .default
private func setupCardShadowView() {
containerView.addSubview(cardShadowView)

cardShadowView.layer.shadowOffset = shadow.offset
cardShadowView.layer.shadowRadius = shadow.radius
cardShadowView.layer.shadowColor = shadow.color?.cgColor
cardShadowView.layer.shadowOpacity = shadow.opacity
cardShadowView.layer.shouldRasterize = shadow.shouldRasterize
cardShadowView.isUserInteractionEnabled = false
cardShadowView.clipsToBounds = false

updateCardShadowView()
}

private func setupCardView() {
containerView.addSubview(cardView)

cardView.clipsToBounds = true

updateCardView()
}

private func setupCardContentView() {
cardView.addSubview(cardContentView)
}

private func setupContentView() {
guard let contentView else {
return
}

cardContentView.addSubview(contentView)
}

private func setupGrabberView() {
containerView.addSubview(grabberView)

grabberView.isUserInteractionEnabled = false
grabberView.clipsToBounds = true

updateGrabberView()
}

private func layoutContainerView() {
containerView.frame = bounds.inset(by: contentInsets)
}

private func layoutCardShadowView() {
Expand Down Expand Up @@ -112,62 +142,24 @@ internal final class BottomSheetTransitionView: UIView {
).cgPath
}

private func setupCardShadowView() {
containerView.addSubview(cardShadowView)

cardShadowView.isUserInteractionEnabled = false
cardShadowView.clipsToBounds = false

updateCardShadowView()
}

private func updateCardView() {
cardView.backgroundColor = card?.backgroundColor
cardView.layer.cornerRadius = card?.cornerRadius ?? .zero

let border = card?.border ?? .default

cardView.layer.borderWidth = border.width
cardView.layer.borderColor = border.color?.cgColor
}

private func layoutCardView() {
cardView.frame = cardShadowView.frame

cardView.layer.maskedCorners = resolveCardMaskedCorners()
}

private func setupCardView() {
containerView.addSubview(cardView)

cardView.clipsToBounds = true

updateCardView()
}

private func layoutContentView() {
guard let contentView else {
return
}

contentView.frame = cardView
private func layoutCardContentView() {
cardContentView.frame = cardView
.bounds
.inset(by: card?.contentInsets ?? .zero)

contentView.layoutIfNeeded()
}

private func setupContentView() {
private func layoutContentView() {
guard let contentView else {
return
}

cardView.addSubview(contentView)
}

private func updateGrabberView() {
grabberView.alpha = grabber == nil ? .zero : 1.0
grabberView.backgroundColor = grabber?.color
contentView.frame = cardContentView.bounds
}

private func layoutGrabberView() {
Expand All @@ -188,13 +180,29 @@ internal final class BottomSheetTransitionView: UIView {
grabberView.layer.cornerRadius = 0.5 * min(size.width, size.height)
}

private func setupGrabberView() {
containerView.addSubview(grabberView)
private func updateCardShadowView() {
let shadow = card?.shadow ?? .default

grabberView.isUserInteractionEnabled = false
grabberView.clipsToBounds = true
cardShadowView.layer.shadowOffset = shadow.offset
cardShadowView.layer.shadowRadius = shadow.radius
cardShadowView.layer.shadowColor = shadow.color?.cgColor
cardShadowView.layer.shadowOpacity = shadow.opacity
cardShadowView.layer.shouldRasterize = shadow.shouldRasterize
}

updateGrabberView()
private func updateCardView() {
cardView.backgroundColor = card?.backgroundColor
cardView.layer.cornerRadius = card?.cornerRadius ?? .zero

let border = card?.border ?? .default

cardView.layer.borderWidth = border.width
cardView.layer.borderColor = border.color?.cgColor
}

private func updateGrabberView() {
grabberView.alpha = grabber == nil ? .zero : 1.0
grabberView.backgroundColor = grabber?.color
}

internal override func layoutSubviews() {
Expand All @@ -203,6 +211,7 @@ internal final class BottomSheetTransitionView: UIView {
layoutContainerView()
layoutCardShadowView()
layoutCardView()
layoutCardContentView()
layoutContentView()
layoutGrabberView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal final class BottomSheetPresentationController: UIPresentationController
}

internal override var shouldPresentInFullscreen: Bool {
false
true
}

internal override init(
Expand Down Expand Up @@ -208,7 +208,10 @@ internal final class BottomSheetPresentationController: UIPresentationController

private func resolveDimmingViewRatio() -> CGFloat {
let invisibleHeight = min(transitionView?.contentInsets.bottom ?? .zero, .zero)
let visibleHeight = contentView.frame.height + invisibleHeight

let visibleHeight = contentView.frame.height
- contentView.safeAreaInsets.bottom
+ invisibleHeight

let largestUndimmedHeight = preferredDimming
.largestUndimmedDetentKey
Expand Down

0 comments on commit 3ed118d

Please sign in to comment.