Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7057] Ti.API: UI - prohibit child views being added to views other than UI.Window and UI.View

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 1.8.0.1
Fix Version/sn/a
ComponentsTiAPI
Labelsparity
ReporterPaul Dowsett
AssigneeEric Merriman
Created2012-01-10T08:17:36.000+0000
Updated2018-08-02T17:31:42.000+0000

Description

Problem

Currently, Android silently ignores a label added to an imageView, whereas iOS accepts and shows the label. Test this using the code below. From what I understand, only Ti.UI.View and Ti.UI.Window should accept child views. Hence, this ticket requests parity between the two platforms. My feeling is that an exception should be thrown on both platforms, to make the intended behavior clear to the user.

Test case

Ti.UI.setBackgroundColor('#000');

var win = Ti.UI.createWindow({
  backgroundColor:'#fff'
});

var imageview = Ti.UI.createImageView({
  image:'KS_nav_views.png'
});
var label = Ti.UI.createLabel({
  color:'#000',
  text:'I am a label',
  font:{fontSize:20,fontFamily:'Helvetica Neue'},
  textAlign:'center',
  width:'auto'
});
imageview.add(label);
win.add(imageview);

win.open();

References

See ticket TC-550, where this situation caused confusion.

Comments

  1. Sven Herzberg 2012-01-10

    Being the one who reported TC-550 20min earlier than this reporter, I have to tell you that I think removing this from other views is totally counter-productive. Feel free to take a look at TC-551 to see how this is actually a useful thing. Also, in the past, we've been displaying some things using a WebView. The fact that WebView on iOS permits child views, was REALLY helpful when porting the code away from WebView towards native controls. Only this feature has provided us with a way to extract one piece of information at a time and also provided us with a way to display both the old content and the new one (which is far more usable than using e.g. screenshots when making sure that the native layout is a pixel-perfect clone of the WebView-based one).
  2. Ivan Skugor 2012-01-11

    Paul, there are more View-like components that can contain other components - TableViewRow and ScrollView. ... IMO, "ImageView" is not the best name because of "View" part. When users read this part from documentation: "Views are always named with the suffix View" and this: "Views are containers that host visual elements such as controls or other views", they are easily confused. "ImageView" is not container and that should be pointed somewhere and it's "add" and "remove" methods should be removed from documentation. Also, "TableView" component has similar issue. There are "add" and "remove" methods that do nothing unfortunately (I'm not sure about "remove", didn't test it, but "add" method does not work even with "TableViewRow"). It would be great if they were used in combination with "TableViewSection" and "TableViewRow" components so we can add sections and rows through "add" method and remove them through "remove" method (and be warned if something else if being passed to that methods). That would make overall Titanium API design more clearer and intuitive. Also, it must be stated that "TableViewSection" and "TableViewRow" cannot exist for themselves (maybe small API documentation design change could be benifical, so that from design that's clear):
       OtherComponent1
       TableView
           TableViewSection
               TableViewRow
       OtherComponent2
       
    (Picker has similar problem) Sorry for mention of unrelated things, but I think it good to know where things can be better. :) Cheers.
  3. Arthur Evans 2012-01-11

    I think ImageView in this case is an anomaly, as Ivan suggests, because of the name. There's already a separate bug open to document the current restrictions for ImageView (TIMOB-6241). We need to document which UI objects support the 'add' method. (Or more accurately, we need to mark any objects that inherit from View but do *not* support add, because that's the way TDoc works.) Paul, can you either open a doc bug for this or repurpose this bug?

JSON Source