Skip to content

Commit

Permalink
add custom extension
Browse files Browse the repository at this point in the history
  • Loading branch information
devmehmetates committed Mar 20, 2024
1 parent 66e1fe8 commit 1a86d6e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Sources/ErrorableView/Abstract/ErrorableViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

import SwiftUI

public extension View {
@ViewBuilder
func errorableView<Content: ErrorableView>(pageState: Binding<PageStates>, @ViewBuilder content: () -> Content) -> some View {
self.modifier(ErrorableViewModifier(pageState: pageState) {
content()
})
}
}

public struct ErrorableViewModifier<ErrorContent: ErrorableView>: ViewModifier {
@State private var sheetTrigger: Bool = false
@Binding var pageState: PageStates
Expand Down Expand Up @@ -93,14 +102,14 @@ struct TestView: View {
}
}.navigationTitle("Example Content")
}
.modifier(ErrorableViewModifier(pageState: $pageState) {
.errorableView(pageState: $pageState) {
DefaultErrorView(type: .sheet) {
pageState = .loading
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
pageState = .successful
}
}
})
}
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
pageState = .failure
Expand Down

0 comments on commit 1a86d6e

Please sign in to comment.