[AC-2978] height / width / size , stooped working on v2.0+
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2012-07-17T09:19:17.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | api, ios |
Reporter | Yoram |
Assignee | Shak Hossain |
Created | 2012-06-27T02:19:31.000+0000 |
Updated | 2016-03-08T07:47:59.000+0000 |
Description
height / width / size for any view stopped working when it's 'auto','100%',Ti.UI.SIZE.
My project created and published to AppStore on version - 1.8.0.1. Now I decided to move on to the latest version of 2.0 - 2.1.
I found out that all my animation in my project stopped working.
If I set for example:
win.setHeight('100%')
getting: win.getHeight() was giving me the exact number (in pixels). Now it returns me '100%'. I can do nothing with this value. I need the number (like it worked before).
I tried to get the size of the device, reducing the status-bar calculation... but it is really a bad idea to support all platforms and devices.
I guess the idea of getHeight() now is to get the original value set, but before it gave the calculated number, is there a new property to have it now on 2.0? I searched and I didn't find... that's why I think it's a bug.
Btw, I also tried to check the width/height/size after the window opened and nothing helps.
Is there a way to fix that bug?
To get the height and width of the view if 'auto', '100%', Ti.UI.SIZE or Ti.UI.FILL has been specified, use the size.height and size.width property. Using the postlayout event listener is recommended as the actual height/width is returned after it has been rendered. For example:
The use of 'auto' is not advised as it will eventually be deprecated. Using Ti.UI.SIZE and Ti.UI.FILL is recommended. For more information on size behavior, please refer to this guide: https://wiki.appcelerator.org/display/guides/Titanium+2.0+Layout+Changes#Titanium2.0LayoutChanges-ViewTypesandDefaultLayoutBehavior.
If I need to make animation calculation, I can't do them all in this 'postlayout' event! I'm willing to wait until the window is ready for getting the correct width/height of views, but it's impossible to deal all the needs from this event, it must be accessible anytime from everywhere (like before). And how come from 'postlayout' the xxx.height will be 234px (for example) and from other area of code it will show the init state '77%'? It's wrong. Why not changing it to a fact that if the layout is ready, anytime I call to Height/Width properties I get it's value and not the init value (100% or whatever)? I'm sorry but I can't write all my code from 'postlayout' function with lots of "if" statements :-( Another thing is that I have a feeling that 'postlayout' event is not fired on time, sometimes it's not firing at all and sometimes it's firing more that once. Strange and not constant behavior.
Betty Tran. your solution is not working if you set the height to (still no values in 'postlayout' event function): height: '30%' // <-- AS I NEED IT (instead of what you did --> height: Ti.UI.FILL)
Setting the height to '30%' still yields the correct actual size.height value in the postlayout event. The height and width properties return the dimensions in platform units, which are the initial values declared. The size.height and size.width properties return the dimensions in system units. This is expected behavior as outlined in the documentation (http://docs.appcelerator.com/titanium/2.0/index.html#!/api/Titanium.UI.View-property-size).
I played a lot with this new "postlayout" event... and I can tell you one thing I noticed: IT IS NOT GOOD ENOUGH !!! It has many problems, impossible to code inside, too many tweaks knowing if it's the first time because it fires sometimes too much... and the most important: NO SUPPORT FOR WINDOW !!!!!!!!! I attach a handler to the main window (because I want the window sizes - excluding the "statusbar" for example) and I get millions of events for each view on the page! I just want to know the width/height of my window, before I show the window, I want to draw/place views on this window regarding it's sizes!!! IT WORKED ON 1.8, WHY DID IT STOPPED ??? I am stack on version 1.8 and can not move forward to 2.1 only because there are too many things that simply STOPPED working :-(
A workaround to obtain the window size without the status bar is to get the size property on window open. For example:
It was removed after 1.8 for performance reasons.
Hello, I tested this issue with the test code bellow. It’s working good in android/iOS. Device size, view height and width are getting perfectly.
Testing Environment:
Titanium SDK: 3.2.0, Titanium CLI: 3.2.0, Android SDK: 4.2.2Steps to Reproduce:
Create a sample project.
Paste this code in app.js file.
Run this code with testing environment.
h5. Test CodeThanks
Marking this closed since we can't reproduce it in our latest versions of the TISDK. We posted a sample to validate our test results.