Giter Site home page Giter Site logo

antoniocasero / panels Goto Github PK

View Code? Open in Web Editor NEW
1.5K 29.0 89.0 39.59 MB

Panels is a framework to easily add sliding panels to your application

License: MIT License

Swift 97.58% Ruby 2.42%
swift4 sliding-menu sliding panel panels safe-area iphone-x containerviewcontroller ui ux

panels's Introduction

Build Status Carthage compatible CocoaPods Platform Language

Twitter

Panels is a framework to easily add sliding panels to your application. It takes care of the safe area in new devices and moving your panel when the keyboard is presented/dismissed.

Updated to Swift 5.1

Sliding Panel demo1 Sliding Panel demo2 Sliding Panel demo3

Usage

First, create your own panel, you can use Interface Builder, use as reference the examples provided. Make sure that you conform the protocol Panelable

import UIKit
import Panels

class PanelOptions: UIViewController, Panelable {
    @IBOutlet var headerHeight: NSLayoutConstraint!
    @IBOutlet var headerPanel: UIView!
}

This protocol defines the interface needed to be able to adjust the sliding panel to the container, expanding and collapsing. It will take care of the safe area

Then in your ViewController, where the panel is presented:

class YourViewController: UIViewController {
    lazy var panelManager = Panels(target: self)
    override func viewDidLoad() {
        super.viewDidLoad()
        let panel = UIStoryboard.instantiatePanel(identifier: "YourPanelName")
        let panelConfiguration = PanelConfiguration(size: .oneThird)
        
        // To present the panel
        panelManager.show(panel: panel, config: panelConfiguration)
        ....
        // To dismiss the panel
        panelManager.dismiss()
    }
}

If you want to get notifications when the panel is presented, collapsed or expanded, just conform the protocol PanelNotifications

You can find extra options in the PanelConfiguration object:

    /// Storyboard name, the first Viewcontroller will be instantiated
    public var panelName: String

    /// Panel height
    public var panelSize: PanelDimensions

    /// Panel margins between the header and the next views.
    public var panelMargin: CGFloat

    /// Visible area when the panel is collapsed
    public var panelVisibleArea: CGFloat

    /// Safe area is avoided if this flag is true.
    public var useSafeArea = true

    /// Collapse and expand when tapping the header view.
    public var respondToTap = true

    /// Collapse and expand when dragging the header view.
    public var respondToDrag = true

    /// Collapse when tapping outside the panel
    public var closeOutsideTap = true

    /// Animate the panel when the superview is shown.
    public var animateEntry = false

    /// If parent view is a navigationcontroller child, this flag allow a better calculation when the panelSize is .fullScreen
    public var enclosedNavigationBar = true

You could add an arrow indicator to give more feedback to your panels. The perfect companion for Panels is Arrows

Arrows Example

Installation

CocoaPods

Add the line pod "Panels" to your Podfile

Carthage

Add the line github "antoniocasero/Panels" to your Cartfile

SPM

dependencies: [
  .package(url: "https://github.com/antoniocasero/Panels.git", from: "2.2.3")
]

Author

Project created by Antonio Casero (@acaserop on Twitter).

Credits

Sketch UI (Elements)

panels's People

Contributors

antoniocasero avatar chalkdust avatar jondwillis avatar julianschiavo avatar ykws 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar

panels's Issues

crash when running on real device

Hi,
I installed the panels pod and setup all the necessary code, then i launched the app on the simulator and everything works like a charm, but when i try to run on a real device the app crashs with the next error:

dyld: Library not loaded: @rpath/Panels.framework/Panels
Referenced from: /private/var/containers/Bundle/Application/4CA47637-BDFB-4473-9305-729F57C14B4A/Metro Sahel.app/Metro Sahel
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/4CA47637-BDFB-4473-9305-729F57C14B4A/Metro Sahel.app/Frameworks/Panels.framework/Panels: code signature invalid for '/private/var/containers/Bundle/Application/4CA47637-BDFB-4473-9305-729F57C14B4A/Metro Sahel.app/Frameworks/Panels.framework/Panels'

Capture d’écran 2020-03-05 à 11 24 28 PM

Xcode version : 11.3.1
Device used: iPhone 7 Plus / iOS 13.3.1

keyboard present and Penel moves up with the keyboard

Hi
I am getting this behavior when a panel is present and the keyboard is opened. Penel moves up and fits the keyboard top(below picture).
How to stop this behavior?
I have tried keyboard observer too but no success yet.
conf.keyboardObserver = false
Thanks for this nice library.

IMG_475D92C76697-1

Panel reopens after being dismissed

I have created a Panel and when it is called I call the show function on the panel. Everything works fine here.

lazy var panelManager = Panels(target: self)
let panel = UIStoryboard.instantiatePanel(identifier: "Timer")
var panelConfiguration = PanelConfiguration(size: .custom(230))
panelConfiguration.animateEntry = true
panelConfiguration.useSafeArea = false
panelConfiguration.respondToDrag = true
panelConfiguration.respondToTap = false
self.panelManager.show(panel: panel, config: panelConfiguration)

My issue arrises when I try to dismiss the panel using the panelManager.
self.panelManager.dismiss()
I'm calling the dismiss function when I Post to NotificationCenter that the timer was stopped. I'm using the PanelNotification to see when it is presented to begin observing when the timer will be stopped.

    func panelDidPresented() {
        isPannelOpen = true
        panelDismissed = false
        NotificationCenter.default.post(name: .CurrentSession, object: nil, userInfo: ["sessionInterval": sessionInterval,
                                                                                       "sessionClientName": sessionClientName])
        NotificationCenter.default.addObserver(self, selector: #selector(timeLeft(notification:)), name: .TimeLeft, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(stopTimer(notification:)), name: .StopTimer, object: nil)

        print("Did present")
    }
    @objc func stopTimer(notification: Notification) {
        self.panelManager.dismiss()
        self.timer?.invalidate()
        self.timer = nil
        NotificationCenter.default.removeObserver(self, name: .TimeLeft, object: nil)
        NotificationCenter.default.removeObserver(self, name: .StopTimer, object: nil)
        NotificationCenter.default.removeObserver(TimerViewController(), name: .CurrentSession, object: nil)
    }

Initially it works and the panel will be dismissed, but when I scroll up or down on the table view...
weirdgrandioseghostshrimp-size_restricted

I can't seem to figure out how to stop it from doing this. Does using NotificationCenter not work well with Panels?

Show the Panels on top of a TabBar

Is it possible to show/present a panel from a view controller that is in a TabBar? I want to show a Panel and present it on top of the TabBar. Thanks

HeaderHeight calculation pushes Header further down with each show

The premise is relatively simple, looking at https://github.com/antoniocasero/Panels/blob/master/Sources/Panels.swift#L50 the safeAreaBottom is added to the PanelHeightConstraint every time show is being executed.

Now in my specific use case, I instantiate the Panelable VC with my parent VC and only show the Panel on didSelect, I dismiss it on didDeselect. With this behavior, the headerHeigh grows every time I execute show which ends up pushing my header further down each time.
The examples show the same behavior (although, it's constraints break and recovery recovers the correct constraints).

Specify a platform for this target in Example Podfile

$ pod install

...

[!] Automatically assigning platform `ios` with version `11.2` on target `Panels_Example` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

need some help

Hi,

I've tried to put the material panel at the top of view controller but I couldn't. Is there any way to do this?

'NSInvalidArgumentException

Followed all the steps and the demo project. But whenever I try call panel view controller, ti gives me the following errors
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView constant]: unrecognized selector sent to instance.

2nd time dismiss animation works but panel stay

Panel

  1. Show
  2. Dismiss
  3. Show
  4. Dismiss (Here after dismiss animation, panel stay remain on visible position )

Any help?

Below is my code, took latest from pods (2.0.3)

            if self.currentPanel != nil {
                panelManager?.dismiss()
                self.currentPanel = nil
            } else {
                currentPanel = UIStoryboard.instantiatePanel(identifier: "PanelOptions")
                var panelConfiguration = PanelConfiguration(size: .custom(200))
                panelConfiguration.panelVisibleArea = 30
                
                panelManager?.show(panel: currentPanel as! UIViewController & Panelable, config: panelConfiguration)
            }

Example app crashes if you tap "Close" twice

The example app crashes while unwrapping an optional if you open the "Material" example, then open the panel and tap Close a few times.

movePanel(value:keyboard:completion:)

panelHeightConstraint!.constant = value
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

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.