Code Monkey home page Code Monkey logo

sheeeeeeeeet's Introduction

Sheeeeeeeeet Logo

Version Swift 5.6 Swift UI MIT License Twitter: @danielsaidi Mastodon: @danielsaidi@mastodon.social

About Sheeeeeeeeet

Sheeeeeeeeet is a UIKit library that lets you create menus that can be presented as custom action sheets, context menus, alert controllers, or in any way you like.

The result can look like this or completely different:

Sheeeeeeeeet comes with many item types (standard items, buttons, titles, toggles, etc.) and can be extended with your own custom item types.

About this repository

Since I have personally moved over to SwiftUI, this repository is no longer under active development. I will however gladly merge any PRs that add value to it or fixes problems with new iOS versions.

Installation

Sheeeeeeeeet can be installed with the Swift Package Manager:

https://github.com/danielsaidi/Sheeeeeeeeet.git

or with CocoaPods:

pod Sheeeeeeeeet

If you prefer to not have external dependencies, you can also just copy the source code into your app.

Supported Platforms

Sheeeeeeeeet supports iOS 9 and later.

Getting Started

Creating a menu

With Sheeeeeeeeet, you start with creating a menu, like this:

let item1 = MenuItem(title: "Int", value: 1)
let item2 = MenuItem(title: "Car", value: Car())
let button = OkButton(title: "OK")
let items = [item1, item2, button]
let menu = Menu(title: "Select a type", items: items)

The library has many built-in item types, e.g. buttons, select items, links, etc. A complete list can be found here.

You can also create your own custom item types by inheriting any of the existing ones. For instance, if you build a car rental app, you can create a car-specific item that takes a Car model.

You can even create your own menu types by subclassing Menu. This makes it possible to create app-specific menus that provide specific functionality, handle specific tasks, etc.

Presenting a menu as an action sheet

You can present menus as custom action sheets:

let sheet = menu.toActionSheet(...) { sheet, item in ... }
sheet.present(in: vc, from: view) { sheet, item in ...
    print("You selected \(item.title)")
}

You can find more information in this action sheet guide.

Adding a menu as a context menu

You can add menus as iOS 13 context menus to any view you like:

menu.addAsContextMenu(to: view) { sheet, item in ...
    print("You selected \(item.title)")
}

You can find more information in this context menu guide.

Presenting a menu as an alert controller

You can present menus as UIAlertControllers:

let delegate = menu.presentAsAlertController(in: self, from: view) { sheet, item in ...
    print("You selected \(item.title)")
}

You can find more information in this alert controller guide.

Demo Application

The demo demonstrates different menus and menu items, including subclassing and appearance adjustments. To try it out, just open and run the Sheeeeeeeeet project.

Support

You can sponsor this project on GitHub Sponsors or get in touch for paid support.

Contact me

Feel free to reach out if you have questions or if you want to contribute in any way:

License

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

sheeeeeeeeet's People

Contributors

binarydennis avatar danielsaidi avatar itsliamdowd avatar mohammadghk avatar mx-iris avatar sebbo176 avatar senseiphonex avatar ullstrm avatar woxtu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sheeeeeeeeet's Issues

How to center text in option ?

If say I need to center option text in an item, how to do that ?
In addition, how to change color of the option text ?

appearance does not seem to work for color change:

        clearAction.appearance.textColor = .red
        clearAction.appearance.tintColor = .red

And there seems no options for do text adjustment :(

Delegate for Danger Button pressed?

Is there a way to detect the Danger button was pressed? My code is below.

 func createStandardActionSheet(indexPath: IndexPath) -> ActionSheet {
        let title = ActionSheetTitle(title: "Select an option")
        let item1 = ActionSheetItem(title: "View Code", value: "1", image: UIImage(named: "baseline_pageview_black_18pt"))
        let item2 = ActionSheetItem(title: "Edit Profile", value: "2", image: UIImage(named: "baseline_create_black_18pt"))
        let item3 = ActionSheetItem(title: "Share Profile", value: "3", image: UIImage(named: "baseline_share_black_18pt"))
        let deleteButton = ActionSheetDangerButton(title: "Delete Profile")
        let button = ActionSheetOkButton(title: "Cancel")
        return ActionSheet(items: [title, item1, item2, item3, deleteButton, button]) { _, item in
            guard let value = item.value as? String else { return }
            if value == "1" {
                //do stuff
            } else if value == "2" {
               //do stuff
            } else if value == "3" {
                //do stuff
            } 
        }
    }

Scroll handling behaves incorrectly

The standard presenter handles scrolling incorrectly, where a sheet scrolls when it shouldn't and behaves strange after orientation change.

Items not showing, not responding and not respecting width

I'm trying to present a Sheeeeeeeeet from the example code:

        let title = ActionSheetTitle(title: "Select an option")
        let item1 = ActionSheetItem(title: "Option 1", value: "1", image: image1)
        let item2 = ActionSheetItem(title: "Option 2", value: "2", image: image2)
        let button = ActionSheetOkButton(title: "OK")
        let action = ActionSheet(items: [title, item1, item2, button]) { (_, item) in
            guard let value = item.value as? String else { return }
            // You now have the selected value, e.g. "1". The ok button uses `true`.
        }
        action.present(in: self, from: view)

Unfortunately, this is what I get:

screen shot 2018-02-22 at 11 32 24

Not only are the items not visible, but the Sheeeeeeeeet doesn't seem to respect the width of the device.

Tapping any of the items doesn't do anything. Tapping outside the Sheeeeeeeeet doesn't do anything as well. This happens on my iPhone 8+ as well, not only in the simulator.

The example project is working as intended though!

Tap behavior .none but still highlight on tap

I need to execute my own actions when a ActionSheetCustomButton is tapped (opening a modal). At the moment I have to set the tapBehavior for the button to .none otherwise the default value .dismiss causes the sheet to close when tapped however .none seems to disable the highlight color and that's not what I want.

Presenting ActionSheet in SplitView on iPad removes underlying ViewController

Hi Daniel,

Presenting an ActionSheet, while SplitViewing a second App results in a black Background ( / the underlying Views being removed !? )

How to reproduce:

  1. Run SheeeeeeeeetExample Project on an iPad with SplitView capability
  2. Open a second App and activate SplitView
  3. Try any ActionSheet
  4. Black Background

I uploaded some Images / Screenshots for you:
https://imgur.com/a/UEY85Zw

I hope you can identify the Problem faster than I can

Love your Pod ❤️
Dominic

iPhone X horizontal inset bug

Sheeeeeeeeet honors the bottom safe area on an iPhone X, but it does not honor the horizontal safe areas, which causes the action sheets to extend beyond the notch in landscape.

Please update readme

Creating and presenting an action sheet section contains code which seems to be deprecated/removed from library

Use stack view instead of manually positioned views

Today, the three possible sections (header + items + buttons) are manually positioned in code, which leads to a lot of additional code in the action sheet. Sheeeeeeeeet should use a stack view instead.

Popovers should not close when the app resigns its active state

In order to fix the flickering issue that did occur when the app had a popover sheet presented when it was awaken from the background, I added a notification check that hid the sheet when the app was sent to the background. Since the flicker bug has been solved, this is no longer needed.

Changing appearance of individual items

How can i change the appearance of individual items?
I tried this with no success

let a = ActionSheetItem(title: "foo", value: "1", image: nil )
a.appearance.textColor = .brown

Simplify select item handling

Today, the select item type has no built-in selection logic, which means that you have to intercept that a select item is selected, then handle stuff like:

  • Single or multi-select items should have .none as default tap behavior
  • Single select items should auto-deselect all other items
  • Single select items should only auto-deselect all other items within the same section

Cancel button in iPad Popover

Hi Daniel,

I have notice that ActionSheetCancelButton button is visible in iPad popover.

Generally cancel button should not be in popover.

Quick Solution:
Before adding ActionSheetCancelButton item We can check if device is iPad or not.

But It would be great if this can be handle in Great Sheeeeeeeeet lib.

Thanks.

How to access values from a custom item

I received this e-mail:

Good afternoon!

I have a question about your Sheeeeeeeeet Cocoapod. If I create a custom view with things such as a UITextField, DatePicker, etc, how would I go about accessing these values when I click OK? Here is some code to show what I was attempting to do:

let title = ActionSheetTitle(title: "App Info")
let customType = CustomViewCell.self
let item1 = ActionSheetCustomItem(cellType: customType) { cell in
let formatter = DateFormatter()
formatter.dateFormat = "MM/dd/yyyy"
            
       //set to current date
cell.updatedLabel.text = formatter.string(from: Date())
}
       
let button = ActionSheetOkButton(title: "Save")
return ActionSheet(items: [title, item1, button]) { sheet, item in
   
if item is ActionSheetOkButton {
             print("Save buttons has the value `true`")
              //access the values in item1 and do something with the data
       }
}

Thoughts on what I am missing?

Action when a link is selected.

Can we create an action handler whenever a link is selected without removing the action sheet that was use. I want to present an alert view when I want the user to be able to come back to the same action sheet when they are finish with the alert.

Sheeeeeeeeet on iPhone in Landscape Mode

Hi Daniel,
your library looks very great (it's really a nice job!!) and I'm considering to use it in my app.
I need to show until 8 options in actionsheet, so, to try, I modified foodOptions() function in SheeeeeeeeetExample like this

func foodOptions() -> [FoodOption] {
    return [.fast, .light, .homeMade, .fancy, .none, .fast, .light, .none]
}

and this is how action sheet appear on iPhone 7 simulator in landscape mode
simulator screen shot - iphone 7 - 2017-12-19 at 12 30 42
I think in this case the action sheet should be able to scroll so that any option can be available (like Dropbox iOS app or Google Drive iOS app, for example).

Thanks,
Giorgio

Default presenter should not have an iPad presenter

The current action sheet presenter setup, where the ActionSheetDefaultPresenter class has an embedded presenter for iPad, is just horrible.

Instead, the action sheet should resolve the correct default presenter depending on the current device, and let the user set a custom presenter whenever needed.

CocoaPod doesn't include xib files

The collection item doesn't work when Sheeeeeeeeet is installed with CocoaPods. The xib isn't included in the spec, which cause the app to crash.

Action sheet doesn't honor the notch after orientation change

Today, an action sheet is correctly positioned in relation to a possible notch, which means that if you present a sheet in landscape, it uses the safe area insets. However, if you present the sheet in portrait then flip to landscape, it no longer uses the safe area insets, which causes it to expand beyond the notch.

Add option to hide the header view in landscape.

Today, an action sheet always displays its header view, if one is set. However, on since iPhone landscape height is really limited, maybe there should be an option to hide the header view if the sheet is presented in landscape.

No support for iPad Multitasking (Split-view)

Hi!
Great library, I like it a lot.

However, It lacks the ability to switch between popover and action sheet modes when I change split-view mode on iPad.
Also, it presents itself on 2/3 split screen like it is an iPhone, while standard iOS ActionSheet still presents as a popover.

Please, take a look at this video: https://youtu.be/sS_jcHx8R-I

I tried to fix it myself but found that it requires some API change.

Multi-Select Select/Unselect All feature

Hi Daniel,

Thanks for the great library.

I need help your help adding Select/unselect All in Multi-select sheet.

I want to select all other ActionSheetItem items when user select "All".

Can you help me to achieve this feature?

multi-select

Changing the width of the action sheet on iPad

At the moment I'm setting presenter property of the sheet to a new instance of ActionSheetDefaultPresenter and I pass nil as iPadPresenter. It works as I expected and it shows the mobile sheet on iPad.

However IMO the width is too much on iPad and I would like to make it half as wide.
I tried to create to create a custom presenter but failed to successfully change the frame width.

Please help.

Log level setting

Currently there is print in deinit which prints e.g. ActionSheet deinit. Granted, this print is not frequent and does not have any effect. But it does not feel clean. It would be nice to have some kind of debug printing level setting which disables this print by default and makes enabling it possible when needed.

Allow separator configuration

Mainly turning off and changing color

At the moment one workaround for removing is:

let noSeparator = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: UIScreen.main.bounds.width)
cell.separatorInset = noSeparator

Good: Can be done per cell
Bad: Has to be done for each cell if need to remove all

Hadn't found a way to change color without traversing view hierarchy

Some problems on iPad

Hi Daniel,
I'm running into some trouble using your library on iPad. First, I see an annoying flickering when I put app in background with a Sheeeeeeeeet opened menu and take it in foreground again . To reproduce it

  1. Run Demo
  2. Open a menu (tap on standard row, for example)
  3. Put app in background
  4. Take it in foreground again

Second, in the demo app, when I open Standard menu and I tap a menu item no alert appears. In the console I see

SheeeeeeeeetExample[8754:168099] Warning: Attempt to present <UIAlertController: 0x7fdabd04f400> on <SheeeeeeeeetExample.ViewController: 0x7fdabbc06b10> which is already presenting (null)

Thanks,
Giorgio

Improve how the example presents action sheets on iPads

The example app presents action sheets from the tapped cells. However, this means that on iPad, the popover will not use the available screen height, since it will be displayed above or below the cell.

Instead, present the action sheet from the cell's text label instead. This will make the action sheet float above the cell, making use of the entire iPad screen.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.