Skip to content

Commit 3a213b5

Browse files
committed
[CM-1261] Comments addressed.
1 parent b6bf97a commit 3a213b5

File tree

6 files changed

+33
-23
lines changed

6 files changed

+33
-23
lines changed

Sources/YBottomSheet/BottomSheetController+Appearance.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ extension BottomSheetController {
3232
///
3333
/// Only applicable for resizable sheets. `nil` means to use the content view's intrinsic height as the minimum.
3434
public var minimumContentHeight: CGFloat?
35-
/// Whether the sheet is dismissible or not. Default is `true`.
36-
public var allowDismiss: Bool
37-
35+
/// Whether the sheet can be dismissed by swiping down or tapping on the dimmer. Default is `true`.
36+
///
37+
/// The user can always dismiss the sheet from the close button if it is visible.
38+
public var isDismissAllowed: Bool
39+
3840
/// Default appearance (fixed size sheet)
3941
public static let `default` = Appearance()
4042
/// Default appearance for a resizable sheet
@@ -51,7 +53,7 @@ extension BottomSheetController {
5153
/// - presentAnimationCurve: Animaiton during presenting.
5254
/// - dismissAnimationCurve: Animation during dismiss.
5355
/// - minimumContentHeight: Optional) Minimum content view height.
54-
/// - allowDismiss: Whether the sheet is dismissible or not.
56+
/// - isDismissAllowed: Whether the sheet can be dismissed by swiping down or tapping on the dimmer.
5557
public init(
5658
indicatorAppearance: DragIndicatorView.Appearance? = nil,
5759
headerAppearance: SheetHeaderView.Appearance? = .default,
@@ -62,7 +64,7 @@ extension BottomSheetController {
6264
presentAnimationCurve: UIView.AnimationOptions = .curveEaseIn,
6365
dismissAnimationCurve: UIView.AnimationOptions = .curveEaseOut,
6466
minimumContentHeight: CGFloat? = nil,
65-
allowDismiss: Bool = true
67+
isDismissAllowed: Bool = true
6668
) {
6769
self.indicatorAppearance = indicatorAppearance
6870
self.headerAppearance = headerAppearance
@@ -73,7 +75,7 @@ extension BottomSheetController {
7375
self.presentAnimationCurve = presentAnimationCurve
7476
self.dismissAnimationCurve = dismissAnimationCurve
7577
self.minimumContentHeight = minimumContentHeight
76-
self.allowDismiss = allowDismiss
78+
self.isDismissAllowed = isDismissAllowed
7779
}
7880
}
7981
}

Sources/YBottomSheet/BottomSheetController.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ public class BottomSheetController: UIViewController {
150150
return true
151151
}
152152

153-
/// Dismiss bottom sheet.
154-
/// - Parameter isCloseButton: whether close button is tapped or not.
155-
func didDismiss(isCloseButton: Bool = false) {
156-
if appearance.allowDismiss || isCloseButton {
153+
/// Dismisses the bottom sheet if allowed.
154+
///
155+
/// This method is not called when the header's close button is tapped.
156+
func didDismiss() {
157+
if appearance.isDismissAllowed {
157158
onDismiss()
158159
}
159160
}
@@ -316,8 +317,9 @@ private extension BottomSheetController {
316317

317318
extension BottomSheetController: SheetHeaderViewDelegate {
318319
@objc
319-
func didCloseTapped() {
320-
didDismiss(isCloseButton: true)
320+
func didTapCloseButton() {
321+
// Directly dismiss the sheet without considering `isDismissAllowed`.
322+
onDismiss()
321323
}
322324
}
323325

@@ -382,6 +384,6 @@ internal extension BottomSheetController {
382384

383385
@objc
384386
func simulateDismiss() {
385-
didCloseTapped()
387+
didTapCloseButton()
386388
}
387389
}

Sources/YBottomSheet/Protocols/SheetHeaderViewDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
import Foundation
1010

1111
internal protocol SheetHeaderViewDelegate: AnyObject {
12-
func didCloseTapped()
12+
func didTapCloseButton()
1313
}

Sources/YBottomSheet/SheetHeaderView/SheetHeaderView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ open class SheetHeaderView: UIView {
5151
required public init?(coder: NSCoder) { nil }
5252

5353
@objc private func closeButtonAction() {
54-
delegate?.didCloseTapped()
54+
delegate?.didTapCloseButton()
5555
}
5656

5757
// For unit testing

Tests/YBottomSheetTests/BottomSheetControllerTests.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import YMatterType
1313

1414
// OK to have lots of test cases
1515
// swiftlint:disable file_length
16+
// swiftlint:disable type_body_length
1617

1718
final class BottomSheetControllerTests: XCTestCase {
1819
var window: UIWindow!
@@ -288,9 +289,7 @@ final class BottomSheetControllerTests: XCTestCase {
288289
let sut = makeSUT(viewController: UINavigationController(rootViewController: UIViewController()))
289290
XCTAssertFalse(sut.hasHeader)
290291
}
291-
}
292292

293-
extension BottomSheetControllerTests {
294293
func test_onDimmer() {
295294
let sut = SpyBottomSheetController(title: "", childView: UIView())
296295

@@ -327,16 +326,18 @@ extension BottomSheetControllerTests {
327326

328327
func test_forbidDismiss() {
329328
let sut = SpyBottomSheetController(title: "", childView: UIView())
330-
sut.appearance.allowDismiss = false
329+
sut.appearance.isDismissAllowed = false
331330

332331
XCTAssertFalse(sut.onSwipeDown)
333332
XCTAssertFalse(sut.onDimmerTapped)
333+
XCTAssertFalse(sut.isDismissed)
334334

335335
sut.simulateOnDimmerTap()
336336
sut.simulateOnSwipeDown()
337337

338338
XCTAssertFalse(sut.onSwipeDown)
339339
XCTAssertFalse(sut.onDimmerTapped)
340+
XCTAssertFalse(sut.isDismissed)
340341
}
341342
}
342343

@@ -383,24 +384,29 @@ final class SpyBottomSheetController: BottomSheetController {
383384
var onSwipeDown = false
384385
var onDimmerTapped = false
385386
var onDragging = false
387+
388+
override func simulateDismiss() {
389+
super.simulateDismiss()
390+
isDismissed = true
391+
}
386392

387-
override func didDismiss(isCloseButton: Bool) {
393+
override func didDismiss() {
388394
super.didDismiss()
389-
if isCloseButton || appearance.allowDismiss {
395+
if appearance.isDismissAllowed {
390396
isDismissed = true
391397
}
392398
}
393399

394400
override func simulateOnSwipeDown() {
395401
super.simulateOnSwipeDown()
396-
if appearance.allowDismiss {
402+
if appearance.isDismissAllowed {
397403
onSwipeDown = true
398404
}
399405
}
400406

401407
override func simulateOnDimmerTap() {
402408
super.simulateOnDimmerTap()
403-
if appearance.allowDismiss {
409+
if appearance.isDismissAllowed {
404410
onDimmerTapped = true
405411
}
406412
}

Tests/YBottomSheetTests/SheetHeaderView/SheetHeaderViewTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private extension SheetHeaderViewTests {
9191
}
9292

9393
extension SheetHeaderViewTests: SheetHeaderViewDelegate {
94-
func didCloseTapped() {
94+
func didTapCloseButton() {
9595
isDismissed = true
9696
}
9797
}

0 commit comments

Comments
 (0)