Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8678] iOS: Webcolor colorForHex returns incorrect values for some strings

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-04-19T15:38:55.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sRelease 2.1.0, Sprint 2012-08
ComponentsiOS
Labelsapi, module_window, qe-testadded
ReporterArthur Evans
AssigneeBlain Hamon
Created2012-04-11T10:23:36.000+0000
Updated2012-07-13T14:53:18.000+0000

Description

Problem

The logic in colorForHex is incorrect for some color values, specifically color values starting with '#'. This is not notable for colors specified by users, because the hash mark is stripped out before the value is passed to colorForHex. However, the values listed internally, 'aqua', 'fuchsia', 'lime' and 'maroon' are improperly returned as transparent. colorForHex should simply strip the '#' character before interpreting the color values, which would simplify the logic.

Test case

// According to the following test case:
// Android does not currently support: brown. The color yellow is used when a name is not recognised.
// iOS does not currently support: aqua, fuchsia, lime and maroon.  The color black is used when a name is not recognised.

// stripped for tableview background color still to be tested

var webcolor = [
  'black', 'gray', 'darkgray', 'lightgray', 'white', 'red', 'green', 'blue', 'cyan', 'yellow',
  'magenta', 'orange', 'purple', 'brown', 'transparent',
  'aqua', 'fuchsia', 'lime', 'maroon', 'pink', 'navy', 'silver', 'olive', 'teal'];

var webcolorPointer = 0;

var win = Ti.UI.createWindow({
  backgroundColor: webcolor[webcolorPointer],
  exitOnClose: true,
  fullscreen: false,
  layout: 'vertical',
  title: 'Webcolor Demo'
});

var label = Ti.UI.createLabel({
  backgroundColor: 'white',
  text: webcolor[webcolorPointer]
});
webcolorPointer++;

win.add(label);

// click window to iterate through color array
win.addEventListener('click', function(e){
  e.source.backgroundColor = webcolor[webcolorPointer];
  label.text = webcolor[webcolorPointer];
  webcolorPointer++;
  if(webcolorPointer === webcolor.length){
    webcolorPointer = 0;
  }
});

win.open();

Comments

  1. Blain Hamon 2012-04-18

    Pull request pending.
  2. Max Stepanov 2012-04-19

    PR merged https://github.com/appcelerator/titanium_mobile/pull/2033
  3. Eric Merriman 2012-06-18

    Verified fixed with SDK 2.1.0.v20120618102300 on iPod 4th Gen

JSON Source