Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): report width/height of Blob as pixels, not points #11803

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions iphone/TitaniumKit/TitaniumKit/Sources/API/TiBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (NSUInteger)width
{
[self ensureImageLoaded];
if (image != nil) {
return image.size.width;
return image.size.width * image.scale;
}
return 0;
}
Expand All @@ -78,7 +78,7 @@ - (NSUInteger)height
{
[self ensureImageLoaded];
if (image != nil) {
return image.size.height;
return image.size.height * image.scale;
}
return 0;
}
Expand All @@ -88,7 +88,7 @@ - (NSUInteger)size
{
[self ensureImageLoaded];
if (image != nil) {
return image.size.width * image.size.height;
return image.size.width * image.size.height * image.scale * image.scale;
}
switch (type) {
case TiBlobTypeData: {
Expand Down
57 changes: 57 additions & 0 deletions tests/Resources/ti.blob.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* eslint no-unused-expressions: "off" */
'use strict';
const should = require('./utilities/assertions');

describe('Titnaium.Blob', function () {
this.slow(2000);
this.timeout(5000);

let win;
afterEach(done => { // fires after every test in sub-suites too...
if (win && !win.closed) {
win.addEventListener('close', function listener () {
win.removeEventListener('close', listener);
win = null;
done();
});
win.close();
} else {
win = null;
done();
}
});

// iOS had a bug where it reported Blob width/height as pts, but Android reported px
// And worse - numbers not divisble by the device scale (2, 3, etc) we could not reliably reproduce the *real* pixel size
// i.e. a 10 x 10 pixel image/view on a 3x device woudl report width/height of 3 and scale of 3, so just multiplying those we'd get 9
// when the real image was actually 10px.
// However, natively we *can* properly generate true pixel size because image would report scale like 3.33 that we coudl multiply by before returning
it('image dimensions should be reported in pixels', finish => {
win = Ti.UI.createWindow();
const view = Ti.UI.createView({
backgroundColor: 'green',
width: '11px',
height: '13px'
});
win.add(view);
win.addEventListener('postlayout', function postlayout() {
win.removeEventListener('postlayout', postlayout); // only run once
try {
const blob = view.toImage();
should(blob.width).equal(11);
should(blob.height).equal(13);
} catch (e) {
return finish(e);
}
finish();
});
win.open();
});
});