Skip to content

Commit

Permalink
Fix ImageView zoomEnabled bug
Browse files Browse the repository at this point in the history
Setting zoomEnabled to false while it is already disabled would attempt
to also reset the min/max/level values which can not be reset while
disabled.

Change-Id: I685f69e0694c0acc1b6e41daed91073de8d9a472
  • Loading branch information
mpost committed Mar 1, 2018
1 parent 5fa64e2 commit e2b081c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/api/widgets/ImageView.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"zoomEnabled": {
"type": "boolean",
"description": "Enables the pinch-to-zoom gesture on the `ImageView` and makes the properties `zoomLevel`, `minZoomLevel` and `maxZoomLevel` available. Setting `zoomEnabled` to `false` also resets the `zoomLevel`, `minZoomLevel`, `maxZoomLevel` to their respective defaults.",
"default": false,
"platforms": {
"windows": false
}
Expand Down
15 changes: 9 additions & 6 deletions src/tabris/widgets/ImageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ NativeObject.defineProperties(ImageView.prototype, {
},
zoomEnabled: {
type: 'boolean',
default: false,
set(name, value) {
if (!value) {
this.minZoomLevel = 1;
this.maxZoomLevel = 3;
this.zoomLevel = 1;
if (this.zoomEnabled !== value) {
if (!value) {
this.minZoomLevel = 1;
this.maxZoomLevel = 3;
this.zoomLevel = 1;
}
this._nativeSet(name, value);
this._storeProperty(name, value);
}
this._nativeSet(name, value);
this._storeProperty(name, value);
}
},
zoomLevel: {
Expand Down
8 changes: 8 additions & 0 deletions test/tabris/widgets/ImageView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ describe('ImageView', function() {
expect(client.calls({op: 'set', id: imageView.cid})[1].properties.zoomLevel).to.equal(1.0);
});

it('set false does not reset zoomLevel, minZoomLevel and maxZoomLevel when already disabled', function() {
imageView.zoomEnabled = false;
client.resetCalls();
imageView.zoomEnabled = false;

expect(client.calls({op: 'set', id: imageView.cid})).to.be.empty;
});

});

describe('zoomLevel', function() {
Expand Down

0 comments on commit e2b081c

Please sign in to comment.