Skip to content

Commit c7fc4d0

Browse files
committed
update README
1 parent 3443d2d commit c7fc4d0

File tree

1 file changed

+114
-41
lines changed

1 file changed

+114
-41
lines changed

README.md

Lines changed: 114 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fcalimarkus%2FJDStatusBarNotification%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/calimarkus/JDStatusBarNotification)
44

5-
Highly customizable & feature rich notifications displayed below the status bar / the notch.
5+
Highly customizable & feature rich notifications displayed below the status bar / notch / Island. Written in Swift, compatible for Obj-C! Please open a [Github issue](https://github.com/calimarkus/JDStatusBarNotification/issues), if you think anything is missing or wrong.
66

77
* Customizable colors, fonts & animations with multiple built-in styles
88
* Interactive & interuptable Drag-to-Dismiss
@@ -17,15 +17,11 @@ Highly customizable & feature rich notifications displayed below the status bar
1717
* A progress bar
1818
* Custom views (UIView or SwiftUI View)
1919

20-
Written in Swift, compatible for Obj-C!
21-
22-
Please open a [Github issue](https://github.com/calimarkus/JDStatusBarNotification/issues), if you think anything is missing or wrong.
23-
24-
Here's some examples of the possibilities (the pill style is the default):
20+
Some examples of the possibilities - the pill style is the default:
2521

2622
![examples](https://user-images.githubusercontent.com/807039/173831886-d7c8cca9-9274-429d-b924-78f21a4f6092.jpg)
2723

28-
Full-Width styles in action (the pill styles support the same features / animations):
24+
Full-Width styles in action - the above pill style supports the same features and animations:
2925

3026
| Drag to dismiss | Activity & Progress Bars | Custom styles |
3127
| ------------- | ------------- | ------------- |
@@ -59,39 +55,67 @@ See [CHANGELOG.md](CHANGELOG.md)
5955

6056
## Getting started
6157

62-
`NotificationPresenter` is a singleton. You don't need to initialize it anywhere. All examples here are written in Swift. But everything can be called from Objective-C too.
58+
All examples here are written in Swift. But everything can be called from Objective-C too. Also checkout the example project, which has many examples and includes a convenient style editor to build a custom style.
6359

64-
Also checkout the example project, which has many examples and includes a convenient style editor.
60+
### SwiftUI state-driven presentation
6561

66-
Here's some usage examples:
67-
68-
### Showing a text notification
62+
#### Showing a simple text notification
6963

7064
```swift
71-
NotificationPresenter.shared.present("Hello World")
65+
var body: some View {
66+
Button("Present/dismiss") {
67+
isPresented.toggle()
68+
}
69+
.notification(title: "Hello World", isPresented: $isPresented)
70+
}
71+
```
7272

73-
// with completion
74-
NotificationPresenter.shared.present("Hello World") { presenter in
75-
// ...
73+
#### Showing a styled notification with subtitle, activity and/or progress
74+
75+
```swift
76+
var body: some View {
77+
Button("Present/dismiss") {
78+
isPresented.toggle()
79+
}
80+
.notification(title: "A text",
81+
subtitle: "with a little subtitle.",
82+
isPresented: $isPresented,
83+
isShowingActivity: $activity, // toggles an activity indicator on/off
84+
progress: $progress, // sets the percentage of a progress bar
85+
includedStyle: .success) // picks a predefined style
7686
}
7787
```
7888

79-
### Showing a SwiftUI based notification
89+
90+
#### Showing a custom view as notification
8091

8192
```swift
82-
NotificationPresenter.shared.presentSwiftView {
83-
Text("Hi from Swift!")
93+
var body: some View {
94+
Button("Present/dismiss") {
95+
isPresented.toggle()
96+
}
97+
.notification(isPresented: $isPresented) {
98+
Text("👋 Hi there!")
99+
.font(.subheadline)
100+
.foregroundStyle(.white)
101+
}
84102
}
103+
```
104+
105+
### Manual presentation (from Swift or ObjC)
106+
107+
#### Showing a text notification
108+
109+
```swift
110+
NotificationPresenter.shared.present("Hello World")
85111

86112
// with completion
87-
NotificationPresenter.shared.presentSwiftView {
88-
Text("Hi from Swift!")
89-
} completion: { presenter in
90-
// ...
113+
NotificationPresenter.shared.present("Hello World") { presenter in
114+
// ...
91115
}
92116
```
93117

94-
### Dismissing a notification
118+
#### Dismissing a notification
95119

96120
```swift
97121
NotificationPresenter.shared.dismiss()
@@ -102,7 +126,7 @@ NotificationPresenter.shared.dismiss(after: 0.5) { presenter in
102126
}
103127
```
104128

105-
### Showing activity
129+
#### Showing activity
106130

107131
```swift
108132
NotificationPresenter.shared.present("")
@@ -111,7 +135,7 @@ NotificationPresenter.shared.displayActivityIndicator(true)
111135

112136
![activity](https://user-images.githubusercontent.com/807039/175884729-c6255d41-4728-4bcb-bf72-fb12db01b5d5.gif)
113137

114-
### Showing a custom left view
138+
#### Showing a custom left view
115139

116140
```swift
117141
let image = UIImageView(image: UIImage(systemName: "gamecontroller.fill"))
@@ -121,7 +145,7 @@ NotificationPresenter.shared.displayLeftView(image)
121145

122146
![leftview](https://user-images.githubusercontent.com/807039/175884751-c93ffd31-a436-43d2-9eed-82d7cb23d8f6.gif)
123147

124-
### Showing progress
148+
#### Showing progress
125149

126150
```swift
127151
NotificationPresenter.shared.present("Animating Progress…") { presenter in
@@ -136,7 +160,7 @@ NotificationPresenter.shared.displayProgressBar(at: 0.0)
136160

137161
![progress](https://user-images.githubusercontent.com/807039/175886588-e1aba466-85fa-4e32-951a-cd368c7d553d.gif)
138162

139-
### Using other included styles
163+
#### Using other included styles
140164

141165
There's a few included styles you can easily use with the following API:
142166

@@ -147,7 +171,22 @@ NotificationPresenter.shared.present("Yay, it works!",
147171

148172
![itworks](https://user-images.githubusercontent.com/807039/175888059-3beeb659-b561-4e7c-9c66-6fbc683ae152.jpg)
149173

150-
### Using a custom UIView
174+
#### Showing a custom SwiftUI view (Swift only)
175+
176+
```swift
177+
NotificationPresenter.shared.presentSwiftView {
178+
Text("Hi from Swift!")
179+
}
180+
181+
// with completion
182+
NotificationPresenter.shared.presentSwiftView {
183+
Text("Hi from Swift!")
184+
} completion: { presenter in
185+
// ...
186+
}
187+
```
188+
189+
#### Using a custom UIView (Swift or ObjC)
151190

152191
If you want full control over the notification content and styling, you can use your own custom UIView.
153192

@@ -168,6 +207,30 @@ NotificationPresenter.shared.presentCustomView(button)
168207

169208
You have the option to easily create & use fully customized styles.
170209

210+
### From SwiftUI
211+
212+
Modify the style in a `NotificationStyleClosure`:
213+
214+
```swift
215+
var body: some View {
216+
Button("Present/dismiss") {
217+
isPresented.toggle()
218+
}
219+
.notification(isPresented: $isPresented, style: {
220+
let s = $0.backgroundStyle
221+
s.backgroundColor = .black
222+
s.pillStyle.minimumWidth = 150
223+
s.pillStyle.height = 44
224+
}) {
225+
Text("👋 Hi there!")
226+
.font(.subheadline)
227+
.foregroundStyle(.white)
228+
}
229+
}
230+
```
231+
232+
### Manually
233+
171234
The ``PrepareStyleClosure`` provides a copy of the default style, which can then be modified. See the ``StatusBarNotificationStyle`` API for all options.
172235

173236
```swift
@@ -195,26 +258,36 @@ Or checkout the example project, which contains a full style editor. You can twe
195258

196259
### Background Styles
197260

198-
There's two supported background styles:
261+
There's two supported `StatusBarNotificationBackgroundType`'s:
199262

200263
```swift
201-
/// The background is a floating pill around the text. The pill size and appearance can be customized. This is the default.
202-
StatusBarNotificationBackgroundType.pill
203-
/// The background covers the full display width and the full status bar + navbar height.
204-
StatusBarNotificationBackgroundType.fullWidth
264+
enum {
265+
/// The background is a floating pill around the text.
266+
/// The pill size and appearance can be customized. This is the default.
267+
.pill,
268+
269+
/// The background covers the full display width and the full status bar + navbar height.
270+
.fullWidth
271+
}
205272
```
206273

207274
### Animation Types
208275

209-
The supported animation types:
276+
The supported `StatusBarNotificationAnimationType`'s:
210277

211278
```swift
212-
/// Slide in from the top of the screen and slide back out to the top. This is the default.
213-
StatusBarNotificationAnimationType.move,
214-
/// Fade-in and fade-out in place. No movement animation.
215-
StatusBarNotificationAnimationType.fade,
216-
/// Fall down from the top and bounce a little bit, before coming to a rest. Slides back out to the top.
217-
StatusBarNotificationAnimationType.bounce,
279+
enum {
280+
/// Slide in from the top of the screen and slide
281+
/// back out to the top. This is the default.
282+
.move,
283+
284+
/// Fade-in and fade-out in place. No movement animation.
285+
.fade,
286+
287+
/// Fall down from the top and bounce a little bit, before
288+
/// coming to a rest. Slides back out to the top.
289+
.bounce
290+
}
218291
```
219292

220293
## Troubleshooting

0 commit comments

Comments
 (0)