Skip to content

Commit 25dd365

Browse files
HarishwaranVijayakumarsheiksyedm
authored andcommitted
[Android] Implement material3 support for TimePicker (#33646)
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change <!-- Enter description of the fix in this section --> This pull request introduces a new Material3-based time picker for Android and updates the handler registration and platform-specific extensions to support it. The main goal is to enable the use of `TimePickerHandler2` and `MauiMaterialTimePicker` when Material3 is enabled, while maintaining compatibility with the existing time picker otherwise. ### Material3 Time Picker Integration * Added new `TimePickerHandler2` class for Android, implementing a Material3-style time picker dialog, with custom mapping and event handling for properties such as time, format, background, and open/close state. (`src/Core/src/Handlers/TimePicker/TimePickerHandler2.Android.cs`) * Introduced `MauiMaterialTimePicker` control for Android, which wraps the Material3 time picker UI and exposes methods for showing/hiding the picker and updating its appearance. (`src/Core/src/Platform/Android/MauiMaterialTimePicker.cs`) ### Handler Registration Updates * Modified `AddControlsHandlers` method to register `TimePickerHandler2` for Android when Material3 is enabled, and fall back to the original handler otherwise. (`src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs`) [[1]](diffhunk://#diff-66e353858f3298f672f1eb103758a50e379019a1d8efe1b845de3779e7323b8bR72-R83) [[2]](diffhunk://#diff-66e353858f3298f672f1eb103758a50e379019a1d8efe1b845de3779e7323b8bL90) ### Platform Extension Methods * Added extension methods for updating format, time, and text color for `MauiMaterialTimePicker`, mirroring existing methods for the legacy time picker, and ensuring correct formatting and appearance. (`src/Core/src/Platform/Android/TimePickerExtensions.cs`) Material Design Spec - [TimePicker](https://m3.material.io/components/time-pickers/specs) ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #33645 ### Output | Material 2 |Material 3 | |----------|----------| | <img src="https://github.com/user-attachments/assets/13cf453c-93e4-4009-a465-9ed9975d9d18"> | <img src="https://github.com/user-attachments/assets/577cd1d1-79fe-4348-856e-8658ea969fd9"> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
1 parent 81dbe0e commit 25dd365

24 files changed

Lines changed: 783 additions & 9 deletions

File tree

src/Controls/src/Core/Hosting/AppHostBuilderExtensions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo
6969
#else
7070
handlersCollection.AddHandler<CollectionView, CollectionViewHandler>();
7171
handlersCollection.AddHandler<CarouselView, CarouselViewHandler>();
72+
#endif
73+
#if ANDROID
74+
if (RuntimeFeature.IsMaterial3Enabled)
75+
{
76+
handlersCollection.AddHandler<TimePicker, TimePickerHandler2>();
77+
}
78+
else
79+
{
80+
handlersCollection.AddHandler<TimePicker, TimePickerHandler>();
81+
}
82+
#else
83+
handlersCollection.AddHandler<TimePicker, TimePickerHandler>();
7284
#endif
7385
handlersCollection.AddHandler<Application, ApplicationHandler>();
7486
handlersCollection.AddHandler<ActivityIndicator, ActivityIndicatorHandler>();
@@ -87,7 +99,6 @@ internal static IMauiHandlersCollection AddControlsHandlers(this IMauiHandlersCo
8799
handlersCollection.AddHandler<Slider, SliderHandler>();
88100
handlersCollection.AddHandler<Stepper, StepperHandler>();
89101
handlersCollection.AddHandler<Switch, SwitchHandler>();
90-
handlersCollection.AddHandler<TimePicker, TimePickerHandler>();
91102
handlersCollection.AddHandler<Page, PageHandler>();
92103
handlersCollection.AddHandler<WebView, WebViewHandler>();
93104
if (RuntimeFeature.IsHybridWebViewSupported)
153 KB
Loading
74.5 KB
Loading
79.4 KB
Loading
77.8 KB
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)