Skip to content
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

Bottom sheet layout improvements #111

Merged
merged 1 commit into from
Oct 5, 2023
Merged
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
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