[ALOY-359] buttongrid Widget and orientation change
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Low |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2012-12-07T22:30:33.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 0.3.4, 2012 Sprint 25 |
Components | Widgets |
Labels | n/a |
Reporter | Rick Blalock |
Assignee | Unknown |
Created | 2012-11-02T14:58:31.000+0000 |
Updated | 2018-03-07T22:25:35.000+0000 |
Description
We're using the built in widget "ButtonGrid" (which is documented very well btw). Everything works fine but I wanted to point out a potential issue with using the orientationchange global event: https://github.com/appcelerator/alloy/blob/master/widgets/com.appcelerator.buttongrid/controllers/widget.js#L167
While this is innocent if the developer only plans on having one instance of the buttongrid that's always in memory, imagine if there are multiple instances that are meant to go out of scope. The user would have created a memory leak if he hadn't looked at the source code, realized this was there, and manually removed the event.
Three possible options:
1. Remove it completely and let the user assign an orientation event to the Widget.relayout() method on his own.
2. Have some type of remove method that will remove it for the user
3. Document that the user must remove it manually.
I prefer #1.
I think I'm going to do a little bit of a mix of #1 and #2. I'm going to add a configuration option to the init() called *autoLayout*, which will be *true* by default to maintain compatibility with any existing uses of this widget. If *autoLayout* is set to true, then the developer will be required to free the gesture handler manually with a new destroy() function. If *autoLayout* is set to false, the gesture handler will not be created automatically, but the developer will need to handle orientation changes themselves if they so choose.
Latest inline docs for the buttongrid widget can be found here: https://github.com/appcelerator/alloy/blob/master/widgets/com.appcelerator.buttongrid/controllers/widget.js They detail the use of the new *autoLayout* property and *destroy()* function.