Swiftpack.co -  alxrguz/ALPopup as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
alxrguz/ALPopup
Native card controller like AirPods or Wi-Fi password sharing
.package(url: "https://github.com/alxrguz/ALPopup.git", from: "1.0.9")

ALPopup

Navigation

Requirements

  • iOS 11.0 +
  • Swift 5.3 +

Installation

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate ALPopup click File -> Swift Package -> Add Package Dependency and insert:

https://github.com/alxrguz/ALPopup

CocoaPods

ALPopup is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ALPopup'

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate ALPopupController into your project manually. Put Source/ALPopup folder in your Xcode project.

Usage

Quick Start

First of all import library

import ALPopup

Use ALPopup.card for create card (it is similar to the one shown when the airpods are connected to your device), if you need a regular popup - use ALPopup.popup (it will be displayed in the middle of the screen).

For present controller use:

cardController.push(from: UIViewController, haptic: ALHaptic)

For dismiss controller use:

cardController.pop(completion: (() -> Void))

There are 3 options for configure the controller:

  1. As a template

Create controller with .init(template: ALTemplateSettings)

let popupVC = ALPopup.card(template: .init(
                                        title: "Hi",
                                        subtitle: "This is popup template controller",
                                        image: UIImage(systemName: "airpodspro"),
                                        privaryButtonTitle: "Connect",
                                        secondaryButtonTitle: "Not Now")
                )
popupVC.push(from: self)

All template fields are optional, if you do not specify some property, then it simply will not be shown.

  1. Using your controller

Create controller with .init(controller: UIViewController)

let baseViewController = BaseViewController()
let cardVC = ALPopup.card(controller: baseViewController)
cardVC.push(from: self)

In order for the size to be calculated correctly, you need your controller to be correctly laid out (If you have difficulty - see Example App BaseViewController).

  1. Inherit from controller
class InheritedFromCardController: ALCardController { }

class InheritedFromPopupController: ALPopupControlle { }

let myCardVC = InheritedFromCardController()
myCardVC.push(from: self)

let myPopupVC = InheritedFromPopupController()
myPopupVC.push(from: self)

Be careful, if you inherit, then all your elements must be added to the contentView (see Example App InheritedFromPopupController)

Customization

Base customization

Is close Button show on controller

myPopupVC.isEnableCloseButton = true

Should the controller be closed by tap on the darkened area

myPopupVC.dismissByTapAround = true

Whether swipe to dismiss should be allowed. Defaults is true.

myPopupVC.allowsSwipeInteraction = true

If you set this to false, the pan gesture will continue to be recognized, but with noticeable resistance and the user won't be able to close the controller with a swipe.

The home indicator for iPhone X should be hidden or not. Defaults is true.

myPopupVC.isHomeIndicatorVisible = true

Rounding corners in superellipse for contentView. Default is true

myPopupVC.superellipticRounding = true

Gives nicer and more correct rounding, but does not work well with frame animations.

Template customization

Suitable if the controller is created using: .init(template: ALTemplateSettings)

The template has 5 elements in total, all of them are open and can be changed at your discretion

// Create Controller
let popupVC = ALPopup.card(template: .init(
                                        title: "Hi",
                                        subtitle: "This is popup template controller",
                                        image: UIImage(systemName: "airpodspro"),
                                        privaryButtonTitle: "Connect",
                                        secondaryButtonTitle: "Not Now")
                )

// Setup templateView
popupVC.tempateView.titleLabel
popupVC.tempateView.subtitleLabel
popupVC.tempateView.imageView
popupVC.tempateView.primaryButton
popupVC.tempateView.secondaryButton

// Show 
vc.push(from: self)

Callbacks are prepared for handling button presses

popupVC.tempateView.primaryButtonAction = { [weak self] in }
popupVC.tempateView.secondaryButtonAction = { [weak self] in }

By the way, the template uses extended ALActionButton buttons, so it is more convenient to change their color using:

popupVC.tempateView.primaryButton.applyDefaultAppearance(with: .init(content: .systemBlue, background: .systemGroupedBackground))

License

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

GitHub

link
Stars: 27
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

Welcome
4 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics