PopupView icon indicating copy to clipboard operation
PopupView copied to clipboard

Stacking Popup of same type

Open dentvii opened this issue 1 year ago • 8 comments

Issue: Unable to Stack Popups of the Same Type

Problem

Currently, it is not possible to stack popups of the same type. For instance, displaying multiple TopNotification popups simultaneously is not feasible because they all share the same identifier.

Code Example

public extension Popup {
    var id: String { .init(describing: Self.self) }
    var body: V { createContent() }

    func configurePopup(popup: Config) -> Config { popup }
}

Issue Details

Due to the same identifier (TopPopup_Notification), these messages can only replace each other rather than stack.

Proposed Solution

The id of the Popup should be a property of the caller, making it an optional description of self. This change would allow for multiple notifications of the same type to be displayed concurrently.

Benefits of Custom Popup IDs

  1. Stacking Multiple Popups: Enables multiple notifications of the same type to be displayed simultaneously.
  2. Targeted Removal: Allows a specific popup to be removed from the stack.
  3. Existence Check: Facilitates checking for the existence of a specific popup on the stack before taking action.
  4. Maintaining Current Behavior: Keeps the current behavior intact while allowing for multiple instances of the same type.

Visual Example

Popup Example This has a while loop on this message on the demo, but only one message is shown.

Expected Behavior

image Messages of same Notification Type are reused and stacked.

Conclusion

Modifying the id property to be customizable will enhance the flexibility and functionality of the popup system, allowing for a more dynamic and responsive user experience.

dentvii avatar Jul 24 '24 18:07 dentvii

Hey @dentvii,

Thanks for this post. It does indeed make sense. I'll try to squeeze this feature into the current sprint, but no promises, as I need to finally finish the new library I put on hold about two months ago (so in the worst case, this will be implemented at the end of August) 😅

Thanks for the ticket and have a nice day, Tomasz

FulcrumOne avatar Jul 29 '24 10:07 FulcrumOne

Just adding to this as i'm also hitting this issue for a feature!

Making the ID property public/ with public initialisers should resolve for us?

jamesyorke avatar Aug 13 '24 14:08 jamesyorke

I think i'm having the same issue, the loading popup here does not get replaced

    @MainActor
    private func startLoading() {
        MiddlePopup(state: .loading)
            .showAndStack()
    }

    @MainActor
    private func completeLoading(_ state: PopupState) {
        print("loading completed: \(state)")
        MiddlePopup(state: state)
            .showAndReplace()
    }

Fixed with

   @MainActor
    private func completeLoading(_ state: PopupState) {
        PopupManager.dismiss()

        Task {
            MiddlePopup(state: state)
                .showAndReplace()
        }
    }

praveenperera avatar Aug 14 '24 21:08 praveenperera

Hey, this feature is in our backlog and will be implemented next month.

FulcrumOne avatar Aug 14 '24 22:08 FulcrumOne

Cool thanks! And thanks for the great library, it’s much nicer to use than the pure state driven SwiftUI popup view libraries.

praveenperera avatar Aug 14 '24 22:08 praveenperera

Any rough timeline on this?

jamesyorke avatar Oct 03 '24 15:10 jamesyorke

@jamesyorke,

Working on it now, but it's the part of huge update (#142) that I hope to publish in ~12 days.

FulcrumOne avatar Oct 03 '24 15:10 FulcrumOne

@jamesyorke, @dentvii, @praveenperera,

Just letting you know that the feature is already implemented in the branch patch-3.0.0. It can be used as follows: CleanShot 2024-10-04 at 15 23 12

I would definitely advise to not use the branch on prod, but you can test the changes if you have some time. I plan to publish a pre-release version on 16 October and launch it 7-10 days later.

FulcrumOne avatar Oct 04 '24 13:10 FulcrumOne

Hey @jamesyorke, @dentvii, @praveenperera

Just letting you know that I've finished the update. There are some changes to the API and the GitHub documentation (with migration guidelines) is not yet ready, but the library has extensive documentation with some code examples that I hope will help you understand the new features. CleanShot 2024-10-16 at 01 51 18 CleanShot 2024-10-16 at 01 52 14

Let me know if you need any help and have a nice day, Tomasz

FulcrumOne avatar Oct 15 '24 23:10 FulcrumOne