Mijick / Popups

Popups, popovers, sheets, alerts, toasts, banners, (...) presentation made simple. Written with and for SwiftUI.
Apache License 2.0
1.38k stars 59 forks source link

Stacking Popup of same type #123

Closed dentvii closed 1 month ago

dentvii commented 4 months 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 3 months 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 months 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 months 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 months ago

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

praveenperera commented 3 months ago

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

jamesyorke commented 1 month ago

Any rough timeline on this?

FulcrumOne commented 1 month ago

@jamesyorke,

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

FulcrumOne commented 1 month ago

@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 commented 1 month ago

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