-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add calendar selection delegate for iOS and MacCatalyst platforms
This commit adds a new `CalendarSelectionSingleDateDelegate` class that implements the `IUICalendarSelectionSingleDateDelegate` interface. The delegate is responsible for handling date selection events in the calendar view. When a date is selected, it updates the selected date in the calendar view and triggers the `OnSelectedDateChanged` event. The `CalendarHandler` class has been updated to use this delegate for both iOS and MacCatalyst platforms. The `ConnectHandler` method now sets up the calendar selection behavior using an instance of `UICalendarSelectionSingleDate`. Additionally, there are new methods (`MapSingleDateSelection`, `SetDateRange`) that handle mapping properties related to date selection and range. No changes were made to the Tizen platform implementation. Note: This commit does not include specific file names or mention any specific code files.
- Loading branch information
1 parent
e5e4a65
commit 18e62c3
Showing
3 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,88 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
using Foundation; | ||
using Microsoft.Maui.Handlers; | ||
using Microsoft.Maui.Platform; | ||
using ObjCRuntime; | ||
using UIKit; | ||
|
||
public sealed class CalendarSelectionSingleDateDelegate(ICalendarView calendarView) | ||
: IUICalendarSelectionSingleDateDelegate | ||
{ | ||
public void DidSelectDate(UICalendarSelectionSingleDate calendarSelection, NSDateComponents? date) | ||
{ | ||
calendarView.SelectedDate = date?.Date.ToDateTime(); | ||
calendarView.OnSelectedDateChanged(date?.Date.ToDateTime()); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
public NativeHandle Handle { get; } | ||
} | ||
|
||
public partial class CalendarHandler : ViewHandler<ICalendarView, UICalendarView> | ||
{ | ||
private UICalendarSelection? calendarSelection; | ||
|
||
protected override UICalendarView CreatePlatformView() | ||
{ | ||
return new UICalendarView(); | ||
} | ||
|
||
protected override void ConnectHandler(UICalendarView platformView) | ||
{ | ||
base.ConnectHandler(platformView); | ||
calendarSelection = new UICalendarSelectionSingleDate(new CalendarSelectionSingleDateDelegate(VirtualView)); | ||
platformView.SelectionBehavior = calendarSelection; | ||
} | ||
|
||
private static void MapFirstDayOfWeek(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
handler.PlatformView.Calendar.FirstWeekDay = (nuint)virtualView.FirstDayOfWeek; | ||
} | ||
|
||
private static void MapMinDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
SetDateRange(handler, virtualView); | ||
} | ||
|
||
private static void MapMaxDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
SetDateRange(handler, virtualView); | ||
} | ||
|
||
private static void MapSelectedDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
if (handler.calendarSelection is UICalendarSelectionSingleDate calendarSelection) | ||
{ | ||
MapSingleDateSelection(calendarSelection, virtualView); | ||
} | ||
} | ||
|
||
private static void MapSingleDateSelection(UICalendarSelectionSingleDate calendarSelection, ICalendarView virtualView) | ||
{ | ||
if (virtualView.SelectedDate is null) | ||
{ | ||
calendarSelection.SetSelectedDate(null, true); | ||
return; | ||
} | ||
|
||
calendarSelection.SetSelectedDate(new NSDateComponents() | ||
{ | ||
Day = virtualView.SelectedDate.Value.Day, | ||
Month = virtualView.SelectedDate.Value.Month, | ||
Year = virtualView.SelectedDate.Value.Year | ||
}, true); | ||
} | ||
|
||
private static void SetDateRange(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
var fromDateComponents = virtualView.MinDate.Date.ToNSDate(); | ||
var toDateComponents = virtualView.MaxDate.Date.ToNSDate(); | ||
|
||
var calendarViewDateRange = new NSDateInterval(fromDateComponents, toDateComponents); | ||
handler.PlatformView.AvailableDateRange = calendarViewDateRange; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,89 @@ | ||
namespace MauiBells.Calendar; | ||
|
||
using Foundation; | ||
using Microsoft.Maui.Handlers; | ||
using Microsoft.Maui.Platform; | ||
using ObjCRuntime; | ||
using UIKit; | ||
|
||
public sealed class CalendarSelectionSingleDateDelegate(ICalendarView calendarView) | ||
: IUICalendarSelectionSingleDateDelegate | ||
{ | ||
public void DidSelectDate(UICalendarSelectionSingleDate calendarSelection, NSDateComponents? date) | ||
{ | ||
calendarSelection.SelectedDate = date; | ||
calendarView.SelectedDate = date?.Date.ToDateTime(); | ||
calendarView.OnSelectedDateChanged(date?.Date.ToDateTime()); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
|
||
public NativeHandle Handle { get; } | ||
} | ||
|
||
public partial class CalendarHandler : ViewHandler<ICalendarView, UICalendarView> | ||
{ | ||
private UICalendarSelection? calendarSelection; | ||
|
||
protected override UICalendarView CreatePlatformView() | ||
{ | ||
return new UICalendarView(); | ||
} | ||
|
||
protected override void ConnectHandler(UICalendarView platformView) | ||
{ | ||
base.ConnectHandler(platformView); | ||
calendarSelection = new UICalendarSelectionSingleDate(new CalendarSelectionSingleDateDelegate(VirtualView)); | ||
platformView.SelectionBehavior = calendarSelection; | ||
} | ||
|
||
private static void MapFirstDayOfWeek(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
handler.PlatformView.Calendar.FirstWeekDay = (nuint)virtualView.FirstDayOfWeek; | ||
} | ||
|
||
private static void MapMinDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
SetDateRange(handler, virtualView); | ||
} | ||
|
||
private static void MapMaxDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
SetDateRange(handler, virtualView); | ||
} | ||
|
||
private static void MapSelectedDate(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
|
||
if (handler.calendarSelection is UICalendarSelectionSingleDate calendarSelection) | ||
{ | ||
MapSingleDateSelection(calendarSelection, virtualView); | ||
} | ||
} | ||
|
||
private static void MapSingleDateSelection(UICalendarSelectionSingleDate calendarSelection, ICalendarView virtualView) | ||
{ | ||
if (virtualView.SelectedDate is null) | ||
{ | ||
calendarSelection.SetSelectedDate(null, true); | ||
return; | ||
} | ||
|
||
calendarSelection.SetSelectedDate(new NSDateComponents() | ||
{ | ||
Day = virtualView.SelectedDate.Value.Day, | ||
Month = virtualView.SelectedDate.Value.Month, | ||
Year = virtualView.SelectedDate.Value.Year | ||
}, true); | ||
} | ||
|
||
private static void SetDateRange(CalendarHandler handler, ICalendarView virtualView) | ||
{ | ||
var fromDateComponents = virtualView.MinDate.Date.ToNSDate(); | ||
var toDateComponents = virtualView.MaxDate.Date.ToNSDate(); | ||
|
||
var calendarViewDateRange = new NSDateInterval(fromDateComponents, toDateComponents); | ||
handler.PlatformView.AvailableDateRange = calendarViewDateRange; | ||
} | ||
} |