Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
devmehmetates committed Nov 5, 2023
1 parent 770182c commit aac960e
Showing 1 changed file with 24 additions and 50 deletions.
74 changes: 24 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,44 @@
## How to install this package

+ Open your project on Xcode
+ Go to Project Tab and select "Package Dependencies"
+ Click "+" and search this package with use git clone url
+ Go to the Project Tab and select "Package Dependencies"
+ Click "+" and search this package with use git clone URL
+ Don't change anything and click Add Package
+ The package will be attached to the targeted application

## How to use this package
### Create a ViewModel conforming to the ErrorableViewModelProtocol
### Create a ViewModel conforming to the ErrorableBaseViewModel
<b>Note:<b> The class includes AnyObject and ObservableObject!

```swift
final class TestViewModel: ErrorableViewModelProtocol {
@Published var state: PageStates = .loading

func refresh() {
// TODO: Write here your refresh action
// TODO: Don't forget to update the state property in the refresh action
}
private final class ExampleViewModel: ErrorableBaseViewModel {
// Your actions will come here
}
```
### Create SwiftUI and conform to the ErrorableViewProtocol
- Set the ViewModel typealias to the view model we created
- Create the Viewmodel as @ObservedObject.
- Use the createErrorableView function according to your need.
### Create a SwiftUI view that conforms to the ErrorableView or ErrorableSheetView Protocols. (Usage is the same for both protocols.)
```swift
struct ContentView: ErrorableViewProtocol {
typealias Content = AnyView
typealias ViewModel = TestViewModel
@ObservedObject var viewModel: TestViewModel = TestViewModel()

var body: some View {
NavigationView {
createErrorableView(errorTitle: "Upps!", errorSubTitle: "We encountered an error.\n Please try again later!", errorSystemIcon: "minus.diamond.fill", errorButtonTitle: "Try Again") {
AnyView (
ScrollView {
ForEach(0..<100, id: \.self) { _ in
AsyncImage(url: URL(string: "https://picsum.photos/200")) { phase in
if let image = phase.image {
image
.resizable()
.scaledToFill()
} else {
Color.gray
}
}.frame(width: 300, height: 200, alignment: .center)
.clipped()
}
}.frame(width: UIScreen.main.bounds.width)
)
}
.navigationTitle("Example")
}.onAppear {
Task { @MainActor in
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
viewModel.state = .failure
}
}
private struct SimpleExampleView: ErrorableView {
typealias ViewModel = ExampleViewModel
@ObservedObject var viewModel: ExampleViewModel = ExampleViewModel()

var content: some View {
VStack {
Text("Loaded Statement!")
}
}
}
```

## Demo Images
## ErrorableView Demo Images
<div>
<img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/5dc340f8-e455-46f9-9504-e3fcc6faf3a5">
<img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/f4c4b650-87fb-4b51-a305-c550ba2db85b">
<img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/f28af8bb-dea2-4581-9770-ce7879e99925">
</div>

## ErrorableSheetView Demo Images
<div>
<img width = 255 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/f30a0d95-53a8-42e0-a21d-db67ef093b0e">
<img width = 255 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/269ad7d4-ae61-40bc-a731-7dd87f116a4d">
<img width = 255 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/155a174f-dade-4bba-ba4b-dec12dfa6d7f">
<img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/5dc340f8-e455-46f9-9504-e3fcc6faf3a5">
<img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/3631f105-c1c2-4b71-9895-6a442e2b2dca">
<img width = 255 height = 525 src="https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/f28af8bb-dea2-4581-9770-ce7879e99925">
</div>

0 comments on commit aac960e

Please sign in to comment.