Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/husbig/TransactionAlert
https://github.com/husbig/TransactionAlert
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/husbig/TransactionAlert
- Owner: husbig
- License: mit
- Created: 2021-01-05T05:12:06.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-05T13:47:30.000Z (about 4 years ago)
- Last Synced: 2024-08-11T17:09:19.148Z (5 months ago)
- Language: Swift
- Size: 769 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swiftui - huseyinbagana/TransactionAlert - Simple SwiftUI Alert (Samples)
README
TransactionAlert
===========Animated Alert written in SwiftUI.
Easy to use
----### Get Started
1. Add a **TAViewModel** instance as an *environment object* to your Root View in you *SceneDelegate*
```Swift
// 1.1 Create the model and set environmentObject
let contentView = ContentView().environmentObject(TAViewModel())
//Common SwiftUI code to add the rootView in your rootViewController
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(
rootView: contentView
)
self.window = window
window.makeKeyAndVisible()
}
```
2. Add the **Transaction Alert** to your *Root View*```Swift
struct ContentView: View {var body: some View {
...
.transactionAlert()
}
}
```
3. In your views add a reference to the *environment object* and than just call the `.set(state:)` func whenever you want like this:```Swift
@EnvironmentObject var taViewModel: TAViewModel...
Button(action: {
taViewModel.set(.error(style:--customstyle--))
}, label: {
Text("Show Transaction Alert")
})
```
3. For hide alert just call the `.hide()` func whenever you want like this:```Swift
...Button(action: {
taViewModel.hide()
}, label: {
Text("Hide Transaction Alert")
})
```
### Alert States
```Swift
...taViewModel.set(.start(...)) // Question
taViewModel.set(.loading(...)) // Loading
taViewModel.set(.error(...)) // Error
taViewModel.set(.success(...)) // Success
taViewModel.set(.custom(...)) // Also you can set custom view with style```
## Installation#### Requirements
- iOS 14.0+
- Xcode 11.2+
- Swift 5+#### Via Swift Package Manager
In Xcode 11 or grater, in you project, select: `File > Swift Packages > Add Pacakage Dependency`.