-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add alert context and improve sheet context
- Loading branch information
1 parent
54de41c
commit ad0c8b3
Showing
31 changed files
with
275 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Alerts | ||
|
||
`SwiftUIKit` makes it easier to work with alerts. | ||
|
||
|
||
## AlertContext | ||
|
||
The `AlertContext` class embeds the `isPresented` binding logic and can be used to present any `Alert` or `AlertPresentable`, which means that you can use it for a wide range of alerts and custom types within your apps. | ||
|
||
You could for instance implement a global set of alerts in an `AppAlerts` enum or screen-specific screens in e.g. a `SettingsAlert` enum, and use the same `AlertContext` for all alerts. | ||
|
||
Take a look at the demo app for an example on how to use this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
# Sheets | ||
|
||
`SwiftUIKit` makes managing modal sheets eaiser. | ||
`SwiftUIKit` makes it easier to work with modal sheets. | ||
|
||
The `SheetContext` class embeds the `isPresented` binding logic and can be used to present any `SheetPresentable`, which means that you can use it for a wide range of sheets. | ||
|
||
You could for instance implement a global set of sheets in an `AppSheets` enum or screen-specific screens in e.g. a `SettingsEnum` enum, and use `SheetContext` for both. | ||
## SheetContext | ||
|
||
The `SheetContext` class embeds the `isPresented` binding logic and can be used to present any `SheetPresentable`, which means that you can use it for a wide range of sheets and custom types within your apps. | ||
|
||
You could for instance implement a global set of sheets in an `AppSheets` enum or screen-specific screens in e.g. a `SettingsSheet` enum, and use the same `SheetContext` for all sheets. | ||
|
||
Take a look at the demo app for an example on how to use this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// AlertContext.swift | ||
// SwiftUIKit | ||
// | ||
// Created by Daniel Saidi on 2020-06-07. | ||
// Copyright © 2020 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import Combine | ||
import SwiftUI | ||
|
||
/** | ||
This context can be used to present any `Alert`, as well as | ||
anything that implements`AlertPresentable`. | ||
|
||
`AlertPresentable` can be implemented by any enum, class or | ||
struct that can provide an `alert` to the context. It means | ||
that you can implement custom alerts in many different ways | ||
and present all of them the same way, using this context. | ||
|
||
To use this context within your view, create an instance of | ||
it then call any of the `present(_ alert: AlertPresentable)` | ||
or `present(_ alert: Alert)` to present alerts. To bind the | ||
alert to views, use the `alert` modifier as you normally do: | ||
|
||
```swift | ||
.alert(isPresented: $alertContext.isActive, content: alertContext.alert) | ||
``` | ||
*/ | ||
public class AlertContext: ObservableObject { | ||
|
||
public init() {} | ||
|
||
@Published public var isActive = false | ||
|
||
public private(set) var alertView: Alert? { | ||
didSet { isActive = alertView != nil } | ||
} | ||
|
||
public func alert() -> Alert { | ||
alertView ?? Alert(title: Text("")) | ||
} | ||
|
||
public func present(_ alert: Alert) { | ||
alertView = alert | ||
} | ||
|
||
public func present(_ alert: AlertPresentable) { | ||
alertView = alert.alert | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// AlertPresentable.swift | ||
// SwiftUIKit | ||
// | ||
// Created by Daniel Saidi on 2020-06-07. | ||
// Copyright © 2020 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/** | ||
This protocol can be implemented by anything (e.g. a custom | ||
enum, struct or a class) that can provide an alert. | ||
*/ | ||
public protocol AlertPresentable { | ||
|
||
var alert: Alert { get } | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.