
ProMotion-menu provides a menu component for the popular RubyMotion gem ProMotion. Utilizing MMDrawerController it allows you to easily have a cool Facebook or Path style slide navigation menu, complete with gestures.
The gem was originally named pro_motion_slide_menu
authored by Matt Brewer and continuing development was done by Infinite Red, a web and mobile development company based in Portland, OR and San Francisco, CA. While you're welcome to use it, please note that we rely on the community to maintain it. We are happy to merge pull requests and release new versions but are no longer driving primary development.
Installation
Bundler
Add the following to your project's Gemfile
to work with bundler.
gem 'ProMotion-menu'
Install with bundler:
bundle install
Install pods:
rake pod:install
If you're encountering errors, try cleaning before installing pods:
rake clean:all
Dependenices
This depends on motion-cocoapods and ProMotion.
Rakefile
As of motion-cocoapods v1.3.7, you no longer have to include a pods setup block in your project Rakefile, we can do that for you in the gem.
Creating and Configuring a Menu
To create a menu in your application, you need to start in your AppDelegate:
class AppDelegate < PM::Delegate
def on_load(app, options)
open_menu MyGreatAppScreen.new(nav_bar: true), left: NavigationScreen
self.menu.controller(:left).class.name
end
end
Alternate Approach
If you prefer to keep your menu encapsulated you can create a menu drawer and do your setup there.
class MenuDrawer < PM::Menu::Drawer
def setup
self.center = MyGreatAppScreen.new(nav_bar: true)
self.left = NavigationScreen
self.to_show = [:pan_bezel, :pan_nav_bar]
self.transition_animation = :swinging_door
self.max_left_width = 250
self.shadow = false
end
end
class AppDelegate < PM::Delegate
def on_load(app, options)
@menu = open MenuDrawer
end
def show_menu
@menu.show :left
end
end
Gesture Recognition
By default you can show the menu by panning within 20 pts of the bezel and hide it by panning or tapping
the center view. It's possible to override the default behavior:
open_menu BodyScreen, right: MenuScreen, to_show: :pan_nav_bar, to_hide: [:pan_nav_bar, :tap_nav_bar]
app_delegate.menu.to_show = :pan_center
:pan_nav_bar
:pan_content
:pan_center
:pan_bezel
:all
:none
:pan_nav_bar
:pan_content
:pan_center
:pan_bezel
:tap_nav_bar
:tap_content
:tap_center
:pan_menu
:all
:none
Transition Animation
Changing the transition animation is easy:
app_delegate.menu.transition_animation = :swinging_door
:slide
:slide_and_scale
:swinging_door
:parallax_n
:parallax
:parallax_1
:"parallax_#{Float::MAX}"
To make the menu drawer present the menu from anywhere in your app:
app_delegate.menu.show(:left)
app_delegate.menu.openDrawerSide MMDrawerSideLeft, animated: true, completion: ->(c) { true }
app_delegate.menu.hide
app_delegate.menu.closeDrawerAnimated animated: true, completion: ->(c) { true }
app_delegate.menu.toggle(:left)
app_delegate.menu.toggle_left
app_delegate.menu.toggleDrawerSide MMDrawerSideLeft, animated: true, completion: ->(c) { true }
app_delegate.menu.max_left_width = 250
You can use any UIViewController
subclass you want as the menu controller, but the easiest way to provide this would be to subclass ProMotion::TableScreen
like below:
class NavigationScreen < ProMotion::TableScreen
def table_data
[{
title: nil,
cells: [{
title: 'OVERWRITE THIS METHOD',
action: :swap_center_controller,
arguments: HomeScreen
}]
}]
end
def swap_center_controller(screen_class)
app_delegate.menu.center_controller = screen_class
end
end
More Information
Be sure to check out more documenation from the cocoapod itself, for fun things such as gesture support for showing or dismissing drawers, custom UIBarButtonItems and more.
Help
ProMotion is not only an easy DSL to get started. The community is very helpful and
welcoming to new RubyMotion developers. We don't mind newbie questions.
If you need help, feel free to open an issue on GitHub. If we don't respond within a day, tweet us a link to the issue -- sometimes we get busy.
A very minimal ProMotion-menu sample is available for reference.
Contributing
See CONTRIBUTING.md.
Primary Contributors