Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Example/TSAlertController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_STRICT_CONCURRENCY = minimal;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
};
Expand All @@ -568,6 +569,7 @@
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_STRICT_CONCURRENCY = minimal;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 5.0;
};
Expand Down
4 changes: 2 additions & 2 deletions Example/TSAlertController/Presentation/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class ViewController: UIViewController {
@IBAction func showActionSheetWithVariousAppearance(_ sender: Any) {

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

let config = TSButton.Configuration(imageSpacing: 15,
Expand Down
92 changes: 71 additions & 21 deletions Example/Tests/TSAlertControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,29 @@ final class TSAlertControllerTests: XCTestCase {
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}

func testTSAlertController_WhenInitalizedWithFourButtonsAndAutomaticAxis_ShouldSetCorrectActionsOrderAndCount() {

func testTSAlertController_WhenIntlaizedWithAlertStyle_ShouldSetDefaultConfiguration() {
// given
let alertController = TSAlertController(
title: "The title of the alert",
preferredStyle: .alert
)
let mockViewController = MockViewController()

alertController.addAction(.init(title: "Cancel", style: .cancel))
// when
mockViewController.present(alertController, animated: true)

// then
let config = alertController.configuration
XCTAssertEqual(config.enteringTransition, .fadeInAndScaleDown)
XCTAssertEqual(config.exitingTransition, .fadeOut)
XCTAssertEqual(config.headerAnimation, .none)
XCTAssertEqual(config.buttonGroupAnimation, .none)
XCTAssertEqual(config.prefersGrabberVisible, false)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}


func testTSAlertController_WhenIntlaizedWithAlertStyle_ShouldSetDefaultConfiguration() {
func testTSAlertController_WhenIntializedWithAlertStyle_ShouldSetDefaultViewConfiguration() {
// given
let alertController = TSAlertController(
title: "The title of the alert",
Expand All @@ -118,16 +128,13 @@ final class TSAlertControllerTests: XCTestCase {
mockViewController.present(alertController, animated: true)

// then
let config = alertController.configuration
XCTAssertEqual(config.enteringTransition, .fadeInAndScaleDown)
XCTAssertEqual(config.exitingTransition, .fadeOut)
XCTAssertEqual(config.headerAnimation, .none)
XCTAssertEqual(config.buttonGroupAnimation, .none)
XCTAssertEqual(config.prefersGrabberVisible, false)
let viewConfig = alertController.viewConfiguration
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 0.75, maximumRatio: 0.75))
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 100)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}

func testTSAlertController_WhenIntializedWithAlertStyle_SouldSetEnforceCorrectConfiguration() {
func testTSAlertController_WhenIntializedWithAlertStyle_SouldSetCorrectConfigurationForcibly() {
// given
let alertController = TSAlertController(
title: "The title of the alert",
Expand Down Expand Up @@ -166,7 +173,7 @@ final class TSAlertControllerTests: XCTestCase {
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}

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

// then
XCTAssertTrue(true)
let viewConfig = alertController.viewConfiguration
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 0.95, maximumRatio: 0.95))
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 20)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}

func testTSAlertController_WhenIntializedWithAlertStyle_ShouldSetDefaultViewConfiguration() {
func testTSAlertController_WhenIntilizedWithFloatingSheetStyle_ShouldSetCorrectConfigurationForcibly() {
// given
let alertController = TSAlertController(
title: "The title of the alert",
preferredStyle: .alert
preferredStyle: .floatingSheet
)
let mockViewController = MockViewController()

// when
mockViewController.present(alertController, animated: true)

// then
let config = alertController.configuration
XCTAssertFalse(alertController.options.contains(.stretchyDragging))
XCTAssertEqual(config.prefersGrabberVisible, true)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}

func testTSAlertController_WhenIntializedWithActionSheetStyle_ShouldSetDefaultCconfiguration() {
// given
let alertController = TSAlertController(
title: "The title of the alert",
preferredStyle: .actionSheet
)
let mockViewController = MockViewController()

// when
mockViewController.present(alertController, animated: true)

// then
let config = alertController.configuration
XCTAssertEqual(config.enteringTransition, .slideUp)
XCTAssertEqual(config.exitingTransition, .slideDown)
XCTAssertEqual(config.headerAnimation, .none)
XCTAssertEqual(config.buttonGroupAnimation, .none)
XCTAssertEqual(config.prefersGrabberVisible, true)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}

func testTSAlertController_WhenIntializedWithActionSheetStyle_ShouldSetDefaultViewConfiguration() {
// given
let alertController = TSAlertController(
title: "The title of the alert",
preferredStyle: .actionSheet
)
let mockViewController = MockViewController()

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

// then
let viewConfig = alertController.viewConfiguration
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 0.75, maximumRatio: 0.75))
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 100)
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 1.0, maximumRatio: 1.0))
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 0.0)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}

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

// then
let viewConfig = alertController.viewConfiguration
XCTAssertEqual(viewConfig.size.width, .proportional(minimumRatio: 0.95, maximumRatio: 0.95))
XCTAssertEqual(viewConfig.spacing.keyboardSpacing, 20)
let config = alertController.configuration
XCTAssertFalse(alertController.options.contains(.interactiveScaleAndDrag))
XCTAssertEqual(config.prefersGrabberVisible, true)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
XCTAssertEqual(mockViewController.presentViewControllerTarget, alertController)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ final class TSAlertPresentationController: UIPresentationController {
case .alert:
presentedView.center(in: containerView)

case .actionSheet:
presentedView.centerX(in: containerView)
presentedView.anchor(bottom: containerView.bottomAnchor, bottomInset: 0)

case .floatingSheet:
presentedView.centerX(in: containerView)
presentedView.anchor(bottom: containerView.safeAreaLayoutGuide.bottomAnchor, bottomInset: 10)
Expand Down
12 changes: 7 additions & 5 deletions Sources/TSAlert/TSAlertController+Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ import UIKit

public extension TSAlertController {

///
struct Options: OptionSet {

/// Adds an interactive scaling and dragging effect to the alert
/// Adds an interactive scaling and dragging effect to the alert. Cannot be applied to `actionSheet`.
public static let interactiveScaleAndDrag = Options(rawValue: 1 << 0)

/// Dismisses the action sheet when dragged downward beyond a certain threshold.
public static let dismissOnSwipeDown = Options(rawValue: 1 << 1)

/// Dismisses the alert by tapping the outside area.
public static let dismissOnTapOutside = Options(rawValue: 1 << 2)

/// Dismisses the alert by tapping the inside area.
public static let dismissOnTapInside = Options(rawValue: 1 << 3)

/// Applies a stretching effect to the alert when dragged. Can only be applied to `actionSheet`.
public static let stretchyDragging = Options(rawValue: 1 << 4)

public var rawValue: Int
public init(rawValue: Int) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/TSAlert/TSAlertController+Style.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public extension TSAlertController {
case alert

/// An action sheet displayed by the view controller that presented it.
// case actionSheet
case actionSheet

/// An floating sheet displayed by the view controller that presented it.
case floatingSheet
Expand Down
Loading
Loading