-
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 #33 from 3sidedcube/feature/post-view-order
Create a `Toast` message which shows from the bottom. (Very much an iOS equivalent of an Android toast)
- Loading branch information
Showing
14 changed files
with
308 additions
and
82 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,52 @@ | ||
// | ||
// 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() | ||
|
||
// MARK: - ViewController lifecycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
toast.addTo( | ||
view: view, | ||
layout: .bottom, | ||
constrainToSafeArea: true | ||
) | ||
} | ||
|
||
override func viewDidAppear(_ animated: Bool) { | ||
super.viewDidAppear(animated) | ||
|
||
toast.post(message: .shortMessage) | ||
toast.postIfNotShowing(message: .shortMessage) // Shouldn't show | ||
toast.post(message: .longMessage) | ||
} | ||
} | ||
|
||
// MARK: - String + Text | ||
|
||
private extension String { | ||
|
||
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,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 | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.