Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Apr 24, 2024
1 parent 06a2f32 commit d63c071
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 4 deletions.
56 changes: 52 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,69 @@ https://github.com/danielsaidi/SystemNotification.git

## Getting started

After adding SystemNotification to your project, you can add a system notification to a view hierarchy just as you add a `sheet`, `alert` and `fullScreenModal`:
You can add a system notification to any view, just as you add a `sheet`, `alert` and `fullScreenModal`, by applying a `.systemNotification` view modifier with either state or a `SystemNotificationContext` instance.

State-based notifications take a boolean binding and a view builder:

```swift
import SystemNotification

struct MyView: View {

@State
var isActive = false

var body: some View {
Text("Hello, world")
.systemNotification(...)
VStack {
Button("Show notification") {
isActive = true
}
}
.systemNotification(isActive: $isActive) {
Text("You can use any custom content view")
.padding()
}
}
}
```

You can use both state- and context and message-based notifications and style your notifications to great extent.
Context-based notifications just take a `SystemNotificationContext` instance and can show different notifications with a single view modifier:

```swift
import SystemNotification

struct MyView: View {

@StateObject
var notification = SystemNotificationContext()

var body: some View {
VStack {
Button("Show text") {
notification.present {
Text("Context-based notifications are more flexible.")
.padding()
.multilineTextAlignment(.center)
}
}
Button("Show message") {
notification.present {
SystemNotificationMessage(
icon: Text("👍"),
title: "Great job!",
text: "You presented a native-looking message, with an icon, title and text"
)
}
}
}
.systemNotification(notification)
}
}
```

The `SystemNotificationMessage` view can be used to easily mimic a native notification message, with an icon, title and text.

You can use the `.systemNotificationConfiguration` and `.systemNotificationStyle` view modifiers to configure and style the notification, and the `.systemNotificationMessageStyle` to style the message.

For more information, please see the [getting started guide][Getting-Started].

Expand Down
59 changes: 59 additions & 0 deletions Sources/SystemNotification/SystemNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public struct SystemNotification<Content: View>: View {
content(isActive)
.background(style.backgroundColor)
.background(style.backgroundMaterial)
.compositingGroup()
.cornerRadius(style.cornerRadius ?? 1_000)
.shadow(
color: style.shadowColor,
Expand Down Expand Up @@ -215,3 +216,61 @@ private extension SystemNotification {

return Preview()
}

#Preview("README #1") {

struct MyView: View {

@State
var isActive = false

var body: some View {
VStack {
Button("Show notification") {
isActive = true
}
}
.systemNotification(isActive: $isActive) {
Text("You can use any custom content view")
.padding()
}
}
}

return MyView()
}


#Preview("README #2") {

struct MyView: View {

@StateObject
var notification = SystemNotificationContext()

var body: some View {
VStack {
Button("Show text") {
notification.present {
Text("Context-based notifications are more flexible.")
.padding()
.multilineTextAlignment(.center)
}
}
Button("Show message") {
notification.present {
SystemNotificationMessage(
icon: Text("👍"),
title: "Great job!",
text: "You presented a native-looking message, with an icon, title and text"
)
}
}
}
.systemNotification(notification)
.systemNotificationConfiguration(<#T##configuration: SystemNotificationConfiguration##SystemNotificationConfiguration#>)
}
}

return MyView()
}

0 comments on commit d63c071

Please sign in to comment.