Skip to content

Commit

Permalink
Merge pull request #2 from sanzaru/release/0.1.0
Browse files Browse the repository at this point in the history
release/0.1.0
  • Loading branch information
sanzaru authored Mar 8, 2021
2 parents 74c27d3 + 212506e commit 39969b1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/SimpleToast.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1160"
LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SimpleToast is a simple, lightweight and easy to use library to show toasts / po

You decide the content, the library takes care about the rest.

> ⚠️ **Note:** The current version is still in an early stage. There can be breaking changes in version updates.
## Table of contents
- [Features:](#features)
- [Installation](#installation)
Expand All @@ -32,9 +34,15 @@ dependencies: [
]
```

### Manual
### Manual installation
Simply drag the SimpleToast.swift file into your project.

## Demo
<p align="center">
<img src="https://raw.githubusercontent.com/sanzaru/SimpleToast.assets/master/video/SimpleToastDemo-Capsule-Slide.gif" width="300" align="center" alt="Simple toast">
</p>


## Screenshots

| Simple toast | Complex toast |
Expand Down Expand Up @@ -79,7 +87,7 @@ struct ToastTestView: View {
}
```

> **NOTE:** The toast respects the frame of the view it is attached to. Make sure the view has enough room to render the toast. Preferably the view should be attached to the most outer view or the navigation view, if available.
> **Note:** The toast respects the frame of the view it is attached to. Make sure the view has enough room to render the toast. Preferably the view should be attached to the most outer view or the navigation view, if available.

To run custom code after the toast did disappear you just simply have to pass a function to the completion parameter:
Expand Down Expand Up @@ -125,9 +133,23 @@ struct ToastTestView: View {

## Options

The toast can be configured via an optional SimpleToastOptions object. If nil is given the default values are taken.
The toast can be configured via an optional SimpleToastOptions object. If nil is given default values are taken. See table below for more information.

> &nbsp;<br>
> 📌 All parameters inside the options are optional.
> &nbsp;
The struct has the following signature:
| Option | Description | Default |
| -------- | ------------- | -------- |
| **alignment** | Defines the alignment of the toast. See [https://developer.apple.com/documentation/swiftui/alignment](https://developer.apple.com/documentation/swiftui/alignment) for more information. | .top |
| **hideAfter** | Defines when the toast disappears. If nil is given the toast won't disappear. | nil |
| **showBackdrop** | Defines if the toast is rendered over a backdrop. | true |
| **backdropColor** | Defines the backdrop color | Color.white.opacity(0.9) |
| **animation** | Defines the animation type. See [https://developer.apple.com/documentation/swiftui/animation](https://developer.apple.com/documentation/swiftui/animation) for more information. | .linear |
| **modifierType** | Defines the type of toast animation. Possible values(.slide, .fade) | .fade |


### The struct has the following signature:

```swift
public struct SimpleToastOptions {
Expand All @@ -140,25 +162,18 @@ public struct SimpleToastOptions {
}
```

**alignment:** Defines the alignment of the toast. See [https://developer.apple.com/documentation/swiftui/alignment](https://developer.apple.com/documentation/swiftui/alignment) for more information.

**hideAfter:** Optional parameter to define when the toast disappears. If nil is given the toast won't disappear.

**showBackdrop:** Optional parameter to define if the toast is rendered over a backdrop.

**backdropColor:** Optional parameter for the backdrop color

**animation:** Optional parameter for the animation type. See [https://developer.apple.com/documentation/swiftui/animation](https://developer.apple.com/documentation/swiftui/animation) for more information.

**modifierType:** Optional parameter for determining the type of toast animation. Possible values(.slide, .fade), default: .fade


## Changelog

#### v 0.1.0
- First minor release
- Updated drag gesture for better touch handling
- Better options name

#### v0.0.9
- Better animations and transitions
- Better UI integration
- Fixed slide modifier
- Better animations and transitions
- Better UI integration
- Fixed slide modifier

#### v0.0.8
- Better slide modifier
Expand Down
19 changes: 13 additions & 6 deletions Sources/SimpleToast/SimpleToast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public struct SimpleToastOptions {
public init(
alignment: Alignment = .top,
hideAfter: TimeInterval? = nil,
backdrop: Bool? = true,
showBackdrop: Bool? = true,
backdropColor: Color = Color.white.opacity(0.9),
animation: Animation = .linear,
modifierType: SimpleToastModifierType = .fade
) {
self.alignment = alignment
self.hideAfter = hideAfter
self.showBackdrop = backdrop
self.showBackdrop = showBackdrop
self.backdropColor = backdropColor
self.animation = animation
self.modifierType = modifierType
Expand All @@ -47,12 +47,18 @@ struct SimpleToast<SimpleToastContent: View>: ViewModifier {
let content: () -> SimpleToastContent

private var toastDragGesture: some Gesture {
DragGesture(minimumDistance: 20, coordinateSpace: .local)
.onChanged { gesture in
self.toastOffset.height = gesture.translation.height
DragGesture()
.onChanged {
if $0.translation.height < self.toastOffset.height {
self.toastOffset = $0.translation
}
}
.onEnded { _ in
self.hide()
if self.toastOffset.height <= -20 {
self.hide()
}

self.toastOffset = .zero
}
}

Expand Down Expand Up @@ -85,6 +91,7 @@ struct SimpleToast<SimpleToastContent: View>: ViewModifier {
self.content()
.modifier(SimpleToastSlide(showToast: $showToast, options: options))
.gesture(toastDragGesture)
.offset(toastOffset)

default:
self.content()
Expand Down

0 comments on commit 39969b1

Please sign in to comment.