[TIMOB-19482] Parity: Ti.UI.View.add should support array of views on Android as iOS
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | High |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2016-09-29T12:52:31.000+0000 |
| Affected Version/s | Release 4.1.0 |
| Fix Version/s | Release 6.1.0 |
| Components | Android |
| Labels | parity |
| Reporter | Fokke Zandbergen |
| Assignee | Hans Knöchel |
| Created | 2015-09-09T16:37:39.000+0000 |
| Updated | 2016-11-22T18:12:30.000+0000 |
Description
On iOS
Ti.UI.View.add() accepts an array of views:
https://github.com/appcelerator/titanium_mobile/blob/0357b4796abf0032485018fac42614a94f826c9b/iphone/Classes/TiViewProxy.m#L148
On Android it does not:
https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/view/TiUIView.java#L159
This is a very useful feature and looking at the iOS code simple to implement for Android and Windows as well.
Related question on Q&A:
https://community.appcelerator.com/topic/3075/unable-to-add-array-of-views-to-parent-view-on-android
Can we schedule this one for the next release so that - with TIMOB-19394 and TIDOC-2282 already resolved - we can demonstrate how to use this cross-platform in a sample app for the next release.
PR: https://github.com/appcelerator/titanium_mobile/pull/8077 Demo:
var win = Ti.UI.createWindow({ backgroundColor: "#fff" }); var btn1 = Ti.UI.createButton({ title: "Add views together", top: 0 }); var view1 = Ti.UI.createView({ backgroundColor: "red", top: 50, height: 100 }); var view2 = Ti.UI.createView({ backgroundColor: "green", bottom: 50, height: 100 }); btn1.addEventListener("click", function() { win.remove(view1); win.remove(view2); // Just to see that they are actually removed before setTimeout(function() { win.add([view1, view2]); }, 250); }); var btn2 = Ti.UI.createButton({ title: "Add views after each other", bottom: 0 }); btn2.addEventListener("click", function() { win.remove(view1); win.remove(view2); // Just to see that they are actually removed before setTimeout(function() { win.add(view1); win.add(view2); }, 250); }); win.add(btn1); win.add(btn2); win.open();PR + demo-code updated, ready for review.
Reviewed and made some changes master: https://github.com/appcelerator/titanium_mobile/pull/8452
Verified fixed by using the code above provided by [~hansknoechel] was able to press the "Add Views Together button" without crashing. Also verified by the code provided by [~gmathews] in https://github.com/appcelerator/titanium_mobile/pull/8452 was able to press "Add View Array" without the app crashing. (Tested on SDK version 6.1.0.v20161121162514). *Environment*