Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19482] Parity: Ti.UI.View.add should support array of views on Android as iOS

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-09-29T12:52:31.000+0000
Affected Version/sRelease 4.1.0
Fix Version/sRelease 6.1.0
ComponentsAndroid
Labelsparity
ReporterFokke Zandbergen
AssigneeHans Knöchel
Created2015-09-09T16:37:39.000+0000
Updated2016-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

Comments

  1. Fokke Zandbergen 2015-11-17

    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.
  2. Hans Knöchel 2016-06-21

    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();
       
  3. Hans Knöchel 2016-08-07

    PR + demo-code updated, ready for review.
  4. Gary Mathews 2016-09-29

    Reviewed and made some changes master: https://github.com/appcelerator/titanium_mobile/pull/8452
  5. Samir Mohammed 2016-11-22

    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*
       Appcelerator Command-Line Interface, version 6.0.0
       Android 7.0 (Google Nexus 6P)
       Operating System Name: Mac OS X El Capitan
       Operating System Version: 10.11.6
       Node.js Version: 4.6.0
       npm: 4.2.8
       Titanium CLI Version: 5.0.10
       Titanium SDK Version: 6.1.0.v20161121162514
       Xcode: 8.0
       Appcelerator Studio: 4.8.0.201611121409
       

JSON Source