Floating panels (like the one below) are a great way to present helpful content, such as a form or help text, within the context of a parent user interface screen. Unfortunately, the Sencha Touch documentation fails once again at clearly explaining a useful framework feature. In the Ext.Panel documentation, they show some crazy way to use the Ext.Panel.showBy method, which is extremely unhelpful and dosen’t show how to use it in an MVC context. Further, the Overlays sample application is obfuscated and breaks all MVC convention and most general Sencha Touch conventions. Here’s a brief tutorial on how to actually use this in an MVC application.
Floating Panels are simply Ext.Panel controls that are hidden from the main Viewport. These panels are displayed much like an Ext.Msg.alert call, with the ability to customize them at a finer level of detail.
The panel itself is fairly easy to create:
Ext.define('App.view.FloatingPanelView', {
extend: 'Ext.Panel',
alias: 'widget.floatingPanel',
config: {
id: 'floatingPanel',
html: '<p>Here's some content.</p>',
styleHtmlContent: true,
hidden: true,
modal:true,
hideOnMaskTap:true,
height: '200px',
width: '200px',
scrollable: 'vertical'
}
});
The modal and hideOnMaskTap configs provides the user with a visual indication that they can tap anywhere on the screen away from the panel to close the panel. The height and width configs take any CSS compatible pixel or percentage value. You can use maxHeight and maxWidth to loosely define hiehgt and width if you are not using the optional scrollable config.
A tricky piece is the scrollable config. It defaults to false and requires strings such as ‘vertical’ or ‘horizontal’ do indicate the direction of scrolling allowed. If you not explicitly define a height and width config, however, your panel will be displayed as a jumbled mess. This behavior is not officially documented at all, however this Sencha thread discusses the issue.
To show the panel on the tap of a button, you use it in your controller (or listener) like so:
Ext.define('App.controller.PanelDemoController', {
extend: 'Ext.app.Controller',
config: {
control: {
myButton: {
tap: 'myButton_tap'
}
}
refs: {
myButton: '#myButton',
floatingPanel: '#floatingPanel'
}
}
myButton_tap: function(button) {
this.getFloatingPanel().showBy(button, 'br-tc?');
}
});
The Ext.Panel.showBy method automatically builds a frame around your panel and an arrow pointing at the button passed in the first argument. The second argument is a cryptic string:
- The first two characters describe the arrow’s placement relative to the panel, in this example “bottom right”
- The two characters after the dash describe the arrow’s placement relative to the item tapped, in this example “top center”
- The final ? is optonal and forces the panel to be visible within the bounds of the Viewport. Omit this at your own risk!
The decoder ring for these strings are located in the Ext.Panel.showBy documentation.
I know this dosen’t describe everything floating panel related, such as using the Exp.Panel.show method or quirks using forms inside of a floating panel. Perhaps I will get to this down the road!


