Skip to content

Commit

Permalink
Update toast docs
Browse files Browse the repository at this point in the history
  • Loading branch information
scottasoutherland committed Jul 9, 2024
1 parent 77b9eff commit 9fce9d4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 31 deletions.
Binary file added www/src/pages/components/toast/ios/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added www/src/pages/components/toast/ios/custom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 29 additions & 29 deletions www/src/pages/components/toast/ios/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,50 @@ The toast component supports dynamic type by default

`public var message: String` The message text to be displayed to the user

`public var linkText: String` The text on the `link` style CTA button
`public var action: Toast.Action` The "action" to take on the toast. Includes link text, and a handler closure.

`public var theme: Toast.Theme` A toast theme, which allows for customization of the background color, text color, icon, and icon color.

`public let presentationDuration: TimeInterval` The duration for which to display the toast, defaults to 5 seconds.

## Usage

Once constructed, a toast can be displayed with animation.
You can construct a toast with various themes like

```swift
import Thumbprint
let toast = Toast(message: "This is a message?", theme: Toast.Theme.alert(), action: Toast.Action(text: "Take Action", handler: {
/* Do some action */
}))
```

/* ... */
![alert](alert.png)

public func display(_ toastWithText text: String, linkText: String, in view: UIView, animate: Bool = true) {
let toast = Toast(title: text, linkText: linkText)
view.addSubview(toast)
You can customize the theme by overriding various properties

var initialYPositionConstraint: Constraint?
```swift
let toast = Toast(message: "This is a message?", theme: Toast.Theme.success(Icon.contentActionsAddMedium), action: Toast.Action(text: "Take Action", handler: {}))
```

toast.snp.makeConstraints { make in
make.left.right.equalToSuperview().inset(Space.three)
initialYPositionConstraint = make.top.equalTo(tabBar.snp.bottom).constraint
}
![custom](custom.png)

view.layoutIfNeeded()
Once constructed, a toast can be displayed with animation using the showToast method.

initialYPositionConstraint?.deactivate()
```swift
import Thumbprint

toast.snp.makeConstraints { make in
make.bottom.equalTo(tabBar.snp.top).offset(-Self.toastSpacing)
}
/* ... */

toast.alpha = 0.0
public func display(_ toastWithText text: String, linkText: String, in view: UIView) {
let toast = Toast(message: text, action: Toast.Action(text: linkText, handler: {
/* Do some action */
}))

UIView.animate(withDuration: animate ? 0.5 : 0) {
toast.alpha = 1.0
view.layoutIfNeeded()
}
toast.showToast(animated: false, completion: nil)
view.addSubview(toast)
toast.snp.makeConstraints { make in
make.leading.trailing.bottom.equalToSuperview()
}

DispatchQueue.main.asyncAfter(deadline: .now() + Self.autoDismissDelay) {
UIView.animate(withDuration: Duration.six, animations: {
toast.alpha = 0.0
}, completion: { _ in
self.remove(toast)
})
}
}
```

Expand Down
Binary file modified www/src/pages/components/toast/ios/toast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added www/src/pages/components/toast/swiftui/alert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions www/src/pages/components/toast/swiftui/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ A toast is used to display a short-lived notification and optional CTA at the bo

## Configuration

Toasts support a single left aligned title and an optional right aligned link. The toast view is attached to a View with the `.withToast()` modifier. `withToast()` accepts a TPToast binding and an optional `linkAction` closure, which is triggered when the user taps on the link text. When the toast binding passed into TPToast is nil, the toast is hidden, when it exists, the toast animates onto the screen. The toast automatically dismisses itself after a short period of time (2.5 seconds, by default)
Toasts support a single left aligned title, a theme, and an optional right aligned link. The toast view is attached to a View with the `.withToast()` modifier. `withToast()` accepts a TPToast binding and an optional `linkAction` closure, which is triggered when the user taps on the link text. When a toast binding exists, it will animated onto the screen, or, if another toast is already showing on screen, it will queue itself for presentation after the existing toast dismisses. The toast automatically dismisses itself after a short period of time (2.5 seconds, by default)

The toast's title, link text, and optional duration are set on the TPToast object itself.
The toast's title, link text, theme, and optional duration are set on the TPToast object itself.

## Usage

Expand All @@ -42,6 +42,20 @@ public var body: some View {
}
```

## Theming

Toasts can be themed via a TPTheme object that includes a background color, an optional icon, an icon color, and text color.

There are several built in themes. `default`, `alert`, `success`, `info`, `caution`.

```swift

let toast = TPToast(title: someText, theme: .alert, linkText: linkText)

```

![alert](alert.png)

export const pageQuery = graphql`
{
# Get links to by path to display in the navbar.
Expand Down
Binary file modified www/src/pages/components/toast/swiftui/thumbprintui_toast.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9fce9d4

Please sign in to comment.