Skip to content

Commit f02f71d

Browse files
committed
Merge branch 'develop'
2 parents 0e7fb80 + 0078345 commit f02f71d

File tree

2 files changed

+72
-18
lines changed

2 files changed

+72
-18
lines changed

AuroraControls.TestApp/MainPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ await this.Navigation.PushAsync(new GridImagePage())),
234234
Content =
235235
new CalendarPicker()
236236
{
237-
UpdateMode = CalendarPickerUpdateMode.Immediately,
237+
UpdateMode = CalendarPickerUpdateMode.WhenDone,
238238
}
239239
.Assign(out _calendarPicker),
240240
},

AuroraControlsMaui/Platforms/iOS/CalendarPickerHandler.cs

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace AuroraControls;
66

7-
public partial class CalendarPickerHandler : DatePickerHandler
7+
public partial class CalendarPickerHandler : DatePickerHandler, IDisposable
88
{
9+
private UIBarButtonItem? _clearButton;
10+
private UIBarButtonItem? _doneButton;
11+
912
public static PropertyMapper<CalendarPicker, CalendarPickerHandler> NullableDatePickerPropertyMapper =
1013
new(ViewMapper)
1114
{
@@ -52,21 +55,15 @@ protected override void ConnectHandler(MauiDatePicker platformView)
5255

5356
if (platformView.InputAccessoryView is UIToolbar tb)
5457
{
55-
var clearButton = new UIBarButtonItem("Clear", UIBarButtonItemStyle.Plain,
56-
(_, _) =>
57-
{
58-
if (this.VirtualView is not CalendarPicker el)
59-
{
60-
return;
61-
}
62-
63-
el.Unfocus();
64-
el.Date = null;
65-
});
66-
67-
var items = new List<UIBarButtonItem>(tb.Items);
68-
items.Insert(0, clearButton);
69-
tb.Items = items.ToArray();
58+
_clearButton = new UIBarButtonItem();
59+
_clearButton.Style = UIBarButtonItemStyle.Plain;
60+
_clearButton.Title = "Clear";
61+
_clearButton.Clicked += ClearButtonOnClicked;
62+
63+
_doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done);
64+
_doneButton.Clicked += DoneButtonOnClicked;
65+
66+
tb.Items = [_clearButton, new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace), _doneButton];
7067
}
7168
}
7269

@@ -77,6 +74,16 @@ protected override void DisconnectHandler(MauiDatePicker platformView)
7774
dp.ValueChanged -= OnDatePickerValueChanged;
7875
}
7976

77+
if (_clearButton != null)
78+
{
79+
_clearButton.Clicked -= ClearButtonOnClicked;
80+
}
81+
82+
if (_doneButton != null)
83+
{
84+
_doneButton.Clicked -= DoneButtonOnClicked;
85+
}
86+
8087
base.DisconnectHandler(platformView);
8188
}
8289

@@ -95,7 +102,35 @@ private void OnDatePickerValueChanged(object sender, EventArgs e)
95102
}
96103
}
97104

98-
public void TryShowEmptyState()
105+
private void DoneButtonOnClicked(object? sender, EventArgs e)
106+
{
107+
if (
108+
this.PlatformView?.InputView?.Subviews.FirstOrDefault() is not UIDatePicker datePicker ||
109+
this.VirtualView is not CalendarPicker calendarPicker ||
110+
calendarPicker.UpdateMode != CalendarPickerUpdateMode.WhenDone)
111+
{
112+
return;
113+
}
114+
115+
calendarPicker.Date = datePicker.Date.ToDateTime();
116+
117+
this.TryShowEmptyState();
118+
119+
this.PlatformView.ResignFirstResponder();
120+
}
121+
122+
private void ClearButtonOnClicked(object? sender, EventArgs e)
123+
{
124+
if (this.VirtualView is not CalendarPicker el)
125+
{
126+
return;
127+
}
128+
129+
el.Unfocus();
130+
el.Date = null;
131+
}
132+
133+
private void TryShowEmptyState()
99134
{
100135
if (this.VirtualView is not CalendarPicker el)
101136
{
@@ -111,4 +146,23 @@ public void TryShowEmptyState()
111146
: string.Empty;
112147
});
113148
}
149+
150+
protected virtual void Dispose(bool disposing)
151+
{
152+
if (!disposing)
153+
{
154+
return;
155+
}
156+
157+
_clearButton?.Dispose();
158+
_doneButton?.Dispose();
159+
}
160+
161+
public void Dispose()
162+
{
163+
Dispose(true);
164+
GC.SuppressFinalize(this);
165+
}
166+
167+
~CalendarPickerHandler() => Dispose(false);
114168
}

0 commit comments

Comments
 (0)