Skip to content

Commit a0bd79c

Browse files
authored
feat: 알림 모달에 actionSheet 스타일 구현, stretchyDragging 옵션 구현 (#65)
* feat: 알림 모달에 actionSheet 스타일 구현 * feat: StretchyDragging 옵션 코드 구현 * feat: TestCode 추가 작성
1 parent 1be4d08 commit a0bd79c

File tree

10 files changed

+202
-54
lines changed

10 files changed

+202
-54
lines changed

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/TSAlertController.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@
545545
MODULE_NAME = ExampleApp;
546546
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
547547
PRODUCT_NAME = "$(TARGET_NAME)";
548+
SWIFT_STRICT_CONCURRENCY = minimal;
548549
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
549550
SWIFT_VERSION = 5.0;
550551
};
@@ -568,6 +569,7 @@
568569
MODULE_NAME = ExampleApp;
569570
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
570571
PRODUCT_NAME = "$(TARGET_NAME)";
572+
SWIFT_STRICT_CONCURRENCY = minimal;
571573
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
572574
SWIFT_VERSION = 5.0;
573575
};

Example/TSAlertController/Presentation/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class ViewController: UIViewController {
9393
@IBAction func showActionSheetWithVariousAppearance(_ sender: Any) {
9494

9595
let actionSheet = TSAlertController(title: "What kind of inquiry do you have?",
96-
options: [.interactiveScaleAndDrag],
97-
preferredStyle: .floatingSheet)
96+
options: [.stretchyDragging, .dismissOnSwipeDown],
97+
preferredStyle: .actionSheet)
9898
actionSheet.viewConfiguration.margin = .init(buttonLeft: 5, buttonRight: 5)
9999

100100
let config = TSButton.Configuration(imageSpacing: 15,

Example/Tests/TSAlertControllerTests.swift

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,29 @@ final class TSAlertControllerTests: XCTestCase {
9494
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
9595
}
9696

97-
func testTSAlertController_WhenInitalizedWithFourButtonsAndAutomaticAxis_ShouldSetCorrectActionsOrderAndCount() {
97+
98+
func testTSAlertController_WhenIntlaizedWithAlertStyle_ShouldSetDefaultConfiguration() {
9899
// given
99100
let alertController = TSAlertController(
100101
title: "The title of the alert",
101102
preferredStyle: .alert
102103
)
103104
let mockViewController = MockViewController()
104105

105-
alertController.addAction(.init(title: "Cancel", style: .cancel))
106+
// when
107+
mockViewController.present(alertController, animated: true)
108+
109+
// then
110+
let config = alertController.configuration
111+
XCTAssertEqual(config.enteringTransition, .fadeInAndScaleDown)
112+
XCTAssertEqual(config.exitingTransition, .fadeOut)
113+
XCTAssertEqual(config.headerAnimation, .none)
114+
XCTAssertEqual(config.buttonGroupAnimation, .none)
115+
XCTAssertEqual(config.prefersGrabberVisible, false)
116+
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
106117
}
107118

108-
109-
func testTSAlertController_WhenIntlaizedWithAlertStyle_ShouldSetDefaultConfiguration() {
119+
func testTSAlertController_WhenIntializedWithAlertStyle_ShouldSetDefaultViewConfiguration() {
110120
// given
111121
let alertController = TSAlertController(
112122
title: "The title of the alert",
@@ -118,16 +128,13 @@ final class TSAlertControllerTests: XCTestCase {
118128
mockViewController.present(alertController, animated: true)
119129

120130
// then
121-
let config = alertController.configuration
122-
XCTAssertEqual(config.enteringTransition, .fadeInAndScaleDown)
123-
XCTAssertEqual(config.exitingTransition, .fadeOut)
124-
XCTAssertEqual(config.headerAnimation, .none)
125-
XCTAssertEqual(config.buttonGroupAnimation, .none)
126-
XCTAssertEqual(config.prefersGrabberVisible, false)
131+
let viewConfig = alertController.viewConfiguration
132+
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 0.75, maximumRatio: 0.75))
133+
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 100)
127134
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
128135
}
129136

130-
func testTSAlertController_WhenIntializedWithAlertStyle_SouldSetEnforceCorrectConfiguration() {
137+
func testTSAlertController_WhenIntializedWithAlertStyle_SouldSetCorrectConfigurationForcibly() {
131138
// given
132139
let alertController = TSAlertController(
133140
title: "The title of the alert",
@@ -166,7 +173,7 @@ final class TSAlertControllerTests: XCTestCase {
166173
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
167174
}
168175

169-
func testTSAlertController_WhenIntilizedWithFloatinSheetStyle_ShouldSetEnforceCorrectConfiguration() {
176+
func testTSAlertController_WhenInitializedWithFloatingSheetStyle_ShouldSetDefaultViewConfiguration() {
170177
// given
171178
let alertController = TSAlertController(
172179
title: "The title of the alert",
@@ -178,15 +185,57 @@ final class TSAlertControllerTests: XCTestCase {
178185
mockViewController.present(alertController, animated: true)
179186

180187
// then
181-
XCTAssertTrue(true)
188+
let viewConfig = alertController.viewConfiguration
189+
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 0.95, maximumRatio: 0.95))
190+
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 20)
182191
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
183192
}
184193

185-
func testTSAlertController_WhenIntializedWithAlertStyle_ShouldSetDefaultViewConfiguration() {
194+
func testTSAlertController_WhenIntilizedWithFloatingSheetStyle_ShouldSetCorrectConfigurationForcibly() {
186195
// given
187196
let alertController = TSAlertController(
188197
title: "The title of the alert",
189-
preferredStyle: .alert
198+
preferredStyle: .floatingSheet
199+
)
200+
let mockViewController = MockViewController()
201+
202+
// when
203+
mockViewController.present(alertController, animated: true)
204+
205+
// then
206+
let config = alertController.configuration
207+
XCTAssertFalse(alertController.options.contains(.stretchyDragging))
208+
XCTAssertEqual(config.prefersGrabberVisible, true)
209+
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
210+
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
211+
}
212+
213+
func testTSAlertController_WhenIntializedWithActionSheetStyle_ShouldSetDefaultCconfiguration() {
214+
// given
215+
let alertController = TSAlertController(
216+
title: "The title of the alert",
217+
preferredStyle: .actionSheet
218+
)
219+
let mockViewController = MockViewController()
220+
221+
// when
222+
mockViewController.present(alertController, animated: true)
223+
224+
// then
225+
let config = alertController.configuration
226+
XCTAssertEqual(config.enteringTransition, .slideUp)
227+
XCTAssertEqual(config.exitingTransition, .slideDown)
228+
XCTAssertEqual(config.headerAnimation, .none)
229+
XCTAssertEqual(config.buttonGroupAnimation, .none)
230+
XCTAssertEqual(config.prefersGrabberVisible, true)
231+
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
232+
}
233+
234+
func testTSAlertController_WhenIntializedWithActionSheetStyle_ShouldSetDefaultViewConfiguration() {
235+
// given
236+
let alertController = TSAlertController(
237+
title: "The title of the alert",
238+
preferredStyle: .actionSheet
190239
)
191240
let mockViewController = MockViewController()
192241

@@ -195,12 +244,12 @@ final class TSAlertControllerTests: XCTestCase {
195244

196245
// then
197246
let viewConfig = alertController.viewConfiguration
198-
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 0.75, maximumRatio: 0.75))
199-
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 100)
247+
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 1.0, maximumRatio: 1.0))
248+
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 0.0)
200249
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
201250
}
202251

203-
func testTSAlertController_WhenInitializedWithFloatingSheetStyle_ShouldSetDefaultViewConfiguration() {
252+
func testTSAlertController_WhenIntializedWithActionSheetStyle_ShouldSetCorrectConfigurationForcibly() {
204253
// given
205254
let alertController = TSAlertController(
206255
title: "The title of the alert",
@@ -212,9 +261,10 @@ final class TSAlertControllerTests: XCTestCase {
212261
mockViewController.present(alertController, animated: true)
213262

214263
// then
215-
let viewConfig = alertController.viewConfiguration
216-
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 0.95, maximumRatio: 0.95))
217-
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 20)
264+
let config = alertController.configuration
265+
XCTAssertFalse(alertController.options.contains(.interactiveScaleAndDrag))
266+
XCTAssertEqual(config.prefersGrabberVisible, true)
267+
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
218268
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
219269
}
220270

Sources/PresentationController/TSAlertPresentationController.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ final class TSAlertPresentationController: UIPresentationController {
9696
case .alert:
9797
presentedView.center(in: containerView)
9898

99+
case .actionSheet:
100+
presentedView.centerX(in: containerView)
101+
presentedView.anchor(bottom: containerView.bottomAnchor, bottomInset: 0)
102+
99103
case .floatingSheet:
100104
presentedView.centerX(in: containerView)
101105
presentedView.anchor(bottom: containerView.safeAreaLayoutGuide.bottomAnchor, bottomInset: 10)

Sources/TSAlert/TSAlertController+Options.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ import UIKit
2424

2525
public extension TSAlertController {
2626

27-
///
2827
struct Options: OptionSet {
2928

30-
/// Adds an interactive scaling and dragging effect to the alert
29+
/// Adds an interactive scaling and dragging effect to the alert. Cannot be applied to `actionSheet`.
3130
public static let interactiveScaleAndDrag = Options(rawValue: 1 << 0)
32-
31+
3332
/// Dismisses the action sheet when dragged downward beyond a certain threshold.
3433
public static let dismissOnSwipeDown = Options(rawValue: 1 << 1)
35-
34+
3635
/// Dismisses the alert by tapping the outside area.
3736
public static let dismissOnTapOutside = Options(rawValue: 1 << 2)
38-
37+
3938
/// Dismisses the alert by tapping the inside area.
4039
public static let dismissOnTapInside = Options(rawValue: 1 << 3)
40+
41+
/// Applies a stretching effect to the alert when dragged. Can only be applied to `actionSheet`.
42+
public static let stretchyDragging = Options(rawValue: 1 << 4)
4143

4244
public var rawValue: Int
4345
public init(rawValue: Int) {

Sources/TSAlert/TSAlertController+Style.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public extension TSAlertController {
3030
case alert
3131

3232
/// An action sheet displayed by the view controller that presented it.
33-
// case actionSheet
33+
case actionSheet
3434

3535
/// An floating sheet displayed by the view controller that presented it.
3636
case floatingSheet

0 commit comments

Comments
 (0)