All Projects → davdroman → MultiModal

davdroman / MultiModal

Licence: Unlicense license
Use multiple .sheet, .alert, etc. modifiers in the same SwiftUI View

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to MultiModal

Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (+2453.06%)
Mutual labels:  alert, modal
Bdialog
Extend the Bootstrap Modal features, making dialog more functions and easier to use, dialog type including modal, alert, mask and toast types
Stars: ✭ 174 (+255.1%)
Mutual labels:  alert, modal
Customalertviewdialogue
Custom AlertView Dialogue is the world's most advanced alert view library. Custom AlertView Dialogue includes simple message popups, confirmation alerts, selector popups, action sheet bottom menus, and input/feedback contact forms.
Stars: ✭ 100 (+104.08%)
Mutual labels:  alert, modal
Jalert
jQuery alert/modal/lightbox plugin
Stars: ✭ 73 (+48.98%)
Mutual labels:  alert, modal
Jspanel4
A JavaScript library to create highly configurable floating panels, modals, tooltips, hints/notifiers/alerts or contextmenus for use in backend solutions and other web applications.
Stars: ✭ 217 (+342.86%)
Mutual labels:  alert, modal
Smalltalk
Promise-based Alert, Confirm and Prompt replacement
Stars: ✭ 76 (+55.1%)
Mutual labels:  alert, modal
Alertifyjs
A javascript framework for developing pretty browser dialogs and notifications.
Stars: ✭ 1,922 (+3822.45%)
Mutual labels:  alert, modal
Sweetalert
A beautiful replacement for JavaScript's "alert"
Stars: ✭ 21,871 (+44534.69%)
Mutual labels:  alert, modal
Wc Messagebox
基于 Vue 2.0 开发的 Alert, Toast, Confirm 插件, UI仿照 iOS 原生
Stars: ✭ 203 (+314.29%)
Mutual labels:  alert, modal
Pmalertcontroller
PMAlertController is a great and customizable alert that can substitute UIAlertController
Stars: ✭ 2,397 (+4791.84%)
Mutual labels:  alert, modal
React Native Alert Pro
The Pro Version of React Native Alert (Android & iOS)
Stars: ✭ 69 (+40.82%)
Mutual labels:  alert, modal
Nativepopup
Clone of Apple iOS App's feedback popup, and easily customizable.
Stars: ✭ 247 (+404.08%)
Mutual labels:  alert, modal
Ng Bootstrap
Angular powered Bootstrap
Stars: ✭ 7,872 (+15965.31%)
Mutual labels:  alert, modal
Ng Popups
🎉 Alert, confirm and prompt dialogs for Angular. Simple as that.
Stars: ✭ 80 (+63.27%)
Mutual labels:  alert, modal
Gcnotificationview
Simplest notification alert view for iOS
Stars: ✭ 27 (-44.9%)
Mutual labels:  alert, view
Zhpopupcontroller
Help you pop up custom views easily. and support pop-up animation, layout position, mask effect and gesture interaction etc.
Stars: ✭ 1,481 (+2922.45%)
Mutual labels:  alert, sheet
Cleanymodal
Swift UI Kit to present clean modal/alert
Stars: ✭ 437 (+791.84%)
Mutual labels:  alert, modal
Ngx Sweetalert2
Declarative, reactive, and template-driven SweetAlert2 integration for Angular
Stars: ✭ 503 (+926.53%)
Mutual labels:  alert, modal
React Popup
React popup component
Stars: ✭ 198 (+304.08%)
Mutual labels:  alert, modal
Presentr
iOS let's you modally present any view controller, but if you want the presented view controller to not cover the whole screen or modify anything about its presentation or transition you have to use the Custom View Controller Presentation API's.
Stars: ✭ 2,816 (+5646.94%)
Mutual labels:  alert, modal

MultiModal

CI

Introduction

By default, SwiftUI views with multiple modal modifiers (e.g. .sheet, .alert) in the same body will only use the last one in the chain of modifiers and ignore all previous ones.

struct NoMultiModalDemoView: View {
    @State var sheetAPresented = false
    @State var sheetBPresented = false
    @State var sheetCPresented = false

    var body: some View {
        VStack(spacing: 20) {
            Button("Sheet A") { sheetAPresented = true }
            Button("Sheet B") { sheetBPresented = true }
            Button("Sheet C") { sheetCPresented = true }
        }
        .sheet(isPresented: $sheetAPresented) { Text("Sheet A") } // does not work
        .sheet(isPresented: $sheetBPresented) { Text("Sheet B") } // does not work
        .sheet(isPresented: $sheetCPresented) { Text("Sheet C") } // works
    }
}

MultiModal brings a .multiModal modifier to declare multiple modal modifiers in the same view body.

struct MultiModalDemoView: View {
    @State var sheetAPresented = false
    @State var sheetBPresented = false
    @State var sheetCPresented = false

    var body: some View {
        VStack(spacing: 20) {
            Button("Sheet A") { sheetAPresented = true }
            Button("Sheet B") { sheetBPresented = true }
            Button("Sheet C") { sheetCPresented = true }
        }
        .multiModal {
            $0.sheet(isPresented: $sheetAPresented) { Text("Sheet A") } // works
            $0.sheet(isPresented: $sheetBPresented) { Text("Sheet B") } // works
            $0.sheet(isPresented: $sheetCPresented) { Text("Sheet C") } // works
        }
    }
}

Disclaimer

MultiModal does not enable "nested" modals; it just enables multiple modals appearing within a view body one at a time. For this reason, it's recommended that your modal presentation be dependant on a source of truth that ensures only one of them is presented at any given time.

Hopefully Apple will introduce support for multiple modals in a future iteration of SwiftUI, rendering this library unnecessary.

Benchmarks

MacBook Pro (14-inch, 2021)
Apple M1 Pro (10 cores, 8 performance and 2 efficiency)
32 GB Memory

$ swift run -c release Benchmarks

name     time        std        iterations
------------------------------------------
Modifier 2416.000 ns ±  15.72 %     571301
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].