FreakyAli / Maui.FreakyControls

FreakyControls is a free OSS UI Kit for .NET MAUI which provides a set of controls and utilities to build modern mobile apps.
MIT License
312 stars 37 forks source link

Method Chaining & Generic #103

Closed lukewire129 closed 10 months ago

lukewire129 commented 11 months ago

Maui AppBuilder before

public static void InitializeFreakyControls(this MauiAppBuilder builder, bool useSkiaSharp = true)
{
       if (useSkiaSharp)
       {
           builder.UseSkiaSharp();
       }
       builder.ConfigureMauiHandlers(builders => builders.AddHandlers());
       builder.ConfigureEffects(effects => effects.AddEffects());
}
namespace Samples;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });
        builder.UseMauiCommunityToolkit();
        builder.InitializeFreakyControls();
        return builder.Build();
    }
}

after

public static MauiAppBuilder InitializeFreakyControls(this MauiAppBuilder builder, bool useSkiaSharp = true)
{
       if (useSkiaSharp)
       {
           builder.UseSkiaSharp();
       }
       builder.ConfigureMauiHandlers(builders => builders.AddHandlers());
       builder.ConfigureEffects(effects => effects.AddEffects());

       return builder;
}
namespace Samples;

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseMauiCommunityToolkit()
            .InitializeFreakyControls()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });

        return builder.Build();
    }
}

Method Chaining Pattern Used

FreakyAli commented 11 months ago

Hey @lukewire129

Thanks for the PR, I genuinely appreciate it!

I was wondering though do you think this is needed, I mean I don't mind adding it in the next release it's just that I never really chain my initialization, if you use our controls and want this I can add it for you!

lukewire129 commented 11 months ago

It occurred to me that it would be more helpful for future Maui developers to meet the standards by using the chain method in common with all Maui Builders.

FreakyAli commented 10 months ago

Adding this directly to the master was a bit of a hassle so I added this change to an existing PR. Thanks!