Problem
The view's size property values are incorrect (they remain the previous values) when they are used/queried immediately after they have been modified.
Test case
In the example below, the width property is changed within a
orientationchange
event listener. When the device is reorientated, the logged value is the previous rather than new value.
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); // correct
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); // correct
});
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 on first orientation change
});
win.open();
Logs
[INFO] One moment, building ...
[INFO] Detected third-party module: com.testing.module1/1
[INFO] Detected third-party module: com.testing.module1/1
[INFO] Titanium SDK version: 1.8.0.1 (12/22/11 13:09 fbdc96f)
[INFO] iPhone Device family: universal
[INFO] iPhone SDK version: 5.0
[INFO] iPhone simulated device: iphone
[INFO] Launching application in Simulator
[INFO] Launched application in Simulator (1.55 seconds)
[INFO] Found 5.0 patch installed
[INFO] Application started
[INFO] testing11/1.0 (1.8.0.1.fbdc96f)
[INFO] *** Before window open - view.size.width = 50 ***
[INFO] view.size w x h: 50 x 50
[INFO] *** Window open - view.size.width = 100 ***
[INFO] view.size w x h: 100 x 50
[INFO] *** orientationchange - view.size.width = 200 ***
[INFO] view.size w x h: 100 x 50
[INFO] *** orientationchange - view.size.width = 200 ***
[INFO] view.size w x h: 200 x 50
Workaround
Using setTimeout allows the size values to be updated to reflect the re-rendered view.
Issue reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 iOS iPhone Simulator: iOS SDK version: 6.0
I am unable to reproduce this issue with the following environment; iPhone 7 (10.2) Studio 4.9.0.201705302345 Ti SDK 6.1.1.v20170620103414 Appc NPM 4.2.9 Appc CLI 6.2.1 Ti CLI 5.0.13 Alloy 1.9.11 Arrow 2.0.0 Xcode 8.2 (8C38) Node v4.8.2 Java 1.8.0_131