Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An item with the same key has already been added. Key: Mopups.PreBaked.PopupPages.Loader.LoaderPopupPage #145

Open
meopoc opened this issue Dec 1, 2024 · 3 comments

Comments

@meopoc
Copy link

meopoc commented Dec 1, 2024

Hi,

I'm intermittently getting the following exception. I think it's when 2 LoaderPopupPages are loaded in quick succession.

System.ArgumentException: An item with the same key has already been added. Key: Mopups.PreBaked.PopupPages.Loader.LoaderPopupPage
File "AndroidMopups.cs", line 129, in void AndroidMopups.HandleAccessibility(bool showPopup, bool disableAccessibilityHandling, PopupPage popup)
accessibilityStates.Add(popup.GetType(), views);
File "AndroidMopups.cs", line 39, in Task AndroidMopups.AddAsync(PopupPage page)
HandleAccessibility(true, page.DisableAndroidAccessibilityHandling, page);
File "PopupNavigation.cs", line 73, in async Task PopupNavigation.PushAsync(PopupPage page, bool animate)+PushPage(?)
await PopupPlatform.AddAsync(page);
File "PreBakedMopupService.cs", line 260, in async void d__32.MoveNext()
await MainThread.InvokeOnMainThreadAsync(() => s_popupNavigation.PushAsync(popupModal));
File "SafeFireAndForgetExtensions.shared.cs", line 96, in async void d__16.MoveNext()
await task.ConfigureAwait(continueOnCapturedContext);
...
(7 additional frame(s) were not displayed)

Any ideas?

TIA

@robin-schroeder-merc
Copy link

robin-schroeder-merc commented Dec 13, 2024

Same issue. Switched back to version 1.3.1 to see if it was present and it still crashes, same error.

@EmilAlipiev
Copy link

oh this issue was very commun in Rg.Popups. i remember creating another nuget just solved this issue :D

@mf-noirsoft
Copy link

@meopoc This is because you tried to open 2 popups with the same type, in this case "Mopups.PreBaked.PopupPages.Loader.LoaderPopupPage". This used to work a while ago, but now it fails in AndroidMopups.cs:

public Task AddAsync(PopupPage page)
{
HandleAccessibility(true, page.DisableAndroidAccessibilityHandling, page);
...
//! important keeps reference to pages that accessibility has applied to. This is so accessibility can be removed properly when popup is removed. ##93
readonly Dictionary<Type, List<Android.Views.View>> accessibilityStates = new();
void HandleAccessibility(bool showPopup, bool disableAccessibilityHandling, PopupPage popup)
{
...
accessibilityStates.Add(popup.GetType(), views);
...

accessibilityStates is a Dictionary, and uses the popup type as its key, hence we can't add more than 1 popup of the same type.

I had to ditch mopups for those cases when I needed to display multiple popups of the same type, for example during async loading of several tasks when I want to close each popup when its task is done, not in the order they were opened. It would be nice if this was improved in a future release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants