TextFieldAlert - A SwiftUI alert with text field(s) for iOS 13 and greater.

Overview

TextFieldAlert

A SwiftUI alert with text field(s) for iOS 13 and greater.

As Apple is going to introduce text field(s) as an alert actions in iOS 16, this is a good replacement for older versions.

Requirements

  • iOS 13.0+
  • Swift 5.1+

Installation

You can add TextFieldAlert to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Add Packages…
  2. Enter https://github.com/sochalewski/TextFieldAlert into the package repository URL text field.
  3. Add the package to your app target.

Usage

TextFieldAlert is exposed through View extension:

func textFieldAlert(
    title: String?,
    message: String?,
    textFields: [TextFieldAlert.TextField],
    actions: [TextFieldAlert.Action],
    isPresented: Binding<Bool>
)

You can use it in your code as follows:

struct ExampleView: View {
    
    @State var isPresented = false
    @State var text1 = ""
    @State var text2 = ""
    
    var body: some View {
        VStack {
            Button {
                isPresented = true
            } label: {
                Text("Alert")
            }
            
            Text(text1)
            Text(text2)
        }
        .textFieldAlert(
            title: "Title",
            message: "Message",
            textFields: [
                .init(text: $text1),
                .init(text: $text2)
            ],
            actions: [
                .init(title: "OK")
            ],
            isPresented: $isPresented
        )
    }
}

More advanced usage (incl. moving the responsibility to a view model, some customization and enabling action buttons conditionally) is available in the Example app.

Author

Piotr Sochalewski, sochalewski.github.io

TextFieldAlert is heavily inspired by tanzolone's answer on StackOverflow.

License

TextFieldAlert is available under the MIT license. See the LICENSE file for more info.

You might also like...
Customizable simple Alert and simple ActionSheet for Swift
Customizable simple Alert and simple ActionSheet for Swift

SimpleAlert It is simple and easily customizable alert. Can be used as UIAlertController. Appetize's Demo Requirements Swift 5.0 iOS 9.0 or later How

A simple alert with logo image and color.
A simple alert with logo image and color.

YMLogoAlert About YMLogoAlert A simple custom alert. YMLogoAlert lets you pop up a simple alert with a natural animation, your app's own color, font a

A colored alert view for your iOS.
A colored alert view for your iOS.

日本語 KRAlertController KRAlertController is a beautiful and easy-to-use alert controller for your iOS written by Swift. Requirements iOS 10.0+ Xcode 10

A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.
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

Live animated Alert View for iOS written in Swift
Live animated Alert View for iOS written in Swift

Sweet Alert iOS Beautiful Animated custom Alert View inspired from javascript library SweetAlert. Written in Swift this SweetAlertView can be used in

A Swift package for iOS/tvOS for easy alert presentation

AlertPresenter Listed on the Swift Package Index and originally posted on my blog. It can be fiddly to handle the presentation of alerts on a specific

Highly configurable iOS Alert Views with custom content views
Highly configurable iOS Alert Views with custom content views

NYAlertViewController NYAlertViewController is a replacement for UIAlertController/UIAlertView with support for content views and UI customization. Fe

Custom alert View to iOS applications
Custom alert View to iOS applications

A simple, easy and custom iOS UIAlertView written in Swift Malert came to facilitates custom alert views as UIAlertController. Malert allows you to pe

Simple DropDown Alert View For Any iOS Projects.
Simple DropDown Alert View For Any iOS Projects.

⚠️ DEPRECATED, NO LONGER MAINTAINED JDropDownAlert JDropDownALert Simple DropDown Alert View For Any iOS Projects. Usage Top let alert = JDropDown

Owner
Piotr Sochalewski
Piotr Sochalewski
BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

BPStatusBarAlert BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

Ben.Park 131 Aug 12, 2022
Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.

SPAlert Popup from Apple Music & Feedback in AppStore. Contains Done, Heart, Error and other presets. Supports Dark Mode. I tried to recreate Apple's

Ivan Vorobei 1.4k Dec 10, 2021
JAlert - This is "Alert View" project for UIKit + SwiftUI. you can use easily

JAlert Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation JAlert is a

Jackson 3 Feb 22, 2022
DataDrivenAlert - Extension for SwiftUI.Alert for data driven configuration

Data driven alert and confirmation dialog Based on Composable Architecture Alert

Evgeny 2 Apr 9, 2022
Animated Alert written in SwiftUI.

TransactionAlert Animated Alert written in SwiftUI. Easy to use Get Started Add a TAViewModel instance as an environment object to your Root View in y

null 11 Jul 21, 2022
(Experimental libraries) Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI.

UIPresentCoordinator Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI. This library manages items that are

Yuki Tamazawa 1 Jan 22, 2022
Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift

CDAlertView is highly customizable alert popup written in Swift. Usage is similar to UIAlertController. Screenshots Animations Usage Basic usage witho

Candost Dagdeviren 1.1k Dec 30, 2022
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Paolo Musolino 2.5k Jan 3, 2023
Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.

SPAlert Popup from Apple Music & Feedback in AppStore. Contains Done, Heart, Error and other presets. Supports Dark Mode. I tried to recreate Apple's

Ivan Vorobei 1.8k Jan 7, 2023
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Paolo Musolino 2.5k Jan 3, 2023