Toasts and popups library written with SwiftUI

Overview

Popup View

Toasts and popups library written with SwiftUI


We are a development agency building phenomenal apps.




Twitter Version Carthage Compatible License Platform

Usage

  1. Put all your body code into a ZStack
  2. Add a binding bool to control popup presentation state
  3. Add .popup modifier to your ZStack
struct ContentView: View {

    @State var showingPopup = false

    var body: some View {
        ZStack {
            // your view
        }
        .popup(isPresented: $showingPopup, autohideIn: 2) {
            Text("The popup")
                .frame(width: 200, height: 60)
                .background(Color(red: 0.85, green: 0.8, blue: 0.95))
                .cornerRadius(30.0)
        }
    }
}

Required parameters

isPresented - binding to determine if the popup should be seen on screen or hidden
view - view you want to display on your popup

Available customizations - optional parameters

type - toast, float or default
position - top or bottom (for default case it just determines animation direction)
animation - custom animation for popup sliding onto screen
autohideIn - time after which popup should disappear
dragToDismiss - true by default: enable/disable drag to dismiss (upwards for .top popup types, downwards for .bottom and default type)
closeOnTap - true by default: enable/disable closing on tap on popup
closeOnTapOutside - false by default: enable/disable closing on tap on outside of popup
dismissCallback - custom callback to call once the popup is dismissed

Draggable card

With latest addition of dragToDismiss, you can use bottom toast to add this popular component to your app (see example project for implementation)

.popup(isPresented: $show, type: .toast, position: .bottom) {
    // your content
}

Examples

To try PopupView examples:

  • Clone the repo https://github.com/exyte/PopupView.git
  • Open terminal and run cd <PopupViewRepo>/Example/
  • Run pod install to install all dependencies
  • Run open PopupViewExample.xcworkspace/ to open project in the Xcode
  • Try it!

Installation

CocoaPods

To install PopupView, simply add the following line to your Podfile:

pod 'ExytePopupView'

Carthage

To integrate PopupView into your Xcode project using Carthage, specify it in your Cartfile

github "Exyte/PopupView"

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/exyte/PopupView.git", from: "1.0.0")
]

Manually

Drop PopupView.swift in your project.

Requirements

  • iOS 13+
  • Xcode 11+
Comments
  • Add .popup(item:) variant

    Add .popup(item:) variant

    There's a need to pass information to the toast UI. SwiftUI handles this for various views by providing an item variant for view modifiers:

        public func popover<Item, Content>(item: Binding<Item?>, attachmentAnchor: PopoverAttachmentAnchor = .rect(.bounds), arrowEdge: Edge = .top, @ViewBuilder content: @escaping (Item) -> Content) -> some View where Item : Identifiable, Content : View
    

    I'm looking at your code and wondering how hard it would be to add the same thing, but I don't quite understand everything you're doing in yours.

    opened by JetForMe 11
  • popup not showing correctly

    popup not showing correctly

    Hi ,

    I am working on app, to show toast message using below code.

    But issue is If once Popup toast show, second time it's not showing.

    struct ContentView2: View {
        @State var showingPopup = false
    
        var body: some View {
            ZStack {
                Color.yellow
                VStack {
                    Button("Show Popup", action: {
                        showingPopup = true
                    })
                }
            }
            .popup(isPresented: $showingPopup, type: .toast, position: .bottom, autohideIn: 2) {
                Text("The popup")
                    .frame(width: 200, height: 60)
                    .background(Color(red: 0.85, green: 0.8, blue: 0.95))
                    .cornerRadius(30.0)
            }
        }
    }
    

    https://user-images.githubusercontent.com/2367614/181250056-eb963e2b-00dc-46e5-a2aa-d037ed12b9f3.mov

    M I doing something wrong? How can is show different toast messages in same view?

    opened by toseefkhilji 8
  • Added unwrapped item back to builder closure while preserving dismissal animation.

    Added unwrapped item back to builder closure while preserving dismissal animation.

    As the title says, this pull request is all about re-introducing the unwrapped item back into the builder closure. I was able to preserve the animation by caching the last non-nil Item value and falling back to it within the sheet when item is nil.

    opened by rzulkoski 7
  • Improvement: Drag to dismiss

    Improvement: Drag to dismiss

    Hi ! Thanks for your work and for sharing with us this library. I'm coming with a suggestion for improving the UX regarding the options that a user has in order to dismiss the popup. It would be cool if the user would be able to dismiss it by dragging down. Thanks a lot !

    opened by lrun-cmck 7
  • Popup blocks touch propagation to List View

    Popup blocks touch propagation to List View

    When using this library with a List and Navigation links, you have to hold the list cell to activate the navigation link or swipe to delete.

    Here is the code I'm using to set up the toast:

    .popup(isPresented: $showCopiedToast,
                       type: .toast,
                       position: .bottom,
                       autohideIn: 2,
                       closeOnTap: false) {
                    HStack {
                        Text(self.toastText)
                    }
                    .frame(width: 200, height: 60)
                    .background(Color(red: 0.85, green: 0.8, blue: 0.95))
                    .cornerRadius(30.0)
                    .padding(15)
                }
    

    My guess is the simultaneousGesture stuff is messing with the list view. A workaround or fix would be appreciated.

    opened by SlayterDev 7
  • Is there a way to make the toast show on top of modals?

    Is there a way to make the toast show on top of modals?

    Ideally we'd like to be able to display a toast and it appear no matter if there was a modal on the screen or not. Right now if there is a modal the toast appears underneath it. We could add the view modifier onto this modal view, but then the toast would go down once the view was dismissed. Is this something that is possible?

    opened by bratxdy 5
  • Keep getting

    Keep getting "Invalid frame dimension" error

    When dismissing the popup view, got error message often, anyone know how to resolve it?

    2021-04-14 12:51:35.864282+0800 gikiapp[923:160335] [SwiftUI] Invalid frame dimension (negative or non-finite).
    2021-04-14 12:51:35.883202+0800 gikiapp[923:160335] [SwiftUI] Invalid frame dimension (negative or non-finite).
    
    opened by metrue 5
  • Popup view should be lazy loaded

    Popup view should be lazy loaded

    Here is an example

    The current implemention is even showSystemAlertNotification = false, popup body is still executed. This could bring some problems in reality:

    data struct is set a valid value only if showSystemAlertNotification= true. Since it's not lazy-loaded, a crash happens since self.systemAlertNotification = nil

    .popup(isPresented: $showSystemAlertNotification, type: .floater(), position: .top, animation: Animation.spring()) {
                    SystemAlert(alert: self.data!)
                }
    
    opened by ghost 5
  • Need to get dismiss source

    Need to get dismiss source

    I want to react differently when popup is dismissed because of a tap or because of a drag.

    Here is the changes I've made to accomplish this 👇

    PopupChanges

    Is there another way of achieving what I want ? I tried adding a click on my view but it doesn't work well since it doesn't take into account your drag handling code.

    Do you think that can interest other users ? Do you want me to do a pull request ?

    opened by CedricSoubrie 4
  • Redrawing of views

    Redrawing of views

    Changing how the view is shown would prevent reloading of the content.

    public func body(content: Content) -> some View {
            Group {
                main(content: content)
            }
            .valueChanged(value: isPresented) { isPresented in
                appearAction(isPresented: isPresented)
            }
        }
        
        private func main(content: Content) -> some View {
            ZStack {
                content
                    .frameGetter($presenterContentRect)
                
                if showContent {
                    backgroundColor
                        .applyIf(closeOnTapOutside) { view in
                            view.contentShape(Rectangle())
                        }
                        .addTapIfNotTV(if: closeOnTapOutside) {
                            dismiss()
                        }
                        .edgesIgnoringSafeArea(.all)
                        .opacity(currentBackgroundOpacity)
                        .animation(animation)
                }
            }
            .overlay(sheet())
        }
    
    opened by iankoex 4
  • Popup view makes the child view navigate to top

    Popup view makes the child view navigate to top

    Xcode. 13.1 iOS 15.0

    At the end of a long list I want to trigger a popup view. When the user triggers it the scrollview is reset to beginning.

    struct ChildView: View {
        
        @Binding var show: Bool
        let text: String
        
        var body: some View {
            
            ScrollView(.vertical, showsIndicators: false) {
                ForEach(0..<50) { _ in
                    Text("Hello World")
                        .padding()
                }
                
                VStack {
                    Button {
                        show.toggle()
                    } label: {
                        Text(text)
                    }
                }
            }
            .clipped()
    
        }
    }
    
    
    struct TabsView: View {
        
        @State var show = false
        
        var body: some View {
            
            ZStack {
                TabView {
                    ChildView(show: $show, text: "FirstView")
                        .tabItem({
                            Label("First", systemImage: "greetingcard")
                        })
                }
            }
            .popup(isPresented: $show, type: .default, dragToDismiss: true, closeOnTap: false, closeOnTapOutside: true, backgroundColor: .black.opacity(0.5)) {
                VStack {
                    Text("👻")
                    Text("Hello World.")
                    Button {
                        show.toggle()
                    } label: {
                        Text("Dismiss ")
                    }
                }
                .padding(.vertical, 20)
                .padding(.horizontal, 40)
                .frame(width: 300, height: 300)
                .background(.red)
                .cornerRadius(10)
            }
        }
    }
    
    
    opened by solkpolk 4
  • How to make width of popup to all screen?

    How to make width of popup to all screen?

    Hello,

    firstly, thank you for amazing lib!

    I'm trying to implement a pop up and make it all screen width. I've tried .frame(maxWidth: .infinity) but it doesn't help.

    Maybe you can share some cool design of popups (like you used in screenshot on readme page)?

    opened by azaitsev 1
  • Popup from bottom does not cover navigation bar

    Popup from bottom does not cover navigation bar

    Hi,

    Great library!

    I'm trying to replace partialSheet with the bottom popupview from this library, but I'm having trouble with the navigation bar. The solution proposed here (https://github.com/exyte/PopupView/issues/61#issuecomment-1118347975) animates weird because you can see the transparent view come up from the bottom.

    How would one get the the same behavior as in the partial sheet library? The main reason I'm considering switching is because they do not support activity sheets for iPads.

    https://github.com/AndreaMiotto/PartialSheet

    Thanks,

    opened by jtressle 1
  • Keyboard handling for popups

    Keyboard handling for popups

    Keyboard area is not handled for popups

    I'm using floater type to show a popup. (bottom popup version 2 from example)

    .popup(isPresented: $showForgotPassword, type: .floater(verticalPadding: 0, useSafeAreaInset: false), position: .bottom, dragToDismiss: false, closeOnTap: false, backgroundColor: .black.opacity(0.4)) {
                ForgotPasswordView(forgotPasswordViewModel: ForgotPasswordViewModel(email: email))
            }
    

    And this is the result

    Simulator Screen Shot - iPhone 14 Pro Max - 2022-10-13 at 18 25 34

    Simulator Screen Shot - iPhone 14 Pro Max - 2022-10-13 at 18 25 37

    opened by rajdhakategraphy 0
Owner
Exyte
Exyte
MIBlurPopup lets you create popups with a blurred background

MIBlurPopup MIBlurPopup lets you create amazing popups with a blurred background Setup Add pod 'MIBlurPopup' to your Podfile or copy the "MIBlurPopup.

Mario Iannotta 607 Nov 24, 2022
Create fully customizable popups easier than ever before ⚜️

FlexFlex Create fully customizable popups easier than ever before. ?? Installation FlexFlex requires iOS 13 and Xcode 12. 1️⃣ In Xcode go to File ➤ Ad

adri567 2 Aug 15, 2022
SSToastMessage is written purely in SwiftUI. It will add toast, alert, and floating message view over the top of any view. It is intended to be simple, lightweight, and easy to use. It will be a popup with a single line of code.

SSToastMessage SSToastMessage is written in SwiftUI. It will add toast, alert, and floating message view over the top of any view. It is intended to b

Simform Solutions 223 Dec 2, 2022
Popover is a balloon library like Facebook app. It is written in pure swift.

Popover Description and appetize.io`s DEMO Usage To run the example project, clone the repo, and run pod install from the Example directory first. Sim

Yusuke Takahashi 2k Jan 2, 2023
STPopup provides STPopupController, which works just like UINavigationController in popup style, for both iPhone and iPad. It's written in Objective-C and compatible with Swift.

STPopup STPopup provides STPopupController, which works just like UINavigationController in popup style, for both iPhone and iPad. It's written in Obj

Kevin Lin 2.6k Jan 6, 2023
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Orderella Ltd. 3.8k Dec 20, 2022
A lightweight library for popup view

SHPopup SHPop is lightweight library used for popup view Sample One Sample Two Sample Three Features SHPopup supports a popup inside another popup wit

Shezad Ahamed 37 Oct 2, 2022
SwiftEntryKit is a presentation library for iOS. It can be used to easily display overlays within your iOS apps.

SwiftEntryKit ?? Donations can be made here. Table of Contents Overview Features Example Project Example Project Installation Presets Playground Requi

Daniel Huri 6.1k Jan 6, 2023
The library allows to create simple popup menus

react-native-popup-menu This library allows to create simple popup menus Installation "react-native-popup-menu": "sergeymild/react-native-popup-menu"

SergeyMild 0 Aug 20, 2022
A simple way to show toast in SwiftUI.

A simple way to show toast in SwiftUI Documentation • Example • Change Log Overview ToastUI provides you a simple way to present toast, head-up displa

Quan Tran 384 Dec 29, 2022
A framework for presenting bars and view controllers as popup, much like the look and feel of Apple Music App.

PBPopupController PBPopupController is a framework for presenting bars and view controllers as popup, much like the look and feel of Apple Music App.

Patrick 58 Dec 3, 2022
Simple way to present custom views as a popup in iOS and tvOS.

PopupKit PopupKit is a simple and flexible iOS framework for presenting any custom view as a popup. It includes a variety of options for controlling h

Pointwelve 59 Mar 1, 2022
Toasts and popups library written with SwiftUI

Popup View Toasts and popups library written with SwiftUI We are a development agency building phenomenal apps. Usage Put all your body code into a ZS

Exyte 1.9k Jan 6, 2023
GUI library for displaying various popups (HUD), written in pure Swift.

SwiftNotice SwiftNotice is a GUI library for displaying various popups (HUD) written in pure Swift, fits any scrollview and supports iPhone X. Feature

John Lui 838 Dec 9, 2022
Create Apple-like alerts & toasts using SwiftUI

AlertToast-SwiftUI Present Apple-like alert & toast in SwiftUI ?? Example ?? Overview Currently in SwiftUI, the only way to inform the user about some

Elai Zuberman 1.1k Dec 29, 2022
iOS tweak to display toasts for Low Power alerts and charging

Electrode iOS tweak to display toasts for Low Power alerts and charging. Localization Want to help translate Electrode to your language? Sumbit a pull

null 8 Sep 7, 2022
🍞 Loaf is a Swifty Framework for Easy iOS Toasts

Loaf ?? Inspired by Android's Toast, Loaf is a Swifty Framework for Easy iOS Toasts Usage From any view controller, a Loaf can be presented by calling

Mat Schmid 995 Dec 28, 2022
SwiftOverlays is a Swift GUI library for displaying various popups and notifications

SwiftOverlays is a Swift GUI library for displaying various popups and notifications. SwiftOverlays animated logo is kindly made by Crafted Pixels Fea

Peter Prokop 632 Dec 22, 2022
An example of creating custom popups in SwiftUI

Custom Popup Example An example project for Implementing custom popups in SwiftUI article. Author Artem Novichkov, [email protected] License The

Artem Novichkov 37 Dec 10, 2022
LNPopupController is a framework for presenting view controllers as popups of other view controllers, much like the Apple Music and Podcasts apps.

LNPopupController LNPopupController is a framework for presenting view controllers as popups of other view controllers, much like the Apple Music and

Leo Natan 2.9k Jan 2, 2023