You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| <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> |
19
20
20
21
## 📝 Requirements
21
22
@@ -36,75 +37,190 @@ pod 'nodes-ios/Rye'
36
37
37
38
## 💻 Usage
38
39
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
+
39
61
```swift
40
-
importRye
62
+
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text:"Message for the user"]
41
63
```
42
64
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:
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
+
publicenumPosition {
86
+
casetop(inset: CGFloat)
87
+
casebottom(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.
48
96
49
-
let rye = RyeViewController.init(alertType: .toast,
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))
53
103
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.
54
107
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
+
importRye
114
+
...
115
+
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text:"Message for the user"]
116
+
let rye = RyeViewController.init(dismissMode: .gesture,
let rye = RyeViewController.init(viewType: .standard(configuration: ryeConfiguration),
138
+
at: .bottom(inset: 16))
71
139
rye.show()
72
140
73
141
```
74
142
75
143
### Display Rye with a Custom `UIView`
76
144
77
-
```swift
145
+
For even more control you can create your own subclass of `UIView` and use `.custom` for the `viewType` parameter
78
146
79
-
let customRyeView =RyeView()
147
+
```swift
148
+
importRye
149
+
...
80
150
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))
85
154
rye.show()
86
155
87
156
```
88
157
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
+
importRye
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
+
importRye
178
+
...
179
+
var rye: RyeViewController?
180
+
181
+
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text:"Message for the user"]
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.
92
194
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
95
196
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.
97
208
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.
99
209
By default Rye will calculate the safe area insets for you, so be sure to specify only the extra desired inset.
100
210
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.
102
211
103
-
### Time Used
212
+
#### Animation Type
213
+
214
+
Rye provides two animation types:
104
215
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.
106
218
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
108
224
109
225
The following keys can be used in the configuration dictionary when presenting a default type Rye:
110
226
@@ -118,8 +234,32 @@ The following keys can be used in the configuration dictionary when presenting a
118
234
119
235
If configuration is set to nil, a default configuration will be used. Any options set, will override the default state.
120
236
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
+
121
248
## 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`.
Copy file name to clipboardExpand all lines: Rye.podspec
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,8 @@
3
3
Pod::Spec.newdo |spec|
4
4
5
5
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."
0 commit comments