Drawer
is a framework that enables you to easily embed a UIViewController
in a drawer and display it on top of another UIViewController
.
github "nodes-ios/Drawer"
pod 'NDrawer'
UIViewController
for the drawer to be displayed over. This ViewController
is referred to as the backgroundViewController
in the following stepsUIViewController
to act as the content of the drawer. This ViewController
is referred to as the contentViewController
in the following steps.Start by conforming your contentViewController
to the Embeddable
protocol. This exposes several delegate functions to the contentViewController
.
extension ContentViewController: Embeddable {}
Furthermore an instance of EmbeddableContentDelegate
is exposed. This delegate
can be used to instruct the drawer to perform various tasks by calling the handle
function on it.
The handle
function takes an enum
of type Drawer.Action
which allows these actions:
layoutUpdated(config: Drawer.Configuration)
to update the layout of your drawerchangeState(to: MovementState)
to show/hide your drawer.After creating the contentViewController
, initialize an instance of DrawerCoordinator
in your backgroundViewController
to initialize the drawer.
let drawer = DrawerCoordinator(contentViewController: contentVC,
backgroundViewController: self,
drawerBackgroundType: .withColor(UIColor.black.withAlphaComponent(0.5)))
After your content's views have finished creating and you are ready to display the drawer, create an instance of Drawer.Configuration
to set the drawer state and properties.
let options: [Drawer.Configuration.Key : Any] = [
.animationDuration: 0.5,
.fullHeight: maxHeight,
.minimumHeight: minHeight,
.initialState: Drawer.State.minimized,
.cornerRadius: Drawer.Configuration.CornerRadius(fullSize: 20,
minimized: 0)
]
let contentConfiguration = Drawer.Configuration(options: options,
dismissCompleteCallback: nil)
Communication with the EmbeddableContentDelegate
is managed by calling the handle
function, which takes an enum
of type Drawer.Action
as a parameter.
Finally call the EmbeddableContentDelegate
handle
function to update the drawer's layout to the new Configuration
embedDelegate?.handle(action: .layoutUpdated(config: contentConfiguration))
To expand and collapse the drawer programatically, call the EmbeddableContentDelegate
handle
function with a changeState
action containing the state which the drawer should transition to.
embedDelegate?.handle(action: .changeState(to: .fullScreen))
To learn more, please refer to the example project contained in this repository.
Made with ❤️ at Nodes.
Drawer is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 11 |
Last commit: 2 years ago |
All you get in this release is support for Swift Package Manager so if you were hoping for more...well we're sorry 🤷♂️
Thank you for using Drawer. If you have suggestions for new features or improvements, please let us know.
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics