{ "id": "172039", "key": "TIMOB-26283", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "11", "description": "Is not a bug in our product", "name": "Not Our Bug" }, "resolutiondate": "2018-10-29T22:13:02.000+0000", "created": "2018-08-10T10:28:08.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [], "versions": [], "issuelinks": [], "assignee": { "name": "ybanev", "key": "ybanev", "displayName": "Yordan Banev", "active": true, "timeZone": "Europe/Athens" }, "updated": "2018-10-29T22:13:05.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [], "description": "On Android inserting children in a view with defined layout (I have tested only with {{vertical}} so far) ends with a different result based on what order the method is called even if the {{position}} property matches. In the attached sample the views on the left are added in descending order based on the position index and the views in the right container are added in ascending order based on the same. IMO it would make sense for the end result to be the same no matter in what order the method is called if the positions match. \r\n\r\nAfter clicking the button to replace the view with index in the left container you can notice that it is not only changing color - from gray to red, but also changing its position. Having in mind that the {{left}} property is 15 units multiplied by the position index it should remain in the same position. After the replacement the new view takes position which is the same as the view with index 3 in the right container. Which is the expected position.\r\n\r\n-I haven't tested that on iOS and I don't know what is the behavior in such case.-\r\n[~topener] ran the sample on iOS and we get the exact same behavior. Is this the intended behavior?", "attachment": [ { "id": "65425", "filename": "app.js", "author": { "name": "ybanev", "key": "ybanev", "displayName": "Yordan Banev", "active": true, "timeZone": "Europe/Athens" }, "created": "2018-08-10T10:28:04.000+0000", "size": 979, "mimeType": "application/x-javascript" }, { "id": "65426", "filename": "insertAt.png", "author": { "name": "ybanev", "key": "ybanev", "displayName": "Yordan Banev", "active": true, "timeZone": "Europe/Athens" }, "created": "2018-08-10T10:46:35.000+0000", "size": 78862, "mimeType": "image/png" }, { "id": "65484", "filename": "iOS-Screenshot-WithNumbers.png", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-08-28T03:25:59.000+0000", "size": 23650, "mimeType": "image/png" }, { "id": "65427", "filename": "replaced.png", "author": { "name": "ybanev", "key": "ybanev", "displayName": "Yordan Banev", "active": true, "timeZone": "Europe/Athens" }, "created": "2018-08-10T10:46:35.000+0000", "size": 78844, "mimeType": "image/png" }, { "id": "65429", "filename": "Simulator Screen Shot - iPhone X - 2018-08-10 at 12.40.22.png", "author": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-08-10T15:16:04.000+0000", "size": 65395, "mimeType": "image/png" }, { "id": "65428", "filename": "Simulator Screen Shot - iPhone X - 2018-08-10 at 12.40.52.png", "author": { "name": "topener", "key": "topener", "displayName": "Rene Pot", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-08-10T15:15:58.000+0000", "size": 65397, "mimeType": "image/png" } ], "flagged": false, "summary": "insertAt not working as expected", "creator": { "name": "ybanev", "key": "ybanev", "displayName": "Yordan Banev", "active": true, "timeZone": "Europe/Athens" }, "subtasks": [], "reporter": { "name": "ybanev", "key": "ybanev", "displayName": "Yordan Banev", "active": true, "timeZone": "Europe/Athens" }, "environment": null, "closedSprints": [ { "id": 1088, "state": "closed", "name": "2018 Sprint 22", "startDate": "2018-10-21T23:20:52.653Z", "endDate": "2018-11-04T23:20:00.000Z", "completeDate": "2018-11-04T23:29:59.423Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "441111", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "[~ybanev], I haven't look at this yet, but I do remember fixing {{insertAt()}} with {{ScrollViews}} last year. Please see the \"ScrollViewAddRemoveTest.js\" file attached to ticket [TIMOB-25415]. It allows the end-user to insert/remove rows in a vertical layout dynamically by tapping on them.", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-08-27T20:00:48.000+0000", "updated": "2018-08-27T20:00:48.000+0000" }, { "id": "441125", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I just test this out. I'm not convinced this is a bug in Titanium. And the behavior between Android and iOS is the same too.\r\n\r\nLet's have a look at the following...\r\n{code:javascript}\r\nfor (i=6; i >= 0; i--) {\r\n\tviewLeft.insertAt({\r\n\t\tview: Ti.UI.createView({\r\n\t\t\tleft: i * 15,\r\n\t\t\twidth: 40,\r\n\t\t\theight: 40,\r\n\t\t\tbackgroundColor: 'gray',\r\n\t\t}),\r\n\t\tposition: i,\r\n\t});\r\n}\r\n{code}\r\n\r\nNote that {{viewLeft}} is empty before entering the above for-loop. Our {{insertAt()}} method will not allow a position index to be set higher than the number of children. So, a position index of 6 while the child count is 0 causes the actual insert position to be 0. When you attempt to insert the 2nd view at position index 5, it ends being inserted *after* the 1st inserted view. And the reason why the left child views appear *staggered* is because you're inserting backwards and the last half of the inserted views will have valid position indexes.\r\n\r\n* View6 -> insert index 6 -> [View6]\r\n* View5 -> insert index 5 -> [View6, View5]\r\n* View4 -> insert index 4 -> [View6, View5, View4]\r\n* View3 -> insert index 3 -> [View6, View5, View4, View3]\r\n* View2 -> insert index 2 -> [View6, View5, View2, View4, View3]\r\n* View1 -> insert index 1 -> [View6, View1, View5, View2, View4, View3]\r\n* View0 -> insert index 0 -> [View0, View6, View1, View5, View2, View4, View3]\r\n\r\nSo, when you do a {{replaceAt()}} at position index 3, you're really replacing View5 whose \"left\" property was original set to {{75}}, not {{45}}.\r\n\r\nIf you change your {{createView()}} to the a label like the below, then you can see what I mean.\r\n{code:javascript}\r\nTi.UI.createLabel({\r\n\ttext: i,\r\n\tleft: i * 15,\r\n\twidth: 40,\r\n\theight: 40,\r\n\tbackgroundColor: 'gray',\r\n})\r\n{code}\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-08-28T03:23:16.000+0000", "updated": "2018-08-28T03:23:16.000+0000" }, { "id": "441126", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Below is a screenshot with the views numbered.\r\n !iOS-Screenshot-WithNumbers.png|thumbnail! ", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-08-28T03:26:56.000+0000", "updated": "2018-08-28T03:26:56.000+0000" }, { "id": "441233", "author": { "name": "ybanev", "key": "ybanev", "displayName": "Yordan Banev", "active": true, "timeZone": "Europe/Athens" }, "body": "I tried it on native Android as well. It does not work as I thought there too. It throws an {{Out of bounds}} exception. This behavior is fine. Leaving it as is.", "updateAuthor": { "name": "ybanev", "key": "ybanev", "displayName": "Yordan Banev", "active": true, "timeZone": "Europe/Athens" }, "created": "2018-08-30T12:06:25.000+0000", "updated": "2018-08-30T12:06:40.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }