A custom SwiftUI modifier to present an ActionSheet or a Popover menu

Related tags

Menu ActionOver
Overview

ActionOver

A custom SwiftUI modifier to present an Action Sheet on iPhone and a Popover on iPad and Mac.

iPhone Preview

iPad Preview

Mac Preview

Features

Availables

  • Slidable and dismissable with drag gesture.
  • Light/Dark mode.
  • Customizable button color.
  • Custon popup position on ipad and mac.
  • Custom popup arrow edge position on ipad and mac.
  • iOS compatibility
  • iPad compatibility
  • Mac compatibility

Installation

Requirements

  • iOS 13.0+ / macOS 10.15.4+
  • Xcode 11.2+
  • Swift 5+

Via Swift Package Manager

In Xcode 11 or grater, in you project, select: File > Swift Packages > Add Pacakage Dependency.

In the search bar type ActionOver and when you find the package, with the next button you can proceed with the installation.

If you can't find anything in the panel of the Swift Packages you probably haven't added yet your github account. You can do that under the Preferences panel of your Xcode, in the Accounts section.

How to Use

To use the Action Over just attach the new modifier:

YourView
.actionOver(
    presented: Binding<Bool>,
    title: String,
    message: String?,
    buttons: [ActionOverButton],
    ipadAndMacConfiguration: IpadAndMacConfiguration,
    normalButtonColor: UIColor = UIColor.label
)

If you want a starting point copy in your ContentView file the following code:

import SwiftUI
import ActionOver

struct ContentView: View {

    @State var presented = false

    var body: some View {
        NavigationView {
            VStack(alignment: .leading, spacing: 40) {
                Text("""
                Hi, this is the Action Over modifier.

                With this modifier you will preset an Action Sheet on iPhone
                and a Popover on iPad and Mac.

                You will write just once your actions, and with a single modifier
                you will dislay the proper menu according the user's device.
                """)
                Button(action: {
                    self.presented = true
                }, label: {
                    Text("Show Action Over")
                })
                    .actionOver(
                        presented: $presented,
                        title: "Settings",
                        message: "Wich setting will you enamble?",
                        buttons: buttons,
                        ipadAndMacConfiguration: ipadMacConfig
                )
                HStack {
                    Spacer()
                }
                Spacer()
            }
            .padding()
                .navigationBarTitle("Action Over", displayMode: .large)
        }
        .navigationViewStyle(StackNavigationViewStyle())
    }

    private var buttons: [ActionOverButton] = {
        return [
            ActionOverButton(
                title: "Option one",
                type: .normal,
                action: {}
            ),
            ActionOverButton(
                title: "Option two",
                type: .normal,
                action: {}
            ),
            ActionOverButton(
                title: "Delete",
                type: .destructive,
                action: {}
            ),
            ActionOverButton(
                title: nil,
                type: .cancel,
                action: nil
            ),
        ]
    }()

    private var ipadMacConfig = {
        IpadAndMacConfiguration(anchor: nil, arrowEdge: nil)
    }()
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Comments
  • Runtime error on macOS - needs 10.15.4

    Runtime error on macOS - needs 10.15.4

    Andrea, thank you for this code! However, I am attempting to run it via Catalyst on my Mac and I am getting this error:

    application requires at least OS X version 10.15.4 (10.15.4), but is being run on 10.15.3 ( 10.15.3/19D76), and so is exiting.

    I am using Xcode 11.4.1 and have been able to run other Catalyst apps under 10.15.3 so what is the problem here? I've searched the code looking for special OS requirements but can't find any.

    Now, before you suggest I update to 10.15.4 let me tell you my horror story. I did update to 10.15.4 and I have spent the last five days trying undo that foolish decision! 10.15.4 is a nightmare of bugs. Mail, Messages, Contacts, Spotlight, all break with the "not responding" status. I had an external boot disk with 10.15.3 but some obtuse security "feature" in 10.15.4 prevents using an external disk as a startup disk. After days of searching for a backdate solution I was finally able to restore my machine back to 10.15.3.

    Any ideas?

    opened by WholeCheese 5
  • Suggestions

    Suggestions

    I have a couple of minor changes I would like to suggest that I have implemented on a branch. I can list them here or create a PR. Which do you prefer? I guess I need better access to create a PR?

    opened by SAPIENTechnologies 3
  • Not building for MacOS

    Not building for MacOS

    Hello, thanks for the great package. It says Mac compatible, but it is only building in iOS for me. It looks like the platforms array in Package.swift only has iOS listed, is that the issue?

    opened by lukemorse 1
  • Missing change

    Missing change

    For some reason, when I update to the latest code in XCode's SWP, the change made to ActionOverViewModifier line 156 has not been updated.

    should be: .padding(.all, 10)

    code shows: .padding(.vertical, 10)

    opened by SAPIENTechnologies 1
  • Compile time errors

    Compile time errors

    Hello. I have installed this package as directed and have tried to follow your code example. Rather than put it directly into contentView, I have created an ActionButton with body as such...

    var body: some View { Button( action: { self.showActions = true}, label: { Image(systemName: "plus").font(.title) } ) .actionOver( presented: $showActions, title: "Options", message: "", buttons: buttons, ipadAndMacConfiguration: ipadMacConfig ) }

    I create ActionButton array as your sample shows and an ipadMacConfig.

    The following errors appear: Use of undeclared type 'ActionOverButton' Use of unresolved identifier 'IpadAndMacConfiguration' 'actionOver' is inaccessible due to 'internal' protection level

    I have tried importing ActionOver to no avail. Any ideas?

    opened by SAPIENTechnologies 1
  • Cannot find 'self' in scope

    Cannot find 'self' in scope

    Cannot find 'self' in scope when calling finction on action handler.

       var actionButtons: [ActionOverButton] = {
            return [
                ActionOverButton(
                    title: "Edit Profile",
                    type: .normal,
                    action: {}
                ),
                ActionOverButton(
                    title: "Change Password",
                    type: .normal,
                    action: {}
                ),
                ActionOverButton(title: "Sign out", type: .destructive) {
                    self.setting()
                },
                ActionOverButton(
                    title: nil,
                    type: .cancel,
                    action: nil
                ),
            ]
        }()
    
    
        private var ipadMacConfig = {
            IpadAndMacConfiguration(anchor: nil, arrowEdge: nil)
        }()
    
        func setting() {
    
        }
    }
    
    

    Edit - Solved

    
    var actionButtons: [ActionOverButton] {
            return [
                ActionOverButton(
                    title: "Edit Profile",
                    type: .normal,
                    action: {}
                ),
                ActionOverButton(
                    title: "Change Password",
                    type: .normal,
                    action: {}
                ),
                ActionOverButton(title: "Sign out", type: .destructive) {
                    self.setting()
                },
                ActionOverButton(
                    title: nil,
                    type: .cancel,
                    action: nil
                ),
            ]
        }
    
    opened by toseefkhilji 0
  • Grammar/spelling changes and padding change

    Grammar/spelling changes and padding change

    ContentView: Minor spelling and grammatical changes

    ActionOverViewModifier: changed padding for popover from .vertical to .all to give nicer padding when no message is present

    opened by SAPIENTechnologies 0
Owner
Andrea Miotto
iOS Developer
Andrea Miotto
Weather Dock is a MacOS headless application that shows popover view under the menu bar with weather info.

Weather Dock Weather forecast in MacOS menu bar Weather Dock is a MacOS headless application that shows popover view under the menu bar with weather i

Alexander Stepanischev 8 Dec 15, 2022
EasyMenu - SwiftUI Menu but not only button (similar to the native Menu)

EasyMenu SwiftUI Menu but not only button (similar to the native Menu) You can c

null 10 Oct 7, 2022
SwiftySideMenu is a lightweight and easy to use side menu controller to add left menu and center view controllers with scale animation based on Pop framework.

SwiftySideMenu SwiftySideMenu is a lightweight, fully customizable, and easy to use controller to add left menu and center view controllers with scale

Hossam Ghareeb 84 Feb 4, 2022
A Slide Menu, written in Swift, inspired by Slide Menu Material Design

Swift-Slide-Menu (Material Design Inspired) A Slide Menu, written in Swift 2, inspired by Navigation Drawer on Material Design (inspired by Google Mat

Boisney Philippe 90 Oct 17, 2020
Slide-Menu - A Simple Slide Menu With Swift

Slide Menu!! Весь интерфейс создан через код

Kirill 0 Jan 8, 2022
Swift-sidebar-menu-example - Create amazing sidebar menu with animation using swift

 SWIFT SIDEBAR MENU EXAMPLE In this project I create a awesome side bar menu fo

Paolo Prodossimo Lopes 4 Jul 25, 2022
Hamburger Menu Button - A hamburger menu button with full customization

Hamburger Menu Button A hamburger menu button with full customization. Inspired by VinhLe's idea on the Dribble How to use it You can config the looks

Toan Nguyen 114 Jun 12, 2022
RadialMenu is a custom control for providing a touch context menu (like iMessage recording in iOS 8) built with Swift & POP

RadialMenu Looking for help? For $150/hr I'll help with your RadialMenu problems including integrating it into your project. Email [email protected] t

Brad Jasper 297 Nov 27, 2022
RadialMenu is a custom control for providing a touch context menu (like iMessage recording in iOS 8) built with Swift & POP

RadialMenu Looking for help? For $150/hr I'll help with your RadialMenu problems including integrating it into your project. Email [email protected] t

Brad Jasper 297 Nov 27, 2022
adb-tools-mac is a macOS menu bar app written in SwiftUI for common adb tools.

adb-tools-mac is a macOS menu bar app written in SwiftUI for common adb tools.

Naman Dwivedi 930 Jan 2, 2023
Ambar is a macOS Menu Bar app built with SwiftUI.

Ambar Ambar is a macOS Menu Bar app built with SwiftUI. It is a template project which means that it can be used as a starting point for a new Menu Ba

null 16 Nov 14, 2022
An easy way to use `canPerformAction` for context menu in SwiftUI.

Use canPerformAction for TextField/Editor in SwiftUI You know how a TextField displays a set of context menu? It doesn't matter if it's UIKit or Swift

StuFF mc 5 Dec 18, 2021
Easily create dragabble menu with SwiftUI

SwiftUIDragMenu Easily create dragabble menu The gifs are not very good quality. Content is fluid. Sorry for this :( How to install this package Open

Mehmet ateş 1 Dec 5, 2022
A simple customizable side menu written in SwiftUI.

NSideMenu Description A simple customizable side menu written in SwiftUI. Give a Star! ⭐ Feel free to request an issue on github if you find bugs or r

null 5 Oct 10, 2022
Steven Troughton-Smith 57 Dec 6, 2022
SwiftUI Slideoutmenu - Sample Project for slideout menu

SwiftUI_Slideoutmenu This is a sample code project for a slideout menu. Simulato

Rob Evans 17 Dec 2, 2022
Slide Menu (Drawer) in Swift

AKSwiftSlideMenu Slide Menu (Drawer) in Swift 5.0 Why to use a library everytime? Let's create our own Slide Menu in Swift 5.0 I have uploaded a video

Ashish Kakkad 281 Jan 5, 2023
⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion

CIRCLE MENU Simple, elegant UI menu with a circular layout and material design animations We specialize in the designing and coding of custom UI for M

Ramotion 3.4k Dec 29, 2022
A simple side menu for iOS written in Swift.

ENSwiftSideMenu A lightweight flyover side menu component for iOS with the UIDynamic's bouncing animation, UIGestures and UIBlurEffect. Allows you to

Evgeny Nazarov 1.8k Dec 21, 2022