Stacking Popup of same type
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
- Stacking Multiple Popups: Enables multiple notifications of the same type to be displayed simultaneously.
- Targeted Removal: Allows a specific popup to be removed from the stack.
- Existence Check: Facilitates checking for the existence of a specific popup on the stack before taking action.
- Maintaining Current Behavior: Keeps the current behavior intact while allowing for multiple instances of the same type.
Visual Example
Expected Behavior
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.
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
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?
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()
}
}
Hey, this feature is in our backlog and will be implemented next month.
Cool thanks! And thanks for the great library, it’s much nicer to use than the pure state driven SwiftUI popup view libraries.
Any rough timeline on this?
@jamesyorke,
Working on it now, but it's the part of huge update (#142) that I hope to publish in ~12 days.
@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:
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.
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.
Let me know if you need any help and have a nice day, Tomasz