Skip to content

Commit e4883d5

Browse files
authored
Merge pull request #38 from nodes-ios/release/2.0.0
Release/2.0.0
2 parents 56b4395 + 4dc06e6 commit e4883d5

File tree

157 files changed

+768
-14147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+768
-14147
lines changed

README.md

Lines changed: 173 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Rye
1+
# 🍞 Rye
22

33
[![Carthage Compatible](https://img.shields.io/badge/carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
44
![Plaforms](https://img.shields.io/badge/platforms-iOS%20-lightgrey.svg)
@@ -7,15 +7,16 @@
77

88
## Intro
99

10-
Rye allows you to present non intrusive alerts to your users of both "Toast" and "Snack Bar" types.
10+
Rye allows you to present non intrusive alerts to your users.
11+
1112
You can choose to display the default Rye alert type or go fully custom and display your own `UIView`.
1213

1314
### Examples
1415

1516

1617
| ![](ExampleImages/example1.png) | ![](ExampleImages/example2.png) | ![](ExampleImages/example3.png) |
1718
|----------------|---|---|
18-
| <center>Custom Rye with Image</center> | <center>Custom Rye with Button</center> | <center>Default Rye</center> |
19+
| <center>Custom Rye alert with Image</center> | <center>Custom Rye alert with Button</center> | <center>Default Rye alert</center> |
1920

2021
## 📝 Requirements
2122

@@ -36,75 +37,190 @@ pod 'nodes-ios/Rye'
3637

3738
## 💻 Usage
3839

40+
### Principles
41+
42+
To display a Rye alert you declare a new `RyeViewController` and then call:
43+
44+
- `show`: to show the alert
45+
- `dismiss`: to dismiss the alert
46+
47+
**Note:** Depending on which `dismissMode` you have selected, you may not need to dismiss the alert yourself, see the section about [`displayModes`](#display-modes) below for more information.
48+
49+
At the very minimum you need to consider:
50+
51+
- which text to show
52+
- whether to show a standard alert or bring your own custom view to the party
53+
- where to show the text (`top` or `bottom`)
54+
55+
#### Show Text
56+
57+
To show a text using a Rye alert you need to create a `RyeConfiguration`. This is a dictionary allowing you to configure various UI related aspects of your Rye alert. For more information on available keys, please refer to the section: [Possible Rye Configuration Values](#possible-rye-configuration-values) below.
58+
59+
One of the values you can add to a `RyeConfiguration` is a text to show in your alert.
60+
3961
```swift
40-
import Rye
62+
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
4163
```
4264

43-
### Display Default Rye
65+
#### Alert Type
66+
67+
You can use the default Rye alert or you can create your own view and use that instead. To determine which to use, you use the `Rye.ViewType` enum defined like so:
4468

4569
```swift
70+
public enum ViewType {
71+
case standard(configuration: RyeConfiguration?)
72+
case custom(UIView, animationType: AnimationType = .slideInOut)
73+
}
74+
```
4675

47-
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
76+
As you can see, the `standard` ViewType takes an optional `RyeConfiguration` as a parameter. This means that you don't _have_ to provide a `RyeConfiguration` in which case default values will be used for all parameters including the text (but you probably don't want an alert showing the text "Add a message", do you?).
77+
78+
The `custom` ViewType takes the view you would like to use and a `Rye.AnimationType` (with a default value already provided). For more on the `AnimationType` please refer to the section [Animation Type](#animation-type) below.
79+
80+
#### Where To Show the Alert?
81+
82+
Where to show a Rye alert is determined by a `Rye.Position` enum which is defined like so:
83+
84+
```swift
85+
public enum Position {
86+
case top(inset: CGFloat)
87+
case bottom(inset: CGFloat)
88+
}
89+
```
90+
91+
For more on the `Rye.Position` please refer to the section [Position](#position) below.
92+
93+
### Display a Default Rye
94+
95+
Following these principles, we are now ready to show our first Rye alert.
4896

49-
let rye = RyeViewController.init(alertType: .toast,
50-
viewType: .standard(configuration: ryeConfiguration),
51-
at: .bottom(inset: 16),
52-
timeAlive: 2)
97+
```swift
98+
import Rye
99+
...
100+
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
101+
let rye = RyeViewController.init(viewType: .standard(configuration: ryeConfiguration),
102+
at: .bottom(inset: 16))
53103
rye.show()
104+
```
105+
106+
This will result in a Rye alert with the text "Message for the user" appearing at the bottom at the screen and then disappearing automatically after 2.5 seconds.
54107

108+
### Control the Dismiss Type
109+
110+
If you would like the Rye alert to disappear in a different way, you can pass a `dismissMode` parameter when creating the `RyeViewController`
111+
112+
```swift
113+
import Rye
114+
...
115+
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
116+
let rye = RyeViewController.init(dismissMode: .gesture,
117+
viewType: .standard(configuration: ryeConfiguration),
118+
at: .bottom(inset: 16))
119+
rye.show()
55120
```
56121

122+
The alert will now stay on the screen until the user taps or swipes at it.
123+
57124
### Display Default Rye with Custom Configuration
58125

59-
```swift
126+
If you want to have more control of the alert view you can add keys and values to the `RyeConfiguration` as shown here.
60127

128+
```swift
129+
import Rye
130+
...
61131
let ryeConfiguration: RyeConfiguration = [
62132
Rye.Configuration.Key.text: "Error message for the user",
63133
Rye.Configuration.Key.backgroundColor: UIColor.red.withAlphaComponent(0.4),
64-
Rye.Configuration.Key.animationType: Rye.AnimationType.fadeInOut]
134+
Rye.Configuration.Key.animationType: Rye.AnimationType.fadeInOut
65135
]
66136

67-
let rye = RyeViewController.init(alertType: .toast,
68-
viewType: .standard(configuration: ryeConfiguration),
69-
at: .bottom(inset: 16),
70-
timeAlive: 2)
137+
let rye = RyeViewController.init(viewType: .standard(configuration: ryeConfiguration),
138+
at: .bottom(inset: 16))
71139
rye.show()
72140

73141
```
74142

75143
### Display Rye with a Custom `UIView`
76144

77-
```swift
145+
For even more control you can create your own subclass of `UIView` and use `.custom` for the `viewType` parameter
78146

79-
let customRyeView = RyeView()
147+
```swift
148+
import Rye
149+
...
80150

81-
let rye = RyeViewController.init(alertType: .toast,
82-
viewType: .custom(customRyeView),
83-
at: .bottom(inset: 16),
84-
timeAlive: 2)
151+
let customView = YourCustomViewHere()
152+
let rye = RyeViewController.init(viewType: .custom(customView),
153+
at: .bottom(inset: 16))
85154
rye.show()
86155

87156
```
88157

89-
### Alert Type
158+
### Dismiss Completion
159+
If you would like to execute some code when the Rye alert is dismissed you can pass a `dismissCompletion` code block when calling `show` like so:
160+
161+
```swift
162+
import Rye
163+
...
164+
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
165+
let rye = RyeViewController.init(viewType: .standard(configuration: ryeConfiguration),
166+
at: .bottom(inset: 16))
167+
rye.show(withDismissCompletion: {
168+
print("Goodbye from Rye, time to dy..die")
169+
})
170+
```
171+
172+
### Dismiss Rye Alerts Manually
173+
174+
If you have selected to show a Rye alert as `.nonDismissable` you have to dismiss it yourself. Keep a reference to the `RyeViewController` and call `dismiss` when you are ready to let go.
175+
176+
```swift
177+
import Rye
178+
...
179+
var rye: RyeViewController?
180+
181+
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
182+
rye = RyeViewController.init(dismissMode: .nonDismissable,
183+
viewType: .standard(configuration: ryeConfiguration),
184+
at: .bottom(inset: 16))
185+
rye?.show()
186+
187+
...at a later point in time
188+
rye?.dismiss()
189+
```
190+
191+
### Descriptions of Parameters
90192

91-
Rye allows you to define the alert type you want to display to your user. Possible alert types are:
193+
Below you can find descriptions of the various parameters used to control a Rye alert.
92194

93-
- snackBar which is displayed at applications UIWindow level and allows interaction with the presented UIView
94-
- toast which is displayed at applications alert UIWindow level and doesn't allows interaction with the presented UIView
195+
#### Display Modes
95196

96-
### Position
197+
Rye supports three different `displayMode` values which can be passed when creating a new `RyeViewController`:
198+
199+
- `automatic`: The alert appears and disappears automatically after a specified interval.
200+
- `gesture`: To dismiss the alert you can tap or swipe it.
201+
- `nonDismissable`: The alert will stay permanently on the screen until it is dismissed by calling `dismiss()` on your `RyeViewController` instance.
202+
203+
If you do not pass this value when creating a new `RyeViewController`, a default value of `automatic` with a default interval of 2.5 seconds is used (the default interval is defined in `Rye.defaultDismissInterval`)
204+
205+
#### Position
206+
207+
With Rye, you can specify the position where the Rye alert will be displayed on the screen via the `position` parameter, which takes an associated value that allows you to specify the inset.
97208

98-
With Rye you can specify the position where the Rye view will be displayed on screen via the `position` parameter, which takes an associated value that allows you to specify the inset.
99209
By default Rye will calculate the safe area insets for you, so be sure to specify only the extra desired inset.
100210

101-
If you decide to not provide a value for this parameter, you will be in charge of dismissing the Rye when you think it is appropriate.
102211

103-
### Time Used
212+
#### Animation Type
213+
214+
Rye provides two animation types:
104215

105-
When creating an instance of `RyeViewController` you can choose to provide a value for the `timeAlive` parameter during initialisation. The value provided will be the time in seconds the Rye view will be presented on screen to the user.
216+
- `slideInOut`: slides the view in from either top or bottom (depending on which `Position` you have selected). When dismissed the view slides out in the same direction.
217+
- `fadeInOut`: fades the view in and out again when dismissed.
106218

107-
### Possible Rye Configurations
219+
To control how long the animation will take when using a `.standard` view, please use the `animationDuration` key of the `RyeConfiguration` and provide a `TimeInterval` value.
220+
221+
In case you are using a `.custom` view or you _do not_ provide a value for `animationDuration`, a standard value of 0.3 seconds is used.
222+
223+
#### Possible Rye Configuration Values
108224

109225
The following keys can be used in the configuration dictionary when presenting a default type Rye:
110226

@@ -118,8 +234,32 @@ The following keys can be used in the configuration dictionary when presenting a
118234

119235
If configuration is set to nil, a default configuration will be used. Any options set, will override the default state.
120236

237+
## ⚠️ Gotchas
238+
239+
In order to display a Rye message a `parentView` is needed to determine _in relation to what_ the Rye message is positioned.
240+
241+
If you try to display a Rye message before a `parentView` can be obtained, you will see this warning in the console of your IDE.
242+
243+
> A parentView could not be found to display the Rye message on. Are you trying to show a Rye message before the view lifecycle is ready to display views?
244+
245+
This can be seen if you try to call `show()` on a `RyeViewController` in `viewDidLoad()` of a `UIViewController` for instance.
246+
247+
121248
## Example Project
122-
To learn more, please refer to the example project contained in this repository.
249+
To learn more, please refer to the RyeExample project contained in this repository.
250+
251+
## ⬆️ Updating from v1.x.x to v2.0.0
252+
In version 2.0.0 of Rye we changed the way you display messages.
253+
254+
Gone is the distinction between `.toast` and `.snackBar`. Instead, every message is now displayed in a separate `UIWindow` at the very top level of your view stack and you must decide how to dismiss the message with the previously described [`displayModes`](#display-modes).
255+
256+
This also means that the previous init method: `RyeViewController.init(alertType:viewType:at:timeAlive:)` has been deprecated. If you use this init method with version 2.0.0 you will receive a deprecation warning during compilation.
257+
258+
You can - if you stubbornly insist - still use the now old `init` method. Behind the scenes Rye will create a new `RyeViewController` for you and set the `displayMode` based on these rules:
259+
260+
_If_ you have added a `timeAlive` value, that `timeAlive` will be used to create a `displayMode` with a value of `.automatic(interval: timeAlive)`
261+
262+
_If_ you have _not_ added a `timeAlive` value, the `displayMode` will be `.nonDismissable`.
123263

124264
## 👥 Credits
125265
Made with ❤️ at [Nodes](http://nodesagency.com).

Rye.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Pod::Spec.new do |spec|
44

55
spec.name = "Rye"
6-
spec.version = "1.1.9"
7-
spec.summary = "Rye allows you to present non intrusive alerts to your users of both \"Toast\" and \"Snack Bar\" types. You can choose to display the default Rye alert type or go fully custom and display your own UIView."
6+
spec.version = "2.0.0"
7+
spec.summary = "Rye allows you to present non intrusive alerts to your users. You can choose to display the default Rye alert type or go fully custom and display your own UIView."
88
spec.homepage = "https://github.com/nodes-ios/Rye"
99

1010
spec.author = { "Nodes Agency - iOS" => "ios@nodes.dk" }

Rye/Podfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

Rye/Podfile.lock

Lines changed: 0 additions & 20 deletions
This file was deleted.

Rye/Pods/Manifest.lock

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)