Mijick / PopupView

Popups presentation made simple (SwiftUI)
MIT License
1.16k stars 45 forks source link

Stacking Popup of same type #123

Open dentvii opened 1 month ago

dentvii commented 1 month ago

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.

FulcrumOne commented 1 month ago

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

jamesyorke commented 3 weeks ago

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?

praveenperera commented 3 weeks ago

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()
        }
    }
FulcrumOne commented 3 weeks ago

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

praveenperera commented 3 weeks ago

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