MPowerKit / Popups

.NET MAUI popup library which allows you to open MAUI pages as a popup. Also the library allows you to use very simple and flexible animations for showing popup pages.
MIT License
33 stars 7 forks source link

SystemPadding and SystemPaddingSides properties #2

Open alexpetin opened 2 months ago

alexpetin commented 2 months ago

Hi!

In order to migrate from Rg.Plugins.Popup / Mopups it would be great to implement these props. Thanks for great package, Mopups is almost unusable due to a lot of bugs...

Alex-Dobrynin commented 2 months ago

For this there is property called HasSystemPadding

alexpetin commented 2 months ago

It's another props. The first one allow to get current padding sizes to accomodatge the content. The second one allows to use only left/right/top/bottom (or combination) paddings.

HasSystemPadding exists in Mopups too...

Alex-Dobrynin commented 2 months ago
  1. Look. I don't want this package use getting the system paddings api and provide such values to the user. this package is not about it. If you want to get system paddings for iOS/Android here is simple code to do this. You can add it to your MauiProgram.cs :
        builder.ConfigureLifecycleEvents(static l =>
        {
#if ANDROID
            l.AddAndroid(static android =>
            {
                android.OnCreate(static (a, b) =>
                {
                    if (a is not MainActivity) return;

                    var density = a.Resources.DisplayMetrics.Density;
                    float statusBarHeight = 0f;
                    int resourceId = a.Resources.GetIdentifier("status_bar_height", "dimen", "android");
                    if (resourceId > 0)
                    {
                        statusBarHeight = a.Resources.GetDimension(resourceId);
                    }
                    Settings.StatusBarHeight = statusBarHeight / density;

                    float navBarHeight = 0f;
                    resourceId = a.Resources.GetIdentifier("navigation_bar_height", "dimen", "android");
                    if (resourceId > 0)
                    {
                        navBarHeight = a.Resources.GetDimension(resourceId);
                    }
                    Settings.NavigationBarHeight = navBarHeight / density;
                });
            });
#else
            l.AddiOS(static ios =>
            {
                ios.FinishedLaunching(static (a, d) =>
                {
                    var window = PopupService.GetKeyWindow();

                    if (window is not null)
                    {
                        Settings.StatusBarHeight = window.SafeAreaInsets.Top;
                        Settings.NavigationBarHeight = window.SafeAreaInsets.Bottom;
                    }

                    return true;
                });
            });
#endif

Where Settings is your shared preferences. also for iOS you may add all sides

  1. a) You may just use regular Padding on the PopupPage and set it in code behind with values you got above like this:

    public YourPopupPage()
    {
    InitializeComponent();
    
    this.Padding = new Thickness(0, Settings.StatusBarHeight, 0, Settings.NavigationBarHeight);
    }

b) Override the basic implementation and do it there. it is easy, because everything public/protected virtual. c) Propose a PR with your implementation of this, I will appreciate it.

Hope my answer helped you

alexpetin commented 2 months ago
  1. I did not mean to get something new - the package already get it to set correct paddings, why not just publish it?

Ok, thanks.

Alex-Dobrynin commented 2 months ago

For iOS this package does not use API mentioned above, just MAUI's default ignore safe area or not.

But may be I will add such API to be public some day, but for now I'm very busy, sorry