Skip to content

Commit b725979

Browse files
Update README.md
1 parent 4e27ff6 commit b725979

File tree

1 file changed

+61
-77
lines changed

1 file changed

+61
-77
lines changed

README.md

+61-77
Original file line numberDiff line numberDiff line change
@@ -9,96 +9,80 @@
99
+ The package will be attached to the targeted application
1010

1111
## How to use this package
12-
### Create a ViewModel conforming to the ErrorableBaseViewModel
13-
<b>Note:<b> The class includes AnyObject and ObservableObject!
14-
15-
```swift
16-
private final class ExampleViewModel: ErrorableBaseViewModel {
17-
// Your actions will come here
18-
}
19-
```
20-
### Create some SwiftUI view that conforms to the ErrorableView
12+
### Just use The "ErrorableViewModifier" with an $pageState property
2113
```swift
22-
@available(iOS 15.0, *)
23-
private struct ExampleContentView: View {
14+
struct TestView: View {
15+
@State private var pageState: PageStates = .loading
16+
2417
var body: some View {
25-
NavigationView {
26-
ScrollView {
27-
ForEach(0..<100, id: \.self) { _ in
28-
AsyncImage(url: URL(string: "https://picsum.photos/1000")) { phase in
29-
if let image = phase.image {
30-
image
31-
.resizable()
32-
.scaledToFill()
33-
} else {
34-
Color.gray
35-
}
36-
}.frame(height: 200, alignment: .center)
37-
.clipped()
18+
NavigationView {
19+
ScrollView {
20+
ForEach(0..<100, id: \.self) { _ in
21+
AsyncImage(url: URL(string: "https://picsum.photos/1000")) { phase in
22+
if let image = phase.image {
23+
image
24+
.resizable()
25+
.scaledToFill()
26+
} else {
27+
Color.gray
28+
}
29+
}.frame(height: 200, alignment: .center)
30+
.clipped()
31+
}
32+
}.navigationTitle("Example Content")
33+
}
34+
.modifier(ErrorableViewModifier(pageState: $pageState) { // Like this
35+
DefaultErrorView(type: .sheet) {
36+
pageState = .loading
37+
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
38+
pageState = .successful
39+
}
3840
}
39-
}.navigationTitle("Example Content")
40-
}
41-
}
42-
}
43-
44-
@available(iOS 15.0, *)
45-
private struct OnPageExampleView: ErrorableView {
46-
@ObservedObject var viewModel: ExampleViewModel = ExampleViewModel()
47-
48-
var content: some View {
49-
ExampleContentView()
50-
}
51-
52-
var errorStateConfigModel: ErrorStateConfigureModel {
53-
ErrorStateConfigureModel.Builder()
54-
.buttonAction {
55-
viewModel.refreshPage()
56-
}.build()
41+
})
42+
.onAppear {
43+
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
44+
pageState = .failure
45+
}
46+
}
5747
}
5848
}
49+
```
50+
## Useful Tips
51+
This package allows you to manage your page error state easily. But actually, it's useful. What do you get to know?
5952

60-
@available(iOS 15.0, *)
61-
private struct SheetExampleView: ErrorableView {
62-
@ObservedObject var viewModel: ExampleViewModel = ExampleViewModel()
63-
64-
var content: some View {
65-
ExampleContentView()
66-
}
67-
68-
var errorStateConfigModel: ErrorStateConfigureModel {
69-
ErrorStateConfigureModel.Builder()
70-
.buttonAction {
71-
viewModel.refreshPage()
72-
}.build()
73-
}
74-
75-
var errorPresentType: ErrorPresentTypes { .sheet }
53+
- Generic Error Page Support:
54+
The Package includes a DefaultErrorPage but you don't want to use it. Use the ErrorableView protocol, and create your error page.
55+
```swift
56+
protocol ErrorableView: View {
57+
var type: ErrorPresentTypes { get set }
7658
}
77-
78-
@available(iOS 15.0, *)
79-
private struct FullScreenExampleView: ErrorableView {
80-
@ObservedObject var viewModel: ExampleViewModel = ExampleViewModel()
81-
82-
var content: some View {
83-
ExampleContentView()
84-
}
85-
86-
var errorStateConfigModel: ErrorStateConfigureModel {
87-
ErrorStateConfigureModel.Builder()
88-
.buttonAction {
89-
viewModel.refreshPage()
90-
}.build()
59+
```
60+
This protocol only wants to create a type property for your error page presentation state. If your view comformed the protocol you'll use this modifier code block under the below.
61+
```swift
62+
.modifier(ErrorableViewModifier(pageState: $viewModel.pageState) { // Like this
63+
YourView() {
64+
viewModel.reload()
9165
}
92-
93-
var errorPresentType: ErrorPresentTypes { .fullScreen }
66+
})
67+
```
68+
- Fully Customisable Error Page:
69+
The package includes a customizable ErrorPage named DefaultErrorPage. You can use that uiModel to update DefaultErrorPage.
70+
```swift
71+
@frozen public struct DefaultErrorPageUIModel {
72+
var title: LocalizedStringKey
73+
var subtitle: LocalizedStringKey?
74+
var icon: String?
75+
var systemName: String?
76+
var buttonTitle: LocalizedStringKey?
9477
}
9578
```
9679

97-
## Sheet Type
80+
## Examples
81+
### Sheet Type
9882
https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/1fe9e28a-8ba3-48b8-8d85-b2eb4c6aa672
9983

100-
## OnPage Type
84+
### OnPage Type
10185
https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/2c579c96-adec-4d6e-9739-1892d97666aa
10286

103-
## Fullscreen Type
87+
### Fullscreen Type
10488
https://github.com/devmehmetates/ErrorableView-SwiftUI/assets/74152011/6e34332f-6c24-489d-8bd2-bfd5ab2fb027

0 commit comments

Comments
 (0)