diff --git a/Sources/YBottomSheet/Animation/BottomSheetDismissAnimator.swift b/Sources/YBottomSheet/Animation/BottomSheetDismissAnimator.swift index 48e97f1..0cd7ed5 100644 --- a/Sources/YBottomSheet/Animation/BottomSheetDismissAnimator.swift +++ b/Sources/YBottomSheet/Animation/BottomSheetDismissAnimator.swift @@ -38,7 +38,9 @@ class BottomSheetDismissAnimator: BottomSheetAnimator { sheet.dimmerView.alpha = 0 } - UIView.animate(with: sheet.appearance.dismissAnimation) { + UIView.animate( + with: sheet.appearance.dismissAnimation + ) { if self.isReduceMotionEnabled { sheet.sheetView.alpha = 0 } else { diff --git a/Sources/YBottomSheet/Animation/BottomSheetPresentAnimator.swift b/Sources/YBottomSheet/Animation/BottomSheetPresentAnimator.swift index 17276dd..d971d7b 100644 --- a/Sources/YBottomSheet/Animation/BottomSheetPresentAnimator.swift +++ b/Sources/YBottomSheet/Animation/BottomSheetPresentAnimator.swift @@ -50,7 +50,9 @@ class BottomSheetPresentAnimator: BottomSheetAnimator { sheet.dimmerView.alpha = 1 } - UIView.animate(with: sheet.appearance.presentAnimation) { + UIView.animate( + with: sheet.appearance.presentAnimation + ) { if self.isReduceMotionEnabled { sheet.sheetView.alpha = 1 } else { diff --git a/Sources/YBottomSheet/BottomSheetController.swift b/Sources/YBottomSheet/BottomSheetController.swift index 0a72084..b944754 100644 --- a/Sources/YBottomSheet/BottomSheetController.swift +++ b/Sources/YBottomSheet/BottomSheetController.swift @@ -161,6 +161,11 @@ public class BottomSheetController: UIViewController { onDismiss() } } + + /// update views + public func updateViews() { + updateViewAppearance() + } } internal extension BottomSheetController { @@ -252,7 +257,16 @@ private extension BottomSheetController { let idealHeight = appearance.layout.idealContentHeight ?? childContentSize.height if idealHeight > 0.0 { if let idealContentHeightAnchor = idealContentHeightAnchor { - idealContentHeightAnchor.constant = idealHeight + UIView.animate( + withDuration: 0.2, + delay: 0.2, + options: UIView.AnimationOptions.curveEaseIn, + animations: { + idealContentHeightAnchor.constant = idealHeight + self.view.layoutIfNeeded() + }, + completion: nil + ) } else { idealContentHeightAnchor = childView.constrain( .heightAnchor, diff --git a/Tests/YBottomSheetTests/BottomSheetControllerTests.swift b/Tests/YBottomSheetTests/BottomSheetControllerTests.swift index 5cfb138..a9823c8 100644 --- a/Tests/YBottomSheetTests/BottomSheetControllerTests.swift +++ b/Tests/YBottomSheetTests/BottomSheetControllerTests.swift @@ -370,6 +370,17 @@ final class BottomSheetControllerTests: XCTestCase { XCTAssertTrue(sut.isDismissed) } + func test_updateView() { + let sut = SpyBottomSheetController(title: "", childView: MiniView(), appearance: .defaultResizable) + sut.view.layoutIfNeeded() + + XCTAssertFalse(sut.isViewUpdated) + + sut.updateViews() + + XCTAssertTrue(sut.isViewUpdated) + } + func test_onSwipeDown() { let sut = SpyBottomSheetController(title: "", childView: UIView()) @@ -524,6 +535,7 @@ final class SpyBottomSheetController: BottomSheetController { var onDimmerTapped = false var onDragging = false var voiceOverFocusSet = false + var isViewUpdated = false override func simulateTapCloseButton() { super.simulateTapCloseButton() @@ -555,6 +567,11 @@ final class SpyBottomSheetController: BottomSheetController { super.viewDidAppear(animated) voiceOverFocusSet = true } + + override func updateViews() { + super.updateViews() + isViewUpdated = true + } @discardableResult override func simulateDragging(_ gesture: UIPanGestureRecognizer) -> Bool {