Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
devmehmetates committed Mar 1, 2024
1 parent 4e27ff6 commit b725979
Showing 1 changed file with 61 additions and 77 deletions.
138 changes: 61 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,96 +9,80 @@
+ The package will be attached to the targeted application

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

```swift
private final class ExampleViewModel: ErrorableBaseViewModel {
// Your actions will come here
}
```
### Create some SwiftUI view that conforms to the ErrorableView
### Just use The "ErrorableViewModifier" with an $pageState property
```swift
@available(iOS 15.0, *)
private struct ExampleContentView: View {
struct TestView: View {
@State private var pageState: PageStates = .loading

var body: some View {
NavigationView {
ScrollView {
ForEach(0..<100, id: \.self) { _ in
AsyncImage(url: URL(string: "https://picsum.photos/1000")) { phase in
if let image = phase.image {
image
.resizable()
.scaledToFill()
} else {
Color.gray
}
}.frame(height: 200, alignment: .center)
.clipped()
NavigationView {
ScrollView {
ForEach(0..<100, id: \.self) { _ in
AsyncImage(url: URL(string: "https://picsum.photos/1000")) { phase in
if let image = phase.image {
image
.resizable()
.scaledToFill()
} else {
Color.gray
}
}.frame(height: 200, alignment: .center)
.clipped()
}
}.navigationTitle("Example Content")
}
.modifier(ErrorableViewModifier(pageState: $pageState) { // Like this
DefaultErrorView(type: .sheet) {
pageState = .loading
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
pageState = .successful
}
}
}.navigationTitle("Example Content")
}
}
}

@available(iOS 15.0, *)
private struct OnPageExampleView: ErrorableView {
@ObservedObject var viewModel: ExampleViewModel = ExampleViewModel()

var content: some View {
ExampleContentView()
}

var errorStateConfigModel: ErrorStateConfigureModel {
ErrorStateConfigureModel.Builder()
.buttonAction {
viewModel.refreshPage()
}.build()
})
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
pageState = .failure
}
}
}
}
```
## Useful Tips
This package allows you to manage your page error state easily. But actually, it's useful. What do you get to know?

@available(iOS 15.0, *)
private struct SheetExampleView: ErrorableView {
@ObservedObject var viewModel: ExampleViewModel = ExampleViewModel()

var content: some View {
ExampleContentView()
}

var errorStateConfigModel: ErrorStateConfigureModel {
ErrorStateConfigureModel.Builder()
.buttonAction {
viewModel.refreshPage()
}.build()
}

var errorPresentType: ErrorPresentTypes { .sheet }
- Generic Error Page Support:
The Package includes a DefaultErrorPage but you don't want to use it. Use the ErrorableView protocol, and create your error page.
```swift
protocol ErrorableView: View {
var type: ErrorPresentTypes { get set }
}

@available(iOS 15.0, *)
private struct FullScreenExampleView: ErrorableView {
@ObservedObject var viewModel: ExampleViewModel = ExampleViewModel()

var content: some View {
ExampleContentView()
}

var errorStateConfigModel: ErrorStateConfigureModel {
ErrorStateConfigureModel.Builder()
.buttonAction {
viewModel.refreshPage()
}.build()
```
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.
```swift
.modifier(ErrorableViewModifier(pageState: $viewModel.pageState) { // Like this
YourView() {
viewModel.reload()
}

var errorPresentType: ErrorPresentTypes { .fullScreen }
})
```
- Fully Customisable Error Page:
The package includes a customizable ErrorPage named DefaultErrorPage. You can use that uiModel to update DefaultErrorPage.
```swift
@frozen public struct DefaultErrorPageUIModel {
var title: LocalizedStringKey
var subtitle: LocalizedStringKey?
var icon: String?
var systemName: String?
var buttonTitle: LocalizedStringKey?
}
```

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

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

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

0 comments on commit b725979

Please sign in to comment.