Enterprise apps often contain a number of features. Providing a compelling way to display these features and submenus can be challenging. One unique navigation option is to implement a Screen Break Menu, similar to how iOS folders work. This navigation technique allows you to present additional information only when requested by the user.
In this recipe, we will demonstrate how you can implement a cross-platform version of the Screen Break animation and link this effect to a menu view.
This recipe walks through using the screen break interaction pattern to create additional space for an Add Notes field. You can easily tweak this recipe for more complex menu needs, such as implementing advanced options or an interactive help menu.
When the menu is closed, all space is usable for other controls. The following image shows the Screen Break Menu in its closed state.
Once you've added the breakmenu.js
file to your project, you need to use require
to import the module into your code, as the following snippet demonstrates:
//Create our application namespace var my = { breakingMenu : require('breakmenu') };
To demonstrate the Screen Break Menu, we create a basic window with a single button. When this button is clicked, the Screen Break Menu is activated.
var win = Ti.UI.createWindow({ backgroundColor:'#fff' }); //Create button var button = Ti.UI.createButton({ title:'Add Notes', left:20, right:20, height:50, top:150 }); win.add(button);
Next in our example, we add a series of listeners. The following code block demonstrates how to add a listener, to be fired when the Screen Break Menu starts, to show the menu.
my.breakingMenu.addEventListener('breaking',function(e){ Ti.API.info("Screen is breaking"); });
broken
event is fired when the menu is fully displayed.my.breakingMenu.addEventListener('broken',function(e){ Ti.API.info("Screen is broken, menu is visible"); });
closing
event is fired when the menu starts to close. This will take a second to fully close.my.breakingMenu.addEventListener('closing',function(e){ Ti.API.info('Menu starting to close'), });
closed
event is fired.my.breakingMenu.addEventListener('closed',function(e){ Ti.API.info('Menu is closed'), });
Displaying a Ti.UI.View
is at the core of the Screen Break Menu. In this example, we create a notes menu object containing Ti.UI.View
and Ti.UI.TextArea
controls. These controls are used to present the user with an area for entering notes, when the Screen Break Menu is visible.
var notesMenu = { value : '', //Our value for the notes screen view : function(){ //Create a view container var vwMenu = Ti.UI.createView({ backgroundColor:'yellow',top:150, height:200, width: Ti.UI.FILL }); //Create a textArea for the user to type var txtField = Ti.UI.createTextArea({ width: Ti.UI.FILL,height:Ti.UI.FILL, hintText:"Add a note", value : notesMenu.value, backgroundColor:'transparent',font:{fontSize:14,fontWeight:'bold'} }); vwMenu.add(txtField); //When text is added, update the menu value txtField.addEventListener('change',function(e){ notesMenu.value = txtField.value; }); //Return the view so we can later bind for display return vwMenu; } };
When the sample's button is pressed, the breakScreen
function is called to show the Screen Break Menu.
The breakScreen
function takes the following parameters:
Ti.UI.Window
that you wish to split in order to reveal the menu.Ti.UI.View
that you wish to use as your menu. Please note this can only be a Ti.UI.View
object type.settings
object. This object contains the following properties:breakStartPoint
: The position measured from the top of the screen indicating where the break should start.bottomViewHeight
: This property decides the height of the bottom-half section. This value determines the size of the bottom half of the screen that is animated down the screen.slideFinishPoint
: The position from the top of the screen indicating where the bottom view should slide to.The following code block implements all the three properties:
button.addEventListener('click',function(e){ //Options object var settings = {}; //Point of the screen where the screen will separate settings.breakStartPoint = 150; //Size of the bottom half of screen, ie the sliding part settings.bottomViewHeight = 218, //The bottom point you want the screen to slide to. //Measured from top of screen settings.slideFinishPoint = 340; //Call function to split the screen & show our menu my.breakingMenu.breakScreen(win,notesMenu.view(),settings); });
18.117.233.26