Skip to content

Commit 997a594

Browse files
authored
[Issue-30] animate new height. (#31)
* update view method added * Animate new height
1 parent 2b0f317 commit 997a594

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

Sources/YBottomSheet/Animation/BottomSheetDismissAnimator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class BottomSheetDismissAnimator: BottomSheetAnimator {
3838
sheet.dimmerView.alpha = 0
3939
}
4040

41-
UIView.animate(with: sheet.appearance.dismissAnimation) {
41+
UIView.animate(
42+
with: sheet.appearance.dismissAnimation
43+
) {
4244
if self.isReduceMotionEnabled {
4345
sheet.sheetView.alpha = 0
4446
} else {

Sources/YBottomSheet/Animation/BottomSheetPresentAnimator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class BottomSheetPresentAnimator: BottomSheetAnimator {
5050
sheet.dimmerView.alpha = 1
5151
}
5252

53-
UIView.animate(with: sheet.appearance.presentAnimation) {
53+
UIView.animate(
54+
with: sheet.appearance.presentAnimation
55+
) {
5456
if self.isReduceMotionEnabled {
5557
sheet.sheetView.alpha = 1
5658
} else {

Sources/YBottomSheet/BottomSheetController.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ public class BottomSheetController: UIViewController {
161161
onDismiss()
162162
}
163163
}
164+
165+
/// update views
166+
public func updateViews() {
167+
updateViewAppearance()
168+
}
164169
}
165170

166171
internal extension BottomSheetController {
@@ -252,7 +257,16 @@ private extension BottomSheetController {
252257
let idealHeight = appearance.layout.idealContentHeight ?? childContentSize.height
253258
if idealHeight > 0.0 {
254259
if let idealContentHeightAnchor = idealContentHeightAnchor {
255-
idealContentHeightAnchor.constant = idealHeight
260+
UIView.animate(
261+
withDuration: 0.2,
262+
delay: 0.2,
263+
options: UIView.AnimationOptions.curveEaseIn,
264+
animations: {
265+
idealContentHeightAnchor.constant = idealHeight
266+
self.view.layoutIfNeeded()
267+
},
268+
completion: nil
269+
)
256270
} else {
257271
idealContentHeightAnchor = childView.constrain(
258272
.heightAnchor,

Tests/YBottomSheetTests/BottomSheetControllerTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,17 @@ final class BottomSheetControllerTests: XCTestCase {
370370
XCTAssertTrue(sut.isDismissed)
371371
}
372372

373+
func test_updateView() {
374+
let sut = SpyBottomSheetController(title: "", childView: MiniView(), appearance: .defaultResizable)
375+
sut.view.layoutIfNeeded()
376+
377+
XCTAssertFalse(sut.isViewUpdated)
378+
379+
sut.updateViews()
380+
381+
XCTAssertTrue(sut.isViewUpdated)
382+
}
383+
373384
func test_onSwipeDown() {
374385
let sut = SpyBottomSheetController(title: "", childView: UIView())
375386

@@ -524,6 +535,7 @@ final class SpyBottomSheetController: BottomSheetController {
524535
var onDimmerTapped = false
525536
var onDragging = false
526537
var voiceOverFocusSet = false
538+
var isViewUpdated = false
527539

528540
override func simulateTapCloseButton() {
529541
super.simulateTapCloseButton()
@@ -555,6 +567,11 @@ final class SpyBottomSheetController: BottomSheetController {
555567
super.viewDidAppear(animated)
556568
voiceOverFocusSet = true
557569
}
570+
571+
override func updateViews() {
572+
super.updateViews()
573+
isViewUpdated = true
574+
}
558575

559576
@discardableResult
560577
override func simulateDragging(_ gesture: UIPanGestureRecognizer) -> Bool {

0 commit comments

Comments
 (0)