The easiest way to get the actual size of a surface is surface.getSize(true)
. You don't need to subclass Surface.
However, you will get an error if the surface isn't rendered to DOM yet. When a surface is rendered, it will emit a 'deploy' event. You can listen for it like this:
surface.on('deploy', function () {
// Your Code Here
}.bind(this));
More than likely you will also have to wrap your code in a Timer.setTimeout()
too. This is because the surface.getSize(true)
method will execute faster than the next render cycle (60 frames per second or ~16 milliseconds per cycle). The final code will look like this:
// With the rest of your require statements
var Timer = require('famous/utilities/Timer');
surface.on('deploy', function () {
Timer.setTimeout( function () {
// Your code here
// this.surface.getSize(true)
}.bind(this), 16);
}.bind(this));
I'm new to Famo.us too but I have had to implement this fix for a few different situations in my project and it seems to work perfectly.
Let me know if it works for you.