From 1165c93d09ca543cbf3165393a9c50300d05293e Mon Sep 17 00:00:00 2001 From: Almaz Ibragimov Date: Wed, 4 Oct 2023 16:25:42 +0300 Subject: [PATCH] Bottom sheet layout improvements --- .../BottomSheetStackController.swift | 16 ++++++--- .../BottomSheetTransitionView.swift | 34 +++++++++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Sources/Addons/BottomSheet/BottomSheetStackController.swift b/Sources/Addons/BottomSheet/BottomSheetStackController.swift index c5a8deda..7c7b1ee8 100644 --- a/Sources/Addons/BottomSheet/BottomSheetStackController.swift +++ b/Sources/Addons/BottomSheet/BottomSheetStackController.swift @@ -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 @@ -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 diff --git a/Sources/Addons/BottomSheet/BottomSheetTransitionView.swift b/Sources/Addons/BottomSheet/BottomSheetTransitionView.swift index 36222282..ce5da625 100644 --- a/Sources/Addons/BottomSheet/BottomSheetTransitionView.swift +++ b/Sources/Addons/BottomSheet/BottomSheetTransitionView.swift @@ -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) } @@ -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 @@ -143,15 +153,24 @@ 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() { @@ -159,6 +178,10 @@ internal final class BottomSheetTransitionView: UIView { return } + guard contentView.frame != cardContentView.bounds else { + return + } + contentView.frame = cardContentView.bounds } @@ -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) }