Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15291] iOS7: backgroundColor="transparent" doesn't work on custom templates

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-09-26T17:29:17.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 20, 2013 Sprint 20 API, Release 3.1.4, Release 3.2.0
ComponentsiOS
Labels3.1.3, alloy, ios7, listview, qe-closed-3.1.4, qe-testadded
ReporterFederico Casali
AssigneeVishal Duggal
Created2013-09-18T13:07:21.000+0000
Updated2014-06-19T12:44:28.000+0000

Description

Problem description

'transparent' backgroundColor property for ListView Templates is showing a 'white' backgroundColor in the ListItems instead of a transparent one. Setting a color it works as expected.

Sample code and steps to reproduce

Following sample code is basically the one available here http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.ListItem , adding
properties: {
  		backgroundColor: 'transparent', // this will set the backgroundColor to white.
  		// backgroundColor: 'green'   // set the background to a color works
  	},
to the 'plainTemplate' template.
var win = Ti.UI.createWindow({
	backgroundColor: 'yellow',
	top:20
});

var plainTemplate = {
    childTemplates: [
        {                            // Image justified left
            type: 'Ti.UI.ImageView', // Use an image view for the image
            bindId: 'pic',           // Maps to a custom pic property of the item data
            properties: {            // Sets the image view properties
                width: '50dp', height: '50dp', left: 0
            }
        },
        {                            // Title
            type: 'Ti.UI.Label',     // Use a label for the title
            bindId: 'title',         // Maps to a custom title property of the item data
            properties: {            // Sets the label properties
                color: 'black',
                font: { fontFamily:'Arial', fontSize: '20dp', fontWeight:'bold' },
                left: '60dp', top: 0,
            },
        },
        {                            // Subtitle
            type: 'Ti.UI.Label',     // Use a label for the subtitle
            bindId: 'subtitle',      // Maps to a custom subtitle property of the item data
            properties: {            // Sets the label properties
                color: 'gray',
                font: { fontFamily:'Arial', fontSize: '14dp' },
                left: '60dp', top: '25dp',
            }
        }
    ],
  	properties: {
  		// These are the same as the list data item properties
  		// The list data item properties supersedes these if both are defined
  		backgroundColor: 'transparent', // this will set the backgroundColor to white.
  		// backgroundColor: 'green'   // set the background to a color works
  	},
    // Binds a callback to the click event, which catches events bubbled by the view subcomponents.
    events: {click: toggleCheck }
};

// The following API calls are equivalent to using jQuery.extend(true, {}, oldObject)
// Copy the plainTemplate
var redTemplate = JSON.parse(JSON.stringify(plainTemplate));
// Change the text color to red
redTemplate.childTemplates[1].properties.color = 'red';
redTemplate.childTemplates[2].properties.color = 'red';
// Rebind the click event callback
redTemplate.events.click = toggleCheck;

var listView = Ti.UI.createListView({
    // Maps plainTemplate to 'uncheck' and redTemplate to 'check' 
    templates: { 'uncheck': plainTemplate, 'check': redTemplate },
    // Use 'uncheck', that is, the plainTemplate created earlier for all items
    // Can be overridden by the item's template property
    defaultItemTemplate: 'uncheck',
    backgroundColor:'purple'
});

var tasks = [
    {id: 'trash', name: 'Take Out the Trash', person: 'Yakko', icon: 'trash.png'},
    {id: 'dishes', name: 'Do the Dishes', person: 'Wakko', icon: 'dishes.png'},
    {id: 'doggie', name: 'Walk the Dog', person: 'Dot', icon: 'doggie.png'}
];

var data = [];
for (var i = 0; i < tasks.length; i++) {
    data.push({
        // Maps to the title component in the template
        // Sets the text property of the Label component
        title : { text: tasks[i].name },
        // Maps to the subtitle component in the template
        // Sets the text property of the Label component
        subtitle : { text : tasks[i].person },
        // Maps to the pic component in the template
        // Sets the image property of the ImageView component
        pic : { image : tasks[i].icon },
        // Sets the regular list data properties
        properties : {
            itemId: tasks[i].id,
            accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_NONE,
            // backgroundColor:'transparent' //this works
        }
    });
}

var section = Ti.UI.createListSection();
section.setItems(data);
listView.sections = [section];

// Modified version of the itemclick event listener
// Changes the item template rather than the list item's color property
function toggleCheck (e) {
    var item = section.getItemAt(e.itemIndex);
    if (item.properties.accessoryType == Ti.UI.LIST_ACCESSORY_TYPE_NONE) {
        item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK;
        item.template = 'check';
    }
    else {
        item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_NONE;
        item.template = 'uncheck';
    }
    section.updateItemAt(e.itemIndex, item);
} 

win.add(listView);
win.open();	

Further sample

This is the Alloy sample originally provided from community. index.xml
<Alloy>
    <Window class="container">
        <ListView id="lv">
            <ListSection id="ls">
                    <ListItem title="row 1" color="white" backgroundColor="transparent"/>
                    <ListItem title="row 2" color="white" backgroundColor="blue"/>
                </ListSection>
        </ListView>
        <ListView id="lv2" defaultItemTemplate="template1">
            <Templates>
                <ItemTemplate name="template1" height="100" backgroundColor="transparent">
                    <Label bindId="label" id="label1"/>
                </ItemTemplate>
            </Templates>
            <ListSection>
                <ListItem label:text="this is some text"/>
            </ListSection>            
        </ListView>       
    </Window>
</Alloy>
index.tss
".container": {
    backgroundColor:"black"
}
"ListView":{
    backgroundColor: 'transparent'
}
"#lv": {
    top: '10dp',
    height: '100dp'
}
"#lv2": {
    top: '110dp',
    height: '300dp'
}

Comments

  1. Federico Casali 2013-09-19

    I've been able to reproduce the issue also using a common titanium code. Moving to Timob and attaching sample code.
  2. Mark Mokryn 2013-09-19

    More clarity: I am successfully setting ListItem backgrounds to "transparent" dynamically on iOS7 on custom items, e.g.
       item.properties.backgroundColor = 'transparent';
       
    but doing this in the template definition doesn't work. So there is a workaround....
  3. Federico Casali 2013-09-19

    Mark: yes, in particular with Alloy, in the app.tss you can use
       "ListItem":{
       	backgroundColor: 'transparent'
       }
       
    and the rows should be transparent as expected. The problem, as you wrote, is when using the 'transparent' value in the property inside the template definition.
  4. Mark Mokryn 2013-09-20

    Federico - I just tried setting the style in app.tss, and it doesn't work (on iOS7 of course). Only works if I do it in the Javascript as above.
  5. Vishal Duggal 2013-09-20

    Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/4721
  6. Vishal Duggal 2013-09-20

    Backport to 3_1_X https://github.com/appcelerator/titanium_mobile/pull/4722
  7. Vishal Duggal 2013-09-21

    Needs more fixes in master and for iOS6
  8. Vishal Duggal 2013-09-21

    New PR against master https://github.com/appcelerator/titanium_mobile/pull/4729
  9. Olga Romero 2013-09-27

    Tested the above Alloy sample originally provided from community and verified transparent color works with: Appcelerator Studio, build: 3.1.3.201309132456 Titanium SDK, build: 3.1.4.v20130926144546 Alloy 1.2.2 CLI 3.1.2 Device: iPhone 5s iOS7 iPhone 5c iOS7.0.2(11A501)
  10. Jan Helleman 2013-10-09

    So far, I have seen it going white or not white 50% of the time. How is that possible? Sometimes I see it flickering for a very small moment. 3.1.4.v20131008163742

JSON Source