You can create a Drawer by calling createDrawer
on the module. It must be added as a top-level view to a Ti.UI.Window. You may want to pass a contentView
property at creation-time. In addition, you can also pass either a leftView
or rightView
property to add an actual drawer view to your layout. All of them (contentView
, leftView
and rightView
) must be instances of Ti.UI.View.
Here's an example:
var TiDrawerLayout = require('com.tripvi.drawerlayout');
var contentView = Ti.UI.createView();
var leftView = Ti.UI.createTableView({ backgroundColor: '#ccc' });
var drawer = TiDrawerLayout.createDrawer({
centerView: contentView,
leftView: leftView
});
And this is how you'd do it in Alloy:
<Alloy>
<Window>
<Drawer id="drawer" module="com.tripvi.drawerlayout" />
</Window>
</Alloy>
var menu = Alloy.createController('menu');
var main = Alloy.createController('main');
$.drawer.setLeftView( menu.getView() );
$.drawer.setCenterView( main.getView() );
leftView
(Ti.UI.View) - sets the left drawerrightView
(Ti.UI.View) - sets the right drawercenterView
(Ti.UI.View) - sets the center ViewisLeftDrawerOpen
(Boolean) - wether the left drawer is currently in an open state or notisLeftDrawerVisible
(Boolean) - wether the left drawer is currently visible on-screen or notisRightDrawerOpen
(Boolean) - wether the right drawer is currently in an open state or notisRightDrawerVisible
(Boolean) - wether the right drawer is currently visible on-screen or notleftDrawerWidth
(Number/String) - sets the width of the left drawerrightDrawerWidth
(Number/String) - sets the width of the right drawerdrawerIndicatorEnabled
(Boolean) - wether it should use the ActionBarDrawerToggle or not(String) - (DEPRECATED) path to a custom drawer indicator imagedrawerIndicatorImage
drawerLockMode
(Number) - sets the lock mode constant. TiDrawerLayout.LOCK_MODE_UNLOCKED (default), TiDrawerLayout.LOCK_MODE_LOCKED_CLOSED, TiDrawerLayout.LOCK_MODE_LOCKED_OPENdragMargin
(Number) - defines the width of the area the user can swipe the drawer inhideToolbar
(Boolean) - hides the toolbar
setLeftView()
- sets the value for theleftView
propertysetRightView()
- sets the value for therightView
propertysetCenterView()
- sets the value for thecenterView
property- (DEPRECATED) same asreplaceCenterView(view, backstack)
setCenterView
but with second parameterview
(Ti.UI.View) - the new centerViewbackstack
(Boolean) - set this totrue
if you want to add this to the backstack
toggleLeftWindow()
- opens or closes the left draweropenLeftWindow()
- opens the left drawercloseLeftWindow()
- closes the left drawertoggleRightWindow()
- opens or closes the right draweropenRightWindow()
- opens the right drawercloseRightWindow()
- closes the right drawergetIsLeftDrawerOpen()
- returns the value of theisLeftDrawerOpen
propertygetIsLeftDrawerVisible()
- returns the value of theisLeftDrawerVisible
propertygetIsRightDrawerOpen()
- returns the value of theisRightDrawerOpen
propertygetIsRightDrawerVisible()
- returns the value of theisRightDrawerVisible
propertysetLeftDrawerWidth()
- sets the value for theleftDrawerWidth
propertysetRightDrawerWidth()
- sets the value for therightDrawerWidth
propertysetDrawerIndicatorEnabled()
- sets the value for thedrawerIndicatorEnabled
property- (DEPRECATED) sets the value for thesetDrawerIndicatorImage()
drawerIndicatorImage
propertysetDrawerLockMode()
- sets the value for thedrawerLockMode
propertysetLeftDrawerLockMode()
- sets the value for thedrawerLockMode
property for the left drawersetRightDrawerLockMode()
- sets the value for thedrawerLockMode
property for the right drawer- (DEPRECATED) sets the state of the drawerArrowIconsetArrowState(value)
value
(Number) - state (1 is arrow, 0 is hamburger, but you can set everything between)
setToolbarHidden
- sets the value forhideToolbar
property
-
change
- fires when the drawer motion state changesstate
(Number) - the new drawer motion stateidle
(Boolean) - indicates that any drawers are in an idle, settled state. No animation is in progressdragging
(Boolean) - indicates that a drawer is currently being dragged by the usersettling
(Boolean) - indicates that a drawer is in the process of settling to a final position
-
drawerslide
- fires when a drawer's position changesoffset
(Number) - the new offset of this drawer within its range, from 0-1drawer
(String) - left or right
-
draweropen
- fires when the drawer motion state changesdrawer
(String) - left or right
-
drawerclose
- fires when the drawer motion state changesdrawer
(String) - left or right
-
Themes: Actionbar vs. Toolbar
- There are two ways to setup the drawer module according to the App bar:
- Traditional: Drawer below App bar (using the Actionbar)
- use default
Theme.AppCompat
orTheme.AppCompat.Light
- use default
- Material: Drawer covers App bar (using the Toolbar)
- use
Theme.AppCompat.NoActionBar
orTheme.AppCompat.Light.NoActionBar
- add toolbar padding
- use
- Traditional: Drawer below App bar (using the Actionbar)
- There are two ways to setup the drawer module according to the App bar:
-
Using Drawer for Navigation
- This module only provides the layout itself. The Navigation logic must be done in your own code.
- I've put together an example app to demonstrate this here: NavigationDrawer Demo App
-
Customizing the drawerArrowToggle
- This is done in your ActionBar theme like this:
<style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="drawerArrowStyle">@style/DrawerArrowStyle</item> </style> <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> <item name="spinBars">true</item> <item name="color">@android:color/white</item> </style>
Android Docs: http://developer.android.com/reference/android/support/v7/appcompat/R.styleable.html#DrawerArrowToggle
-
TabGroup & Drawer
- Please refer to my answer here