Skip to content

Commit 2aa5a92

Browse files
Update README and include alignment settings
1 parent f88a2e2 commit 2aa5a92

File tree

1 file changed

+69
-38
lines changed

1 file changed

+69
-38
lines changed

README.md

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# 🍞 Rye
22

3+
![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange)
34
[![Carthage Compatible](https://img.shields.io/badge/carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
4-
![Plaforms](https://img.shields.io/badge/platforms-iOS%20-lightgrey.svg)
5+
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Rye.svg)](https://cocoapods.org/pods/Rye)
6+
![Platforms](https://img.shields.io/badge/platforms-iOS%20-lightgrey.svg)
57
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nodes-ios/Rye/blob/master/LICENSE)
6-
[![CircleCI](https://circleci.com/gh/nodes-ios/Rye.svg?style=shield)](https://circleci.com/gh/nodes-ios/Rye)
8+
79

810
## Intro
911

@@ -20,51 +22,57 @@ You can choose to display the default Rye alert type or go fully custom and disp
2022

2123
## 📝 Requirements
2224

23-
iOS 11.4
25+
iOS 11.4
2426
Swift 5
2527

2628
## 📦 Installation
2729

30+
### Swift Package Manager
31+
Copy this repository URL, and add the repo into your Package Dependencies:
32+
```
33+
https://github.com/nodes-ios/Rye.git
34+
```
35+
2836
### Carthage
29-
~~~bash
37+
```bash
3038
github "nodes-ios/Rye"
31-
~~~
39+
```
3240

3341
### Cocoapods
34-
~~~bash
42+
```bash
3543
pod 'Rye'
36-
~~~
44+
```
3745

3846
## 💻 Usage
3947

4048
### Principles
4149

4250
To display a Rye alert you declare a new `RyeViewController` and then call:
4351

44-
- `show`: to show the alert
45-
- `dismiss`: to dismiss the alert
52+
- `show()`: to show the alert
53+
- `dismiss()`: to dismiss the alert
4654

4755
**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.
4856

4957
At the very minimum you need to consider:
5058

5159
- which text to show
5260
- whether to show a standard alert or bring your own custom view to the party
53-
- where to show the text (`top` or `bottom`)
61+
- where to show the alert (`top` or `bottom`)
5462

5563
#### Show Text
5664

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.
65+
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 [Possible Rye Configuration Values](#possible-rye-configuration-values) section.
5866

5967
One of the values you can add to a `RyeConfiguration` is a text to show in your alert.
6068

6169
```swift
62-
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
70+
let ryeConfiguration: RyeConfiguration = [ Rye.Configuration.Key.text: "Message for the user" ]
6371
```
6472

6573
#### Alert Type
6674

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:
75+
You can use the default Rye alert or you can create your own UIView and use that instead. To determine which to use, you use the `Rye.ViewType` enum defined like so:
6876

6977
```swift
7078
public enum ViewType {
@@ -75,9 +83,9 @@ public enum ViewType {
7583

7684
As you can see, both the `standard` and the `custom` 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?).
7785

78-
Additionally, the `custom` ViewType takes the view you would like to use.
86+
Additionally, the `custom` ViewType takes your custom UIView that you would like to use.
7987

80-
Note that some of the `RyeConfiguration` keys are not relevant when using a custom view. More specificaly, theses are the keys not used when you decide to use a `custom` view for your message:
88+
Note that some of the `RyeConfiguration` keys are not relevant when using a custom view. More specificaly, these are the keys not used when you decide to use a `custom` view for your message:
8189

8290
- backgroundColor
8391
- textColor
@@ -90,7 +98,7 @@ As you can see, both the `standard` and the `custom` ViewType takes an optional
9098

9199
#### Where To Show the Alert?
92100

93-
Where to show a Rye alert is determined by a `Rye.Position` enum which is defined like so:
101+
Where to show a Rye alert is determined by the `Rye.Position` and `Rye.Alignment` enums which are defined like so:
94102

95103
```swift
96104
public enum Position {
@@ -99,7 +107,17 @@ public enum Position {
99107
}
100108
```
101109

102-
For more on the `Rye.Position` please refer to the section [Position](#position) below.
110+
```swift
111+
public enum Alignment {
112+
case leading(inset: CGFloat)
113+
case center
114+
case trailing(inset: CGFloat)
115+
}
116+
```
117+
118+
If the alignment is not specified at init time, it will default to `.center` alignment.
119+
120+
For more on `Rye.Position` and `Rye.Alignment`, please refer to the section [Position & Alignment](#position-and-alignment) below.
103121

104122
### Display a Default Rye
105123

@@ -109,12 +127,14 @@ Following these principles, we are now ready to show our first Rye alert.
109127
import Rye
110128
...
111129
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
112-
let rye = RyeViewController.init(viewType: .standard(configuration: ryeConfiguration),
113-
at: .bottom(inset: 16))
130+
let rye = RyeViewController(
131+
viewType: .standard(configuration: ryeConfiguration),
132+
at: .bottom(inset: 16)
133+
)
114134
rye.show()
115135
```
116136

117-
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.
137+
This will result in a Rye alert with the text "Message for the user" appearing at the bottom of the screen, and then disappearing automatically after 2.5 seconds.
118138

119139
### Control the Dismiss Type
120140

@@ -124,17 +144,19 @@ If you would like the Rye alert to disappear in a different way, you can pass a
124144
import Rye
125145
...
126146
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
127-
let rye = RyeViewController.init(dismissMode: .gesture,
128-
viewType: .standard(configuration: ryeConfiguration),
129-
at: .bottom(inset: 16))
147+
let rye = RyeViewController(
148+
dismissMode: .gesture,
149+
viewType: .standard(configuration: ryeConfiguration),
150+
at: .bottom(inset: 16)
151+
)
130152
rye.show()
131153
```
132154

133155
The alert will now stay on the screen until the user taps or swipes at it.
134156

135157
### Display Default Rye with Custom Configuration
136158

137-
If you want to have more control of the alert view you can add keys and values to the `RyeConfiguration` as shown here.
159+
If you want to have more control over the alert view, you can add keys and values to the `RyeConfiguration` dictionary as shown below:
138160

139161
```swift
140162
import Rye
@@ -145,10 +167,11 @@ let ryeConfiguration: RyeConfiguration = [
145167
Rye.Configuration.Key.animationType: Rye.AnimationType.fadeInOut
146168
]
147169

148-
let rye = RyeViewController.init(viewType: .standard(configuration: ryeConfiguration),
149-
at: .bottom(inset: 16))
170+
let rye = RyeViewController(
171+
viewType: .standard(configuration: ryeConfiguration),
172+
at: .bottom(inset: 16)
173+
)
150174
rye.show()
151-
152175
```
153176

154177
### Display Rye with a Custom `UIView`
@@ -159,10 +182,10 @@ For even more control you can create your own subclass of `UIView` and use `.cus
159182
import Rye
160183
...
161184

162-
let customView = YourCustomViewHere()
163-
let rye = RyeViewController.init(viewType: .custom(customView))
164-
rye.show()
185+
let customView = YourCustomView()
186+
let rye = RyeViewController(viewType: .custom(customView))
165187

188+
rye.show()
166189
```
167190

168191
### Dismiss Completion
@@ -172,8 +195,11 @@ If you would like to execute some code when the Rye alert is dismissed you can p
172195
import Rye
173196
...
174197
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
175-
let rye = RyeViewController.init(viewType: .standard(configuration: ryeConfiguration),
176-
at: .bottom(inset: 16))
198+
let rye = RyeViewController(
199+
viewType: .standard(configuration: ryeConfiguration),
200+
at: .bottom(inset: 16)
201+
)
202+
177203
rye.show(withDismissCompletion: {
178204
print("Goodbye from Rye, time to dy..die")
179205
})
@@ -189,9 +215,12 @@ import Rye
189215
var rye: RyeViewController?
190216

191217
let ryeConfiguration: RyeConfiguration = [Rye.Configuration.Key.text: "Message for the user"]
192-
rye = RyeViewController.init(dismissMode: .nonDismissable,
193-
viewType: .standard(configuration: ryeConfiguration),
194-
at: .bottom(inset: 16))
218+
rye = RyeViewController(
219+
dismissMode: .nonDismissable,
220+
viewType: .standard(configuration: ryeConfiguration),
221+
at: .bottom(inset: 16)
222+
)
223+
195224
rye?.show()
196225

197226
...at a later point in time
@@ -212,12 +241,14 @@ Rye supports three different `displayMode` values which can be passed when creat
212241

213242
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`)
214243

215-
#### Position
244+
#### Position and Alignment
216245

217-
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.
246+
You can specify if the Rye alert should be shown at the top or bottom of the screen. This is specified via the `position` parameter at init time. The `position` parameter takes an associated value, that allows you to define an inset.
218247

219248
By default Rye will calculate the safe area insets for you, so be sure to specify only the extra desired inset.
220249

250+
Similarly, you can set the alignment of the Rye via the `aligned` parameter. The `.leading` and `.trailing` alignments also take an associated value, that allows you to define an inset.
251+
If the `aligned` parameter is not specified at init time, it will default to `.center`
221252

222253
#### Animation Type
223254

@@ -255,7 +286,7 @@ If configuration is set to nil, a default configuration will be used. Any option
255286

256287
## ⚠️ Gotchas
257288

258-
In order to display a Rye message a `parentView` is needed to determine _in relation to what_ the Rye message is positioned.
289+
In order to display a Rye message, a `parentView` is needed to determine _in relation to what_ the Rye message is positioned.
259290

260291
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.
261292

0 commit comments

Comments
 (0)