@@ -12,10 +12,14 @@ import SwiftUI
12
12
struct ModalViewPresenterViewModifier < PresentationState: ModalPresentationState > : ViewModifier {
13
13
@EnvironmentObject var modalViewRouter : ModalViewRouter < PresentationState >
14
14
15
- private let options : [ BottomSheet . Options ]
15
+ @ Binding private var options : [ BottomSheet . Options ]
16
16
17
17
init ( options: [ BottomSheet . Options ] = [ ] ) {
18
- self . options = options
18
+ self . _options = . constant( options)
19
+ }
20
+
21
+ init ( options: Binding < [ BottomSheet . Options ] > ) {
22
+ self . _options = options
19
23
}
20
24
21
25
public func body( content: Content ) -> some View {
@@ -44,8 +48,26 @@ public extension View {
44
48
/// Works with the implementation of the `ModalPresentationState` protocol that represents all modals that can be shown with this presenter.
45
49
/// Need to set an environmentObject of `ModalViewRouter<S: ModalPresentationState>` before using this modifier otherwise an error will occur.
46
50
///
51
+ /// - parameters:
52
+ /// - presentationStateType: A type that represent possible states to show
53
+ /// - options: Modal view options to customise it
54
+ ///
55
+ func modalViewPresenter< PresentationState: ModalPresentationState > ( presentationStateType: PresentationState . Type ,
56
+ options: [ BottomSheet . Options ] = [ ] ) -> some View {
57
+ self . modifier ( ModalViewPresenterViewModifier < PresentationState > ( options: options) )
58
+ }
59
+
60
+ /// A view modifier to present modal views from any view.
61
+ ///
62
+ /// Works with the implementation of the `ModalPresentationState` protocol that represents all modals that can be shown with this presenter.
63
+ /// Need to set an environmentObject of `ModalViewRouter<S: ModalPresentationState>` before using this modifier otherwise an error will occur.
64
+ ///
65
+ /// - parameters:
66
+ /// - presentationStateType: A type that represent possible states to show
67
+ /// - options: A options binding to allow to change the modal options
68
+ ///
47
69
func modalViewPresenter< PresentationState: ModalPresentationState > ( presentationStateType: PresentationState . Type ,
48
- options: [ BottomSheet . Options ] ) -> some View {
70
+ options: Binding < [ BottomSheet . Options ] > ) -> some View {
49
71
self . modifier ( ModalViewPresenterViewModifier < PresentationState > ( options: options) )
50
72
}
51
73
}
@@ -61,6 +83,7 @@ struct ModalViewPresenterViewModifier_Previews: PreviewProvider {
61
83
@StateObject private var testModalViewRouter = TestModalViewRouter ( )
62
84
63
85
@State var color : Color = . red
86
+ @State var options : [ BottomSheet . Options ] = [ . disableSwipeToDismiss, . tapToDismiss]
64
87
65
88
var body : some View {
66
89
ZStack {
@@ -70,12 +93,13 @@ struct ModalViewPresenterViewModifier_Previews: PreviewProvider {
70
93
testModalViewRouter. setModal ( state: . text( " Hello World! " ) ,
71
94
type: . customSheet) {
72
95
color = [ Color . red, . purple, . blue, . yellow, . green] . randomElement ( ) ?? . orange
96
+
97
+ options = [ . tapToDismiss]
73
98
}
74
99
}
75
100
}
76
101
. modalViewPresenter ( presentationStateType: TestModalPresentationState . self,
77
- options: [ . tapToDismiss,
78
- . maxHeight( 500 ) ] )
102
+ options: $options)
79
103
. environmentObject ( testModalViewRouter)
80
104
}
81
105
}
0 commit comments