Giter Site home page Giter Site logo

parkgwangbeom / sheet Goto Github PK

View Code? Open in Web Editor NEW
335.0 6.0 26.0 6.52 MB

๐Ÿ“‘ Actionsheet with navigation features such as the Flipboard App

License: MIT License

Swift 99.31% Ruby 0.69%
actionsheet sheet navigationsheet navigation ios ui popup custom customactionsheet navigationactionsheet

sheet's Introduction

Logo

Swift 4.0+ iOS 9.0 Version Carthage Compatible Platform License


๐Ÿ“‘ SHEET helps you easily create a wide variety of action sheets with navigation features used in the Flipboard App


Example

Installation

CocoaPods

pod 'Sheet', '~> 0.7.0'

Carthage

github "ParkGwangBeom/Sheet" ~> 0.7.0

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate Sheet into your project manually.

Usage

Implementing the contents of a Sheet is similar to implementing an existing UICollectionViewController. Simply make your view controller subclass of SheetContentsViewController.

import Sheet

class ViewController: SheetContentsViewController {

   /// Sheet visible contents height. If contentSize height is less than visibleContentsHeight, contentSize height is applied.
    override var visibleContentsHeight: CGFloat {
        return 600
    }
    
    /// Give CollectionView a chance to regulate Supplementray Element
    override func registCollectionElement() {
        let nib = UINib(nibName: "TitleHeaderView", bundle: nil)
        collectionView?.register(nib, forSupplementaryViewOfKind: SheetLayoutElement.header.kind, withReuseIdentifier: SheetLayoutElement.header.id)
    }

    /// Provide an opportunity to set default settings for collectionview custom layout
    override func setupSheetLayout(_ layout: SheetContentsLayout) {
        layout.settings.itemSize = { indexPath in
            let height: CGFloat = indexPath.section == 0 ? 30 : 60
            return CGSize(width: UIScreen.main.bounds.width, height: height)
        }
        layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 15, right: 0)
        layout.settings.headerSize = CGSize(width: UIScreen.main.bounds.width, height: 60)
        layout.settings.isHeaderStretchy = true
    }
    
   override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
         ...
        return cell
    }
    
    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         ...
    }
   
     ...
}

You can use the custom action sheet transition using the default api provided by UIKit such as present, push, pop.

๐Ÿ”ฅ However, do not use the dismiss of the NavigationController, but use the close (duration: completion :) function.

// present
let contentsViewController = ViewController()
let sheetNavigation = SheetNavigationController(rootViewController: contentsViewController)
present(sheetNavigation, animated: true, completion: nil)

// push
let nextContentsViewController = NextContentsViewController()
navigationController?.pushViewController(nextContentsViewController, animated: true)

// pop
navigationController?.popViewController(animated: true)

See the Example project for more details.

Layout

Sheet basically has Navigation structure. All children should inherit from SheetContentsViewController. SheetContentsViewController inherits UICollectionViewController by default, and its layout is like the following image.

layout

Please refer to Example Code for detailed setting of image layout.

Advanced

Easily customizable by SheetContents.

Options

Property Type Default Value
defaultToolBarBackgroundColor UIColor .black
sheetToolBarHeight CGFloat 50
isSheetToolBarHidden Bool false
cornerRadius CGFloat 0
defaultVisibleContentHeight CGFloat 240
dimmingViewBackgroundColor UIColor .black.withAlphaComponent(0.3)
sheetBackgroundColor UIColor .white
presentTransitionType SheetPresentTransitionType .scale

Layout Settings

Property Type
headerSize CGSize?
footerSize CGSize?
itemSize ((IndexPath) -> CGSize)?
sectionHeaderSize ((IndexPath) -> CGSize)?
sectionFooterSize ((IndexPath) -> CGSize)?

SheetContentsViewController

Property Type
sheetToolBar UIView
Method Explanation
func registCollectionElement() Give CollectionView a chance to regulate Supplementray Element
func setupSheetLayout() Provide an opportunity to set default settings for collectionview custom layout
func reload() Help reload CollectionView and adjust the height of the content.
func close(completion: (() -> Void)? = nil) Sheet Dismiss

Custom ToolBar

The built-in toolbar consists of a single button.

Default ToolBar

Setting up a Custom ToolBar is very simple.

sheetToolBar = CustomToolBar()

Author

License

Sheet is released under the MIT license. See LICENSE for details.

sheet's People

Contributors

arlupin avatar nobinson94 avatar parkgwangbeom avatar ppth0608 avatar youkchansim 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

sheet's Issues

Bottomsheet close() not working

I appreciate developer for creating this useful library for iOS.

It seems like there is no way to dismiss the sheet from the screen once it become active.
I tried these methods below,

close()
sheetNavigationController?.close()
navigationController?.popViewController(animated: true)

none of them seems working, and the black color behind the sheet seems a bit weird.
It suppose to be transparent i think.

Feature list

[ ] cell, header view
[ ] present, dismiss transition code
[ ] add custom present animator
[ ] add examples
[ ] structured sheet tool bar
[ ] change to layout delegate pattern
[ ] modify the code so that it is possible to have the default viewcontrol as well as the SheetContentsViewController

App Extension Compatibility Request

Hello,

Would much work be required to enable this library to work in the context of an app extension?

I have tried to add this as a pod to my app's share extension target, but on running the share extension it crashed with a runtime issue. I believe it has something to do with the AppDelegate not being present in this context.

Many Thanks,

James

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.