-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from 3sidedcube/release/v2.2.0
Release/v2.2.0
- Loading branch information
Showing
21 changed files
with
473 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// | ||
// ToastViewController.swift | ||
// Example | ||
// | ||
// Created by Ben Shutt on 02/06/2021. | ||
// Copyright © 2021 3 SIDED CUBE APP PRODUCTIONS LTD. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import MessageStackView | ||
|
||
/// `UIViewController` to test `Toast` | ||
class ToastViewController: UIViewController { | ||
|
||
/// `Toast` to post at the bottom of the screen | ||
private lazy var toast = Toast() | ||
|
||
/// `UIButton` to add to bottom to make sure it can be clicked when the toast is slowing | ||
private lazy var button: UIButton = { | ||
let button = UIButton() | ||
button.setTitle(.buttonTitleClick, for: .normal) | ||
button.setTitleColor(.systemBlue, for: .normal) | ||
button.addTarget( | ||
self, | ||
action: #selector(buttonTouchUpInside), | ||
for: .touchUpInside | ||
) | ||
return button | ||
}() | ||
|
||
// MARK: - ViewController lifecycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
addButtonToBottomLeading() | ||
addAndConstrainToast(toast) | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
|
||
toast.post(message: .shortMessage) | ||
toast.postIfNotShowing(message: .shortMessage) // Shouldn't show | ||
toast.post(message: .longMessage) | ||
} | ||
|
||
// MARK: - Subviews | ||
|
||
private func addButtonToBottomLeading() { | ||
view.addSubview(button) | ||
button.translatesAutoresizingMaskIntoConstraints = false | ||
NSLayoutConstraint.activate([ | ||
button.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 25), | ||
button.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -15) | ||
]) | ||
} | ||
|
||
// MARK: - Actions | ||
|
||
/// `sender` received `.touchUpInside` `UIControl.Event` | ||
/// | ||
/// - Parameter sender: `UIButton` that invoked the action | ||
@objc | ||
private func buttonTouchUpInside(_ sender: UIButton) { | ||
UIView.animate( | ||
withDuration: 0.5, | ||
delay: 0, | ||
options: [.autoreverse], | ||
animations: { | ||
sender.setTitle(.buttonTitleClicked, for: .normal) | ||
sender.transform = CGAffineTransform(scaleX: 2, y: 2) | ||
}, completion: { _ in | ||
sender.transform = .identity | ||
sender.setTitle(.buttonTitleClick, for: .normal) | ||
} | ||
) | ||
} | ||
} | ||
|
||
// MARK: - String + Text | ||
|
||
private extension String { | ||
|
||
static let buttonTitleClick = """ | ||
Click Me | ||
""" | ||
|
||
static let buttonTitleClicked = """ | ||
Clicked! | ||
""" | ||
|
||
static let shortMessage = """ | ||
This is a toast! | ||
""" | ||
|
||
static let longMessage = """ | ||
This is a long toast to test how the text wraps when the width \ | ||
of the text is greater than the width of the screen | ||
""" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// LayoutGuide.swift | ||
// MessageStackView | ||
// | ||
// Created by Ben Shutt on 03/06/2021. | ||
// Copyright © 2021 3 SIDED CUBE APP PRODUCTIONS LTD. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Edge layout guide | ||
protocol EdgeLayoutGuide { | ||
|
||
/// Leading anchor in X | ||
var leadingAnchor: NSLayoutXAxisAnchor { get } | ||
|
||
/// Top anchor in Y | ||
var topAnchor: NSLayoutYAxisAnchor { get } | ||
|
||
/// Trailing anchor in X | ||
var trailingAnchor: NSLayoutXAxisAnchor { get } | ||
|
||
/// Bottom anchor in Y | ||
var bottomAnchor: NSLayoutYAxisAnchor { get } | ||
} | ||
|
||
// MARK: - UIView + EdgeLayoutGuide | ||
|
||
extension UIView: EdgeLayoutGuide {} | ||
|
||
// MARK: - UILayoutGuide + EdgeLayoutGuide | ||
|
||
extension UILayoutGuide: EdgeLayoutGuide {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Order.swift | ||
// MessageStackView | ||
// | ||
// Created by Ben Shutt on 02/06/2021. | ||
// Copyright © 2021 3 SIDED CUBE APP PRODUCTIONS LTD. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// How posted `UIView`s are ordered. | ||
/// E.g. the order of the `arrangedSubviews`. | ||
public enum Order { | ||
|
||
/// Natural order of `UIStackView`s. Posted `UIView`s get appended to the | ||
/// `arrangedSubviews` array appearing below/after the previous. | ||
case topToBottom | ||
|
||
/// Reverse order of `UIStackView`s. Posted `UIView`s get inserted at the start of the | ||
/// `arrangedSubviews` array appearing above/before the previous. | ||
case bottomToTop | ||
} | ||
|
||
// MARK: - Extensions | ||
|
||
public extension Order { | ||
|
||
/// Other `Order` (opposite direction) | ||
var switched: Self { | ||
switch self { | ||
case .topToBottom: return .bottomToTop | ||
case .bottomToTop: return .topToBottom | ||
} | ||
} | ||
} |
Oops, something went wrong.