rotorgames / Rg.Plugins.Popup

Xamarin Forms popup plugin
MIT License
1.15k stars 336 forks source link

Popup hides snackbar (Android) + new feature #730

Open Zilkode opened 2 years ago

Zilkode commented 2 years ago

Thank you for this incredible plugin. I am having an issue with the popup where it hides the native snackbar, i use the popup to message the user about the permission snackbar but when I am using it the snackbar button is unclickable. Is there a way to resize the black overlay or create a transparent clixkable "window"?

The second is something I modified in order to conform with my flow but is something that can be useful for this plugin.

I added an Interface ISelectiveBackbuttonClosable which contains the following: bool PreventClose (callback to closing validation, such as i am intend to use with the snackbar) void PopupClosing(); (backbutton is not wired to popup events, so this is an overlap) void PopupClosed(); (After popup is closed, same reason as Closing ).

I call this interface in Popup.cs sendBackbutton. First checking if closing is allowed and then calling the Closing and Closed. ISelectiveBackbuttonClosable.Closed is crucial for Disposable popups, the Closing method is used to collect neccessary popup fields, trigger Cancel event or send signal to OnClose event listener.

*update, code example:

Rg.Plugins.Popup.Popup.cs:

public static bool SendBackPressed(Action? backPressedHandler = null)
        {
            var popupNavigationInstance = PopupNavigation.Instance;

            if (popupNavigationInstance.PopupStack.Count > 0)
            {
                var lastPage = popupNavigationInstance.PopupStack.Last();

                var isPreventClose = lastPage.DisappearingTransactionTask != null || lastPage.SendBackButtonPressed();

                IBackbuttonClosing closable = lastPage as IBackbuttonClosing;
                if (closable != null && closable.PreventClose)
                    return true;

                if (!isPreventClose)
                {
                    closable?.PopupClosing();

                    Device.BeginInvokeOnMainThread(async () =>
                    {
                        await popupNavigationInstance.RemovePageAsync(lastPage);
                    });

                    closable?.PopupClosed();
                }

                return true;
            }

            backPressedHandler?.Invoke();

            return false;
        }
LuckyDucko commented 2 years ago

Hi @Zilkode I recommend making a PR to review with your code here, at the least the preventclose functionality might gain widespread use to simplify workflows.

When you say black overlay, could you provide an example of some sort? just so I understand what you mean