Skip to content

Commit 90c1220

Browse files
fix: Fix onSizeChange
onSizeChange hasn't been called. Fixes #476
1 parent 6224618 commit 90c1220

3 files changed

Lines changed: 57 additions & 12 deletions

File tree

core/Size.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var ZEROS = [0, 0, 0];
3434
* @param {Size} parent the parent size
3535
*/
3636
function Size (parent) {
37-
3837
this.finalSize = new Float32Array(3);
3938
this.sizeChanged = false;
4039

@@ -266,6 +265,25 @@ Size.prototype.getDifferential = function getDifferential () {
266265
return this.differentialSize;
267266
};
268267

268+
/**
269+
* Gets the render size of this size representation
270+
*
271+
* @method
272+
*
273+
* @return {array} array of render size
274+
*/
275+
Size.prototype.getRender = function getRender () {
276+
return this.renderSize;
277+
};
278+
279+
/**
280+
* Preserved for backwards compatibility.
281+
*
282+
* @deprecated
283+
* @alias {Size#getRender}
284+
*/
285+
Size.prototype.getRenderSize = Size.prototype.getRender;
286+
269287
/**
270288
* Sets the size of this size representation.
271289
*
@@ -301,6 +319,7 @@ Size.prototype.fromComponents = function fromComponents (components) {
301319
var changed = false;
302320
var len = components.length;
303321
var j;
322+
var candidate;
304323
for (var i = 0 ; i < 3 ; i++) {
305324
prev = target[i];
306325
switch (mode[i]) {
@@ -311,13 +330,18 @@ Size.prototype.fromComponents = function fromComponents (components) {
311330
target[i] = this.absoluteSize[i];
312331
break;
313332
case Size.RENDER:
314-
var candidate;
315333
var component;
316334
for (j = 0; j < len ; j++) {
317335
component = components[j];
318336
if (component && component.getRenderSize) {
319337
candidate = component.getRenderSize()[i];
320-
target[i] = target[i] < candidate || target[i] === 0 ? candidate : target[i];
338+
339+
if (this.renderSize[i] !== candidate) {
340+
this.renderSize[i] = candidate;
341+
this.renderSizeChanged = true;
342+
}
343+
344+
target[i] = candidate;
321345
}
322346
}
323347
break;
@@ -329,4 +353,3 @@ Size.prototype.fromComponents = function fromComponents (components) {
329353
};
330354

331355
module.exports = Size;
332-

core/SizeSystem.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
var PathStore = require('./PathStore');
2828
var Size = require('./Size');
2929
var Dispatch = require('./Dispatch');
30+
var TransformSystem = require('./TransformSystem');
3031
var PathUtils = require('./Path');
3132

3233
/**
@@ -118,12 +119,10 @@ SizeSystem.prototype.update = function update () {
118119
if (size.proportionalSizeChanged) proportionalSizeChanged(node, components, size);
119120
if (size.differentialSizeChanged) differentialSizeChanged(node, components, size);
120121
if (size.renderSizeChanged) renderSizeChanged(node, components, size);
121-
if (size.fromComponents(components)) sizeChanged(node, components, size);
122+
if (size.fromComponents(components)) sizeChanged(node, components, size, paths[i]);
122123
}
123124
};
124125

125-
// private methods
126-
127126
/**
128127
* Private method to alert the node and components that size mode changed.
129128
*
@@ -233,7 +232,7 @@ function differentialSizeChanged (node, components, size) {
233232
* @return {undefined} undefined
234233
*/
235234
function renderSizeChanged (node, components, size) {
236-
var renderSize = size.getRenderSize();
235+
var renderSize = size.getRender();
237236
var x = renderSize[0];
238237
var y = renderSize[1];
239238
var z = renderSize[2];
@@ -253,10 +252,11 @@ function renderSizeChanged (node, components, size) {
253252
* @param {Node} node Node to potentially call onSizeChange on
254253
* @param {Array} components a list of the nodes' components
255254
* @param {Size} size the size class for the Node
255+
* @params {String} path the size path
256256
*
257257
* @return {undefined} undefined
258258
*/
259-
function sizeChanged (node, components, size) {
259+
function sizeChanged (node, components, size, path) {
260260
var finalSize = size.get();
261261
var x = finalSize[0];
262262
var y = finalSize[1];
@@ -266,6 +266,9 @@ function sizeChanged (node, components, size) {
266266
if (components[i] && components[i].onSizeChange)
267267
components[i].onSizeChange(x, y, z);
268268
size.sizeChanged = false;
269+
270+
var transform = TransformSystem.get(path);
271+
transform._dirtyFromSizeChange = true;
269272
}
270273

271274
module.exports = new SizeSystem();

core/Transform.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function Transform (parent) {
5959
this.parent = parent ? parent : null;
6060
this.breakPoint = false;
6161
this.calculatingWorldMatrix = false;
62+
this._dirty = false;
6263
}
6364

6465
Transform.IDENT = [ 1, 0, 0, 0,
@@ -464,9 +465,27 @@ Transform.prototype.calculateWorldMatrix = function calculateWorldMatrix () {
464465
while (nearestBreakPoint && !nearestBreakPoint.isBreakPoint())
465466
nearestBreakPoint = nearestBreakPoint.parent;
466467

467-
if (nearestBreakPoint) return multiply(this.global, nearestBreakPoint.getWorldTransform(), this.local);
468+
if (nearestBreakPoint) {
469+
return multiply(this.global, nearestBreakPoint.getWorldTransform(), this.local);
470+
}
468471
else {
469-
for (var i = 0; i < 16 ; i++) this.global[i] = this.local[i];
472+
this.global[0] = this.local[0];
473+
this.global[1] = this.local[1];
474+
this.global[2] = this.local[2];
475+
this.global[3] = this.local[3];
476+
this.global[4] = this.local[4];
477+
this.global[5] = this.local[5];
478+
this.global[6] = this.local[6];
479+
this.global[7] = this.local[7];
480+
this.global[8] = this.local[8];
481+
this.global[9] = this.local[9];
482+
this.global[10] = this.local[10];
483+
this.global[11] = this.local[11];
484+
this.global[12] = this.local[12];
485+
this.global[13] = this.local[13];
486+
this.global[14] = this.local[14];
487+
this.global[15] = this.local[15];
488+
470489
return false;
471490
}
472491
};
@@ -715,7 +734,7 @@ function multiply (out, a, b) {
715734
var res;
716735

717736
// Cache only the current line of the second matrix
718-
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
737+
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
719738

720739
res = b0*a00 + b1*a10 + b2*a20 + b3*a30;
721740
changed = changed ? changed : out[0] === res;

0 commit comments

Comments
 (0)