Skip to content

Commit

Permalink
Replaced Action with Selector in order to reduce the package min vers…
Browse files Browse the repository at this point in the history
…ion from 15 to 13
  • Loading branch information
chrsp committed Sep 18, 2023
1 parent f58a71f commit e44872a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 2 additions & 4 deletions Example/AlertCenterExample/ToastAlertViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ class ToastAlertViewController: UIViewController {

displayToastOnWindowWithActionBtn.setTitle("Toast With Action", for: .normal)

let action = ToastAction(title: "Navigate", action: .init { _ in
self.navigate()
})
let action = ToastAction(title: "Navigate", target: self, selector: #selector(navigate))

displayToastOnWindowWithActionBtn.addAction(.init { _ in
self.alertCenter.display(message: "Displaying With Action", time: self.displayTime, onView: self.view, action: action)
Expand Down Expand Up @@ -90,7 +88,7 @@ class ToastAlertViewController: UIViewController {
.store(in: &cancellables)
}

private func navigate() {
@objc private func navigate() {
let nextViewController = UIViewController()
nextViewController.view.backgroundColor = .white

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "AlertCenter",
platforms: [.iOS(.v15)],
platforms: [.iOS(.v13)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
Expand Down
2 changes: 1 addition & 1 deletion Sources/AlertCenter/Alerts/MDCSnackbarToastAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class MDCSnackbarToastAlert: UIView, AnimatedAlert {

if let action = action {
actionButton.setTitle(action.title.uppercased(), for: .normal)
actionButton.addAction(action.action, for: .touchUpInside)
actionButton.addTarget(action.target, action: action.selector, for: .touchUpInside)
actionButton.isHidden = false
} else {
actionButton.isHidden = true
Expand Down
8 changes: 5 additions & 3 deletions Sources/AlertCenter/ToastAlert/ToastAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import UIKit

public struct ToastAction {
var title: String
var action: UIAction
var target: AnyObject
var selector: Selector

public init(title: String, action: UIAction) {
public init(title: String, target: AnyObject, selector: Selector) {
self.title = title
self.action = action
self.target = target
self.selector = selector
}
}

0 comments on commit e44872a

Please sign in to comment.