GitHub Issue | n/a |
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-03-17T21:08:34.000+0000 |
Affected Version/s | Release 3.1.3, Release 3.2.1 |
Fix Version/s | 2014 Sprint 06, 2014 Sprint 06 SDK, Release 3.2.3, Release 3.3.0 |
Components | iOS |
Labels | imageView, parity, qe-closed-3.2.3, qe-testadded, supportTeam |
Reporter | Eduardo Gomez |
Assignee | Vishal Duggal |
Created | 2013-11-13T19:09:48.000+0000 |
Updated | 2015-01-27T21:27:46.000+0000 |
Issue description
If you create an imageView of a predetermined height but do not specify the width, an image of unknown dimensions is scaled correctly to fit.
If we know the exact dimensions of the image we can specify both the width and height of the image view to be proportional and the left indent is respected. However there is some misbehaviour that occurs with PNG format images that are remote. They aren't left aligned correctly in iOS. Android position this remote PNG image correctly. Screen shoot attached: ImageView_Remote_iOS_PNG_format.jpg
Test Case
var imgUrlpng = 'http://www.elpuercoespin.com.ar/images/2013/01/fifa_logo.png';
var imgUrljpg = 'http://imagenes.es.sftcdn.net/es/scrn/75000/75908/fifa-manager-09-40.jpg';
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var myImage = Ti.UI.createImageView({
left: 10,
width: Ti.UI.SIZE,
height: 200,
//local
//image.jpg & KS_nav_views.png attached to jira
//image: 'image.jpg', /* iOS -> remote or local respected */
//image: 'KS_nav_views.png'
//remote
//left property not respected (format PNG) - iOS
//left property respected (format PNG) - Android
image: imgUrlpng
//image: imgUrljpg //left property respected
});
// this would work:
//myImage.image = 'http://example.com/foo.png'
// set myImage.defaultImage = 'localFoo.png' to show an image while the remote one is loading
myImage.defaultImage = 'KS_nav_views.png'; // to show an image while the remote one is loading
// as would
//myImage.image = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'foo.png');
win.add(myImage);
win.open();
Work around
To ensure an incoming image is scaled to 23 pixels in height and is left justified by 10 pixels (both platforms), without knowing the incoming image dimensions:
var imgUrlpng = 'http://www.elpuercoespin.com.ar/images/2013/01/fifa_logo.png';
var imgUrljpg = 'http://imagenes.es.sftcdn.net/es/scrn/75000/75908/fifa-manager-09-40.jpg';
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var imageTemp = Ti.UI.createImageView({
image: imgUrlpng,
height: Ti.UI.SIZE,
width: Ti.UI.SIZE
});
var imgWidth = imageTemp.toImage().width;
var imgHeight = imageTemp.toImage().height;
var relativeWidth = 23/imgHeight * imgWidth;
var tiHeaderImage = Ti.UI.createImageView({
image: imgUrlpng,
height: 23,
width: relativeWidth,
left: 10,
preventDefaultImage: true
});
win.add(tiHeaderImage);
win.open();
This has nothing to do with JPG and PNG images. Android scales images automatically to match device density based on image density. iOS does no such thing. We treat image dimensions as density independent. That is native platform behavior. The problem is that when calculating width for SIZE behavior iOS does not consider height parameter. We will fix this for ImageView if the height is specified as a fixed height (Anything other than auto, SIZE, FILL or PERCENT)
Test Case
Pull pending master - https://github.com/appcelerator/titanium_mobile/pull/5478 3_2_X - https://github.com/appcelerator/titanium_mobile/pull/5479
Tested and verified the fix with: Appcelerator Studio, build: 3.2.3.201403171239 Titanium SDK, build: 3.2.3.v20140317142455 Node.JS Version: v0.10.13 NPM Version: 1.3.2 ├── acs@1.0.14 ├── alloy@1.3.1 ├── npm@1.3.2 ├── titanium@3.2.1 └── titanium-code-processor@1.1.0 Device:iPhone5S iOS 7.0.1 Image aligned correctly in iOS