Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1667] Changing label view's font.fontSize property after view is rendered has no effect.

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2011-04-15T02:58:54.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelseventlistener, font, fontsize, label
Reporterk00k
AssigneeReggie Seagraves
Created2011-04-15T02:58:52.000+0000
Updated2017-03-09T22:58:36.000+0000

Description

Environment: Titanium Developer 1.40 and iPhone Simulator (iphone and iphone4). Also tested on iPhone4 device with same results.

Issue: Changing the fontSize property of a label after label is rendered has no effect. The following code does not work.

Example code: (notice 2 methods for defining new font size - neither work)

var w = Ti.UI.createWindow({backgroundColor:'#fff'});
var b = Ti.UI.createButton({
   title:'Click Me',
   top:10,
   height:40,
   width:200
});
var lab = Ti.UI.createLabel({
   text: 'test',
   top: 150,
   height: 140,
   width: 300,
   font:{fontSize:20},
   color: '#c00',
   backgroundColor: '#ccc'
});

w.add(b);
w.add(lab);

b.addEventListener('click', function() {
   lab.font = '{fontSize:100}'; 
  // lab.font.fontSize = 100; // this also doesn't work
});

w.open();

Comments

  1. Brion Vibber 2011-04-15

    This should work as a workaround (it's what I've been doing, works for me on both Android and iPhone):

    lab.font = {fontSize:100};

    I think the reason the initial attempt to just assign lab.font.fontSize directly doesn't work is that the 'font' property is implemented with getters/setters that just take and return plain JSON-style objects.

    So 'lab.font' returns a plain old object which has no inherent connection back to 'lab'; changing its contents only changes the new object, and doesn't ever reach the original.

    This could probably be made to work as expected if the font property's getter returned a proxy object, which itself would have getters/setters to handle sending through the subproperties.

  2. Brion Vibber 2011-04-15

    Since we encountered this same issue while working on StatusNet Mobile, I'm assigning this to our support contact. Nolan, can you make sure it's reassigned to the appropriate people for iPhone and Android implementations? We've used the above workaround, but clearly other people are encountering the same problem... if it can't be fixed easily, could the workaround be added to API documentation perhaps?

    Thanks!

  3. Nolan Wright 2011-04-15

    it's working as designed. Our properties use getters/setters, so there is no support for property nesting. The font property takes an object as a value, so this:

    label.font = {fontSize:20};

    is the proper way to change the value.

    thanks.

  4. Brion Vibber 2011-04-15

    Nolan, any comment on the feasibility of my suggested implementation for property nesting?

    Or is there a deliberate choice to not implement property nesting? If so, this should be very clearly documented; most JavaScript developers will probably be coming from web development and will be used to nested properties like 'div.style.fontSize = 100'.

  5. k00k 2011-04-15

    Thanks for the clarification Nolan. I see I was mistakenly wrapping the object in ''. I agree on needing better documentation. I also realize you guys are busy. Time to get a few interns :)

  6. Stephen Tramer 2011-04-15

    Nolan should have invalidated.

  7. Lee Morris 2017-03-09

    Closing ticket as invalid.

JSON Source