Project: titanium
Issue TIMOB-5303: Android: UI view size property values incorrect
h2. Problem The view's size property values are intended to reflect the rendered dimensions. However, if these properties are queried too soon after rendering has completed, the old values will be output. The advice of querying property values within a window open event listener does not work. h2. Test case {code:lang=javascript|title=app.js} var win = Ti.UI.createWindow({ // fullscreen: false, // once fixed, please check with this line uncommented backgroundColor:'red' }); var view = Ti.UI.createView({ backgroundColor:'blue', width:'50', height:50 }); win.add(view); Ti.API.info("*** Before window open - view.size.width = 50 ***"); Ti.API.info("view.size w x h: " + view.size.width + " x " + view.size.height); // incorrect view.width = 100; win.addEventListener('open', function(){ Ti.API.info("*** Window open - view.size.width = 100 ***"); Ti.API.info("view.size w x h: " + view.size.width + " x " + view.size.height); // incorrect }); Ti.Gesture.addEventListener('orientationchange', function(){ Ti.API.info("*** orientationchange - view.size.width = 200 ***"); view.width = 200; Ti.API.info("view.size w x h: " + view.size.width + " x " + view.size.height); // incorrect }); win.open(); {code} h2. Logs {code:lang=none} 1454 AndroidRuntime D >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 1454 AndroidRuntime D CheckJNI is ON 60 InputManagerService W Got RemoteException sending setActive(false) notification to pid 1430 uid 10044 1454 AndroidRuntime D --- registering native functions --- 60 ActivityManager I Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.appcelerator.testing10/.Testing10Activity } 60 ActivityManager I Start proc com.appcelerator.testing10 for activity com.appcelerator.testing10/.Testing10Activity: pid=1461 uid=10044 gids={1015, 3003} 1454 AndroidRuntime D Shutting down VM 1454 AndroidRuntime I NOTE: attach of thread 'Binder Thread #3' failed 1461 TiApplication I (main) [0,0] checkpoint, app created. 1461 TiApplication I (main) [536,536] Titanium 1.8.0.1 (2011/12/22 13:09 fbdc96f) 1461 TiFastDev D (main) [164,700] Enabling Fastdev on port 58902 1461 TiFastDev D (main) [10,710] sent tokens successfully 1461 TiFastDev D (main) [1,711] Fastdev session handshake succesful. 1461 TiApplication I (main) [8,719] Titanium Javascript runtime: v8 1461 TiApplication W (main) [68,787] activity stack is emtpy, unable to get current activity 1461 TiRootActivity I (main) [0,0] checkpoint, on root activity create, savedInstanceState: null 1461 TiApplication W (main) [119,119] activity stack is emtpy, unable to get current activity 1461 TiApplication W (main) [1,120] activity stack is emtpy, unable to get current activity 1461 TiApplication W (main) [1,121] activity stack is emtpy, unable to get current activity 1461 TiApplication E (KrollRuntimeThread) [937,1058] APP PROXY: ti.modules.titanium.app.AppModule@44eb3110 1461 TiAssetHelper D Fetching "app.js" with Fastdev... 1461 TiAPI I *** Before window open - view.size.width = 50 *** 1461 TiAPI I view.size w x h: 0 x 0 1461 TiAPI I *** Window open - view.size.width = 100 *** 1461 TiAPI I view.size w x h: 0 x 0 1461 TiRootActivity I (main) [0,0] checkpoint, on root activity resume. activity = com.appcelerator.testing10.Testing10Activity@44e76478 60 ActivityManager I Displayed activity com.appcelerator.testing10/.Testing10Activity: 3359 ms (total 3359 ms) 60 WindowManager I Setting rotation to 1, animFlags=1 60 ActivityManager I Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/1 nav=3/1 orien=2 layout=34 uiMode=17 seq=70} 1461 TiAPI I *** orientationchange - view.size.width = 200 *** 1461 TiAPI I view.size w x h: 100 x 50 60 ActivityManager I Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=2 layout=34 uiMode=17 seq=71} 60 WindowManager I Setting rotation to 0, animFlags=0 60 ActivityManager I Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=34 uiMode=17 seq=72} 1461 TiAPI I *** orientationchange - view.size.width = 200 *** 1461 TiAPI I view.size w x h: 200 x 50 {code} h2. Discussions See Q/A topic: http://developer.appcelerator.com/question/124426/how-does-dimensions-work#216821 h2. Workaround Using setTimeout allows the size values to be updated to reflect the re-rendered view.
Story points: 1