Skip to content

Commit

Permalink
Bottom sheet layout improvements (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
almazrafi authored Oct 5, 2023
1 parent 3ed118d commit cbe2a60
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
16 changes: 12 additions & 4 deletions Sources/Addons/BottomSheet/BottomSheetStackController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ open class BottomSheetStackController: UINavigationController {
.preferredContentSize
.width + additionalSafeAreaInsets.horizontal

guard preferredContentWidth != .zero else {
return
}

let preferredContentHeight = topViewController
.preferredContentSize
.height + additionalSafeAreaInsets.vertical

guard preferredContentHeight != .zero else {
return
}

let preferredContentSize = CGSize(
width: preferredContentWidth,
height: preferredContentHeight
Expand Down Expand Up @@ -76,11 +84,11 @@ open class BottomSheetStackController: UINavigationController {
}

open override func preferredContentSizeDidChange(forChildContentContainer container: UIContentContainer) {
super.preferredContentSizeDidChange(forChildContentContainer: container)

if !isUpdatingStack {
updatePreferredContentSizeIfNeeded()
guard !isUpdatingStack else {
return
}

updatePreferredContentSizeIfNeeded()
}
}
#endif
34 changes: 31 additions & 3 deletions Sources/Addons/BottomSheet/BottomSheetTransitionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ internal final class BottomSheetTransitionView: UIView {
}

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

guard containerView.frame != frame else {
return
}

containerView.frame = bounds.inset(by: contentInsets)
}

Expand All @@ -127,6 +133,10 @@ internal final class BottomSheetTransitionView: UIView {
height: containerView.bounds.height - topInset
)

guard cardShadowView.frame != frame else {
return
}

cardShadowView.frame = frame

let cornerRadius = card?.cornerRadius ?? .zero
Expand All @@ -143,22 +153,35 @@ internal final class BottomSheetTransitionView: UIView {
}

private func layoutCardView() {
cardView.frame = cardShadowView.frame
guard cardView.frame != cardShadowView.frame else {
return
}

cardView.frame = cardShadowView.frame
cardView.layer.maskedCorners = resolveCardMaskedCorners()
}

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

guard cardContentView.frame != frame else {
return
}

cardContentView.frame = frame
}

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

guard contentView.frame != cardContentView.bounds else {
return
}

contentView.frame = cardContentView.bounds
}

Expand All @@ -170,13 +193,18 @@ internal final class BottomSheetTransitionView: UIView {
let size = grabber.size
let inset = grabber.inset

grabberView.frame = CGRect(
let frame = CGRect(
x: containerView.bounds.midX - size.width * 0.5,
y: cardView.frame.minY + inset,
width: size.width,
height: size.height
)

guard grabberView.frame != frame else {
return
}

grabberView.frame = frame
grabberView.layer.cornerRadius = 0.5 * min(size.width, size.height)
}

Expand Down

0 comments on commit cbe2a60

Please sign in to comment.