There are a couple of ways to solve this issue. Famo.us is aware of this limitation and it should be pretty high on the priority list..
In this example, a new surface class is created that emits an event in the deploy function or when the surface is rendered. I am sure to grab the reference to the original deploy function during construction, so that can be called normally later on. Once you receive the render event you can edit the surface any way you wish..
Good Luck!
var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var StateModifier = require('famous/modifiers/StateModifier');
var EventHandler = require('famous/core/EventHandler');
function MySurface(options) {
Surface.apply(this, arguments);
this._superDeploy = Surface.prototype.deploy;
}
MySurface.prototype = Object.create(Surface.prototype);
MySurface.prototype.constructor = MySurface;
MySurface.prototype.deploy = function deploy(target) {
this._superDeploy(target);
this.eventHandler.trigger('surface-has-rendered', this);
};
var context = Engine.createContext();
var event_handler = new EventHandler();
event_handler.on('surface-has-rendered', function(surface){
var size = surface.getSize();
var width = (size[0] == true) ? surface._currTarget.offsetWidth : size[0] ;
var height = (size[1] == true) ? surface._currTarget.offsetHeight : size[1] ;
surface.setSize([width,height]);
console.log(surface.getSize());
})
var surface = new MySurface({
size: [true,true],
content: "Hello",
properties: {
color: 'white',
textAlign: 'center',
padding: '20px',
backgroundColor: 'green'
}
})
surface.pipe(event_handler);
context.add(new StateModifier({origin:[0.5,0.5]})).add(surface);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…