@@ -7,22 +7,26 @@ struct NoticeModifier: ViewModifier {
77
88 /// Notice object to render
99 ///
10- let notice : Notice
10+ @ Binding var notice : Notice ?
1111
1212 func body( content: Content ) -> some View {
13- content. overlay (
14- // Geometry reader to provide the correct view width.
15- GeometryReader { geometry in
16- // VStack with spacer to push content to the bottom
17- VStack {
18- Spacer ( )
19-
20- // NoticeView wrapper
21- NoticeAlert ( notice: notice, width: geometry. size. width)
22- . fixedSize ( horizontal: false , vertical: true )
13+ if let notice = notice {
14+ content. overlay (
15+ // Geometry reader to provide the correct view width.
16+ GeometryReader { geometry in
17+ // VStack with spacer to push content to the bottom
18+ VStack {
19+ Spacer ( )
20+
21+ // NoticeView wrapper
22+ NoticeAlert ( notice: notice, width: geometry. size. width)
23+ . fixedSize ( horizontal: false , vertical: true )
24+ }
2325 }
24- }
25- )
26+ )
27+ } else {
28+ content
29+ }
2630 }
2731}
2832
@@ -115,7 +119,7 @@ private extension NoticeAlert {
115119extension View {
116120 /// Shows the provided notice in front of the view.
117121 ///
118- func notice( _ notice: Notice ) -> some View {
122+ func notice( _ notice: Binding < Notice ? > ) -> some View {
119123 self . modifier ( NoticeModifier ( notice: notice) )
120124 }
121125}
@@ -125,7 +129,7 @@ extension View {
125129struct NoticeModifier_Previews : PreviewProvider {
126130 static var previews : some View {
127131 Rectangle ( ) . foregroundColor ( . white)
128- . notice (
132+ . notice ( . constant (
129133 . init( title: " API Error " ,
130134 subtitle: " Restricted Access " ,
131135 message: " Your photos could not be downloaded, please ask for the correct permissions! " ,
@@ -135,7 +139,7 @@ struct NoticeModifier_Previews: PreviewProvider {
135139 actionHandler: {
136140 print ( " Retry " )
137141 } )
138- )
142+ ) )
139143 . environment ( \. colorScheme, . light)
140144 . previewDisplayName ( " Light Content " )
141145 }
0 commit comments