Skip to content

Commit

Permalink
move custom handlers to toolkit configuration method
Browse files Browse the repository at this point in the history
  • Loading branch information
gwalus committed May 21, 2024
1 parent cc57b46 commit 614cb65
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 40 deletions.
28 changes: 0 additions & 28 deletions src/Dollet.Presentation/Maui/Handlers/FormHandler.cs

This file was deleted.

27 changes: 18 additions & 9 deletions src/Dollet.Presentation/Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using CommunityToolkit.Maui;
using Dollet.Core;
using Dollet.Handlers;
using Dollet.Infrastructure;
using Dollet.PlatformSpecifics.Handlers;
using Dollet.PlatformSpecifics.Renderers;
using Microcharts.Maui;
using Microsoft.Extensions.Configuration;
using System.Reflection;
#if ANDROID
using Dollet.Platforms.Android.Renderers;
#endif

namespace Dollet
{
Expand All @@ -27,12 +25,23 @@ public static MauiApp CreateMauiApp()
.UseMauiCommunityToolkit()
.ConfigureMauiHandlers(handlers =>
{
#if ANDROID
handlers.AddHandler(typeof(Shell), typeof(CustomShellRenderer));
#endif
});
var platformHandlers = new Dictionary<DevicePlatform, Action>
{
{ DevicePlatform.Android, () =>
{
handlers.AddHandler(typeof(Shell), typeof(CustomShellRenderer));
handlers.AddHandler(typeof(Picker), typeof(CustomPickerHandler));
handlers.AddHandler(typeof(DatePicker), typeof(CustomDatePickerHandler));
}
}
};
FormHandler.RemoveBorders();
if (platformHandlers.TryGetValue(DeviceInfo.Platform, out var configureHandlers))
{
configureHandlers();
}
else return;
});

using var stream = Assembly
.GetExecutingAssembly()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Dollet.PlatformSpecifics.Handlers
{
internal partial class CustomDatePickerHandler { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Dollet.PlatformSpecifics.Handlers
{
internal partial class CustomPickerHandler { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Dollet.PlatformSpecifics.Renderers
{
internal partial class CustomShellRenderer { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Android.Content.Res;
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using Color = Android.Graphics.Color;

namespace Dollet.PlatformSpecifics.Handlers
{
internal partial class CustomDatePickerHandler : DatePickerHandler
{
protected override void ConnectHandler(MauiDatePicker platformView)
{
base.ConnectHandler(platformView);

platformView.Background = null;
platformView.SetBackgroundColor(Color.Transparent);
platformView.BackgroundTintList = ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Android.Content.Res;
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using Color = Android.Graphics.Color;

namespace Dollet.PlatformSpecifics.Handlers
{
internal partial class CustomPickerHandler : PickerHandler
{
protected override void ConnectHandler(MauiPicker platformView)
{
base.ConnectHandler(platformView);

platformView.Background = null;
platformView.SetBackgroundColor(Color.Transparent);
platformView.BackgroundTintList = ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Platform.Compatibility;

namespace Dollet.Platforms.Android.Renderers
namespace Dollet.PlatformSpecifics.Renderers
{
public class CustomShellRenderer(Context context) : ShellRenderer(context)
internal partial class CustomShellRenderer(Context context) : ShellRenderer(context)
{
protected override IShellTabLayoutAppearanceTracker CreateTabLayoutAppearanceTracker(ShellSection shellSection)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Dollet.Platforms.Android.Trackers
{
public class CustomTabLayoutAppearanceTracker(IShellContext shellContext) : ShellTabLayoutAppearanceTracker(shellContext)
internal class CustomTabLayoutAppearanceTracker(IShellContext shellContext) : ShellTabLayoutAppearanceTracker(shellContext)
{
public override void SetAppearance(TabLayout tabLayout, ShellAppearance appearance)
{
Expand Down

0 comments on commit 614cb65

Please sign in to comment.