Skip to content

Commit

Permalink
[Issue-30] animate new height. (#31)
Browse files Browse the repository at this point in the history
* update view method added

* Animate new height
  • Loading branch information
devyml authored Oct 25, 2023
1 parent 2b0f317 commit 997a594
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 15 additions & 1 deletion Sources/YBottomSheet/BottomSheetController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public class BottomSheetController: UIViewController {
onDismiss()
}
}

/// update views
public func updateViews() {
updateViewAppearance()
}
}

internal extension BottomSheetController {
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions Tests/YBottomSheetTests/BottomSheetControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 997a594

Please sign in to comment.