Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3047] Android: TextField crashes when 'dp' units used to set dimension properties

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionHold
Resolution Date2011-04-15T03:35:28.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, defect, enterprise, release-1.7.0, reported-1.6.0, rplist
ReporterBill Dawson
AssigneeBill Dawson
Created2011-04-15T03:35:26.000+0000
Updated2017-03-10T19:23:39.000+0000

Description

(From Andreas Sandberg) Bill, here is a similar use case that also throws an exception and crashes the application:

var win = Ti.UI.createWindow({
backgroundColor:'red',
});
var a = Titanium.UI.createTextField({
        height:'51dp',
        top:'5dp',
        paddingLeft:'10dp',
        left:'10dp',
        right:'54dp'
    });
var fieldContainer = Ti.UI.createView({
        height:a.height,
        width:320,
        layout:'horizontal'
});
fieldContainer.add(a);
win.add(fieldContainer);
win.open();

Stack Trace:

[TRACE] E/KrollReflectionProperty( 559): (kroll$1) [702,1358] Exception getting/setting property: height
[TRACE] E/KrollReflectionProperty( 559): java.lang.NumberFormatException: unable to parse '51dp' as integer 
[TRACE] E/KrollReflectionProperty( 559): at java.lang.Integer.parse(Integer.java:433) 
[TRACE] E/KrollReflectionProperty( 559): at java.lang.Integer.parseInt(Integer.java:422) 
[TRACE] E/KrollReflectionProperty( 559): at java.lang.Integer.parseInt(Integer.java:382) 
[TRACE] E/KrollReflectionProperty( 559): at org.appcelerator.titanium.util.TiConvert.toInt(TiConvert.java:251) 
[TRACE] E/KrollReflectionProperty( 559): at org.appcelerator.titanium.proxy.TiViewProxy.getHeight(TiViewProxy.java:303) 
[TRACE] E/KrollReflectionProperty( 559): at org.appcelerator.titanium.proxy.TiViewProxyBindingGen$2.dynamicGet(TiViewProxyBindingGen.java:276) 
[TRACE] E/KrollReflectionProperty( 559): at org.appcelerator.kroll.KrollDynamicProperty.safeInvoke(KrollDynamicProperty.java:39) 
[TRACE] E/KrollReflectionProperty( 559): at org.appcelerator.kroll.KrollDynamicProperty.get(KrollDynamicProperty.java:88) 
[TRACE] E/KrollReflectionProperty( 559): at org.appcelerator.kroll.KrollProxy.getDynamicProperty(KrollProxy.java:241) 
[TRACE] E/KrollReflectionProperty( 559): at org.appcelerator.kroll.KrollProxy.get(KrollProxy.java:183) 
[TRACE] E/KrollReflectionProperty( 559): at org.appcelerator.kroll.KrollObject.get(KrollObject.java:33) 
[TRACE] E/KrollReflectionProperty( 559): at org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:1963) 
[TRACE] E/KrollReflectionProperty( 559): at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1503) 
[TRACE] E/KrollReflectionProperty( 559): at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1489)

Comments

  1. Bill Dawson 2011-04-15

    Simplified failcase app.js:

       var v = Ti.UI.createView({height: '50dp'});
       var h = v.height;
       
  2. Don Thorp 2011-04-15

    Bill, I spoke with the customer and we're pushing this to 1.7.0. As you know, it requires changing method signatures and dealing with the static vs dynamic problem we found in our UI review in January.

  3. Bill Dawson 2011-04-15

    Also slated for 1.7.0 is a general re-working of the properties that set and expose layout characteristics. For example, currently it is impossible to read that you set a width to "auto". (It throws the exception that is the subject of this ticket.) One of the goals of the overhaul is that differentiate between what you set as a layout dimension ("11", "11dp", "auto", etc.) and the actual pixel dimension that resulted once the view was laid out. At that point, this ticket will not be valid anymore.

    To avoid duplicate effort, we're therefore putting this ticket in a hold state, since both this ticket and the general re-working (which will solve this ticket) are slated for 1.7.0.

    As a temporary workaround to the exception that you're getting as described in this ticket, you can read the .size property of views. For example, if you set view.width = "20dp", you can then read the resulting width (expressed in pixels) with view.size.width, but only after the view has been laid out (i.e., after the window has been open and all child views have been drawn.)

  4. Lee Morris 2017-03-10

    Closing ticket.

JSON Source