Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14795] TiAPI: Add "parent" property for all Ti.UI.View subclasses

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-11-15T05:03:31.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.0.0
ComponentsTiAPI
Labelsparent, view
ReporterFokke Zandbergen
AssigneeHans Knöchel
Created2013-07-21T18:42:40.000+0000
Updated2017-11-15T05:03:39.000+0000

Description

Only via Q&A I discovered I can use .parent and .getParent() to get the parent of any view. This is extremely useful in many cases. Is there are reason for not documenting these? Is it not stable or going to be deprecated soon for another reason? If not, please document it :)

Comments

  1. Benjamin Hatfield 2013-08-08

    Talked with development. This property is not meant to be exposed as a public API. Tested on iOS and Android and the behavior is different.
  2. Fokke Zandbergen 2013-08-09

    So, why not make it behave the same? Being able to get the parent of an element can be quite useful? Should I open another ticket to request the feature to be made solid and public?
  3. Benjamin Hatfield 2013-08-09

    Hi [~fokke], I moved the ticket over to TIMOB as a new feature request. Could you please provide an explanation of why you want this feature and the expected behavior for the development team? Thanks.
  4. Fokke Zandbergen 2013-08-14

    The expected behavior is for view.parent and view.getParent() to return the parent view.
       var viewOne = Ti.UI.createView();
       var viewTwo = Ti.UI.createView();
       
       viewOne.add(viewTwo);
       
       assert(viewOne.parent === viewTwo);
       
    An example use case is removing a view in an Alloy controller. Without .parent I need to assign an id to the parent view. With, I can just do $.myView.parent.remove($.myView); Which makes me think another method that might make sense would be: removeFromParent(), basically doing the above?
  5. Chris Barber 2016-08-30

    We should add this. It makes tons of sense. Mobile Web had this.
  6. Creative 2017-03-09

    +1 this is basic functionality
  7. Simon Buckingham 2017-03-29

    +1 This should be a fundamental option. Like a lot of other things in Ti, basic UI often seems neglected. As Fokke comments it can be useful, because otherwise one has to always pass references to the parent view into the controller in question.
  8. Hans Knöchel 2017-07-26

    We will do it. And if there are parity-gaps, we should discuss them in this ticket. I tested it with iOS and it works just as expected, going directly from the managed view-proxy. I am wondering how Android could behave different here (maybe [~gmathews] has some input here). Also, does Windows support this, [~kiguchi]? Making this for 7.0.0 should be doable, let me know your thoughts! :-) *EDIT*: Tested with Android and it works just fine as well. Let's do this! *EDIT 2*: [This branch](https://github.com/appcelerator/titanium_mobile/compare/master...hansemannn:TIMOB-14795?expand=1) is waiting to be PR'd once we have a decision.
  9. Chris Barber 2017-07-26

    Yes!
  10. Kota Iguchi 2017-07-26

    [~hknoechel] View.parent property and get/setParent functions are already supported on Windows. We also have unit tests: [ti.ui.view.test.js#L452](https://github.com/appcelerator/titanium_mobile_windows/blob/master/Examples/NMocha/src/Assets/ti.ui.view.test.js#L452)
  11. Hans Knöchel 2017-07-26

    Great! Than we should add more unit-tests to the PR and merge it in I guess.
  12. Hans Knöchel 2017-10-25

    Assigning to Gary to clarify how Android handles this. As iOS and Windows do handle it already, we may close this if Android passes as well.
  13. Gary Mathews 2017-10-27

    Android also has this implemented, here's a quick test case. The one above is incorrect:
        var a = Ti.UI.createView(),
            b = Ti.UI.createView();
        
        a.add(b);
        
        alert(b.parent === a); // true
        
    We only need to add parent to our docs
  14. Abir Mukherjee 2017-11-15

    I verified the test case on Android; per comments, I'll close the ticket.

JSON Source