@@ -5,6 +5,21 @@ import SwiftUI
55/// Consists of two date pickers laid out vertically.
66///
77struct RangedDatePicker : View {
8+
9+ @Environment ( \. presentationMode) var presentation
10+
11+ /// Closure invoked when the the custom date range has been confirmed.
12+ ///
13+ var datesSelected : ( ( _ start: Date , _ end: Date ) -> Void ) ?
14+
15+ /// Start date binding variable
16+ ///
17+ @State private var startDate = Date ( )
18+
19+ /// End date binding variable
20+ ///
21+ @State private var endDate = Date ( )
22+
823 var body : some View {
924 NavigationView {
1025 ScrollView {
@@ -17,7 +32,7 @@ struct RangedDatePicker: View {
1732
1833 Divider ( )
1934
20- DatePicker ( " " , selection: . constant ( Date ( ) ) , in: ... Date ( ) , displayedComponents: [ . date] )
35+ DatePicker ( " " , selection: $startDate , in: ... Date ( ) , displayedComponents: [ . date] )
2136 . datePickerStyle ( . graphical)
2237 . accentColor ( Color ( . brand) )
2338
@@ -28,7 +43,7 @@ struct RangedDatePicker: View {
2843
2944 Divider ( )
3045
31- DatePicker ( " " , selection: . constant ( Date ( ) ) , in: ... Date ( ) , displayedComponents: [ . date] )
46+ DatePicker ( " " , selection: $endDate , in: ... Date ( ) , displayedComponents: [ . date] )
3247 . datePickerStyle ( . graphical)
3348 . accentColor ( Color ( . brand) )
3449 }
@@ -47,14 +62,15 @@ struct RangedDatePicker: View {
4762 }
4863 ToolbarItem ( placement: . confirmationAction) {
4964 Button ( action: {
50- // TODO: Send apply action
65+ presentation. wrappedValue. dismiss ( )
66+ datesSelected ? ( startDate, endDate)
5167 } , label: {
5268 Text ( Localization . apply)
5369 } )
5470 }
5571 ToolbarItem ( placement: . cancellationAction) {
5672 Button ( action: {
57- // TODO: Send dismiss action
73+ presentation . wrappedValue . dismiss ( )
5874 } , label: {
5975 Image ( uiImage: . closeButton)
6076 } )
0 commit comments