javascript - Famo.us View can't contain imagesurface on top of a surface inside a scrollview -


define(function(require, exports, module){ var view            = require('src/core/view'); var surface         = require('src/core/surface'); var imagesurface    = require('src/surfaces/imagesurface'); var eventhandler    = require('src/core/eventhandler'); var statemodifier   = require('src/modifiers/statemodifier'); var rendernode      = require('src/core/rendernode'); var transform       = require('src/core/transform')  function detailedlist(){     view.apply(this, arguments);      _createstrips.call(this);     _createimage.call(this); }  detailedlist.prototype = object.create(view.prototype); detailedlist.prototype.constructor = detailedlist; detailedlist.default_options = {     height: 80,     width: undefined,     image: '',     content: '' }   function _createstrips(){     var backgroundsurface = new surface({         size: [this.options.width, this.options.height],         properties: {             backgroundcolor: '#fff',             padding: '10px 15px',             borderbottom: '1px solid rgba(0,0,0,0.1)',             marginbottom: '5px'         },         content: this.options.content     });     var bgmod = new statemodifier({         transform: transform.behind     })     backgroundsurface.pipe(this._eventoutput);      var node = new rendernode(bgmod);     node.add(backgroundsurface);     this.add(node);  }  function _createimage(){     var previewimage = new imagesurface({         size: [50, 50],         content: this.options.image     });      var previewmod = new statemodifier({         origin: [0.5, 0.5],         align : [0, 0.5]     });      previewimage.pipe(this._eventoutput);      var node = new rendernode(previewmod);     node.add(previewimage);     this.add(node); }   module.exports = detailedlist;}); 

this returns view background surface , image on top of it. using item in list. without image surface, scroll fine. when add image, first item appears. also, image outside view.

explaination of issue:

the detailedlist view has no constraints in size , being sized context of scrollview. adding rootnode view , setting it's size constrain items node's size.

define('detailedlist', function(require, exports, module) {   var view = require('famous/core/view');   var surface = require('famous/core/surface');   var imagesurface = require('famous/surfaces/imagesurface');   var eventhandler = require('famous/core/eventhandler');   var statemodifier = require('famous/modifiers/statemodifier');   var modifier = require('famous/core/modifier');   var rendernode = require('famous/core/rendernode');   var transform = require('famous/core/transform');    function detailedlist() {     view.apply(this, arguments);      this.rootnode = this.add(new modifier({       size: [this.options.width, this.options.height]     }));      _createstrips.call(this);     _createimage.call(this);   }    detailedlist.prototype = object.create(view.prototype);   detailedlist.prototype.constructor = detailedlist;   detailedlist.default_options = {     height: 80,     width: undefined,     image: '',     content: ''   };    function _createstrips() {     var backgroundsurface = new surface({       size: [this.options.width, this.options.height - 1],       properties: {         backgroundcolor: '#fff',         padding: '10px 65px',         borderbottom: '1px solid rgba(0,0,0,0.1)'       },       content: this.options.content     });     var bgmod = new statemodifier({       transform: transform.behind     });     backgroundsurface.pipe(this._eventoutput);      var node = new rendernode(bgmod);     node.add(backgroundsurface);     this.rootnode.add(node);    }    function _createimage() {     var previewimage = new imagesurface({       size: [50, 50],       content: this.options.image     });      var previewmod = new statemodifier({       origin: [0, 0.5],       align: [0, 0.5]     });      previewimage.pipe(this._eventoutput);      var node = new rendernode(previewmod);     node.add(previewimage);     this.rootnode.add(node);   }     module.exports = detailedlist; }); 

note:

using padding , margin needs taken consideration when using on child nodes. margin area not fire event, best reconsider using margin.

example snippet:

define('main', function(require, exports, module) {    var engine = require('famous/core/engine');    var optionsmanager = require('famous/core/optionsmanager');    var surface = require('famous/core/surface');    var modifier = require('famous/core/modifier');    var rendernode = require('famous/core/rendernode');    var transform = require('famous/core/transform');    var scrollview = require('famous/views/scrollview');      var detailedlist = require('detailedlist');      var maincontext = engine.createcontext();    maincontext.setperspective(1000);      var dl = new detailedlist({      height: 75,      content: 'famo.us application',      image: 'http://code.famo.us/assets/famous_logo.svg'    });      var surfaces = [];    var scrollview = new scrollview();      var counter = 0;      _getview = function(i) {      var cview = new detailedlist({        height: 75,        content: 'custom view - ' + i,        image: 'http://code.famo.us/assets/famous_logo.svg'      });        cview.pipe(scrollview);        return cview;    };      (var = 0; < 20; i++) {      var view = _getview(i);      surfaces.push(view);    }      scrollview.sequencefrom(surfaces);      maincontext.add(new modifier({      align: [0, 0],      origin: [0, 0]    })).add(scrollview);    });    require(['main']);    define('detailedlist', function(require, exports, module) {    var view = require('famous/core/view');    var surface = require('famous/core/surface');    var imagesurface = require('famous/surfaces/imagesurface');    var eventhandler = require('famous/core/eventhandler');    var statemodifier = require('famous/modifiers/statemodifier');    var modifier = require('famous/core/modifier');    var rendernode = require('famous/core/rendernode');    var transform = require('famous/core/transform');      function detailedlist() {      view.apply(this, arguments);        this.rootnode = this.add(new modifier({        size: [this.options.width, this.options.height]      }));        _createstrips.call(this);      _createimage.call(this);    }      detailedlist.prototype = object.create(view.prototype);    detailedlist.prototype.constructor = detailedlist;    detailedlist.default_options = {      height: 80,      width: undefined,      image: '',      content: ''    };      function _createstrips() {      var backgroundsurface = new surface({        size: [this.options.width, this.options.height - 1],        properties: {          backgroundcolor: '#fff',          padding: '10px 65px',          borderbottom: '1px solid rgba(0,0,0,0.1)'        },        content: this.options.content      });      var bgmod = new statemodifier({        transform: transform.behind      });      backgroundsurface.pipe(this._eventoutput);        var node = new rendernode(bgmod);      node.add(backgroundsurface);      this.rootnode.add(node);      }      function _createimage() {      var previewimage = new imagesurface({        size: [50, 50],        content: this.options.image      });        var previewmod = new statemodifier({        origin: [0, 0.5],        align: [0, 0.5]      });        previewimage.pipe(this._eventoutput);        var node = new rendernode(previewmod);      node.add(previewimage);      this.rootnode.add(node);    }        module.exports = detailedlist;  });
<script src="http://requirejs.org/docs/release/2.1.16/minified/require.js"></script>  <script src="http://code.famo.us/lib/requestanimationframe.js"></script>  <script src="http://code.famo.us/lib/classlist.js"></script>  <script src="http://code.famo.us/lib/functionprototypebind.js"></script>    <link rel="stylesheet" type="text/css" href="http://code.famo.us/famous/0.3.5/famous.css" />  <script src="http://code.famo.us/famous/0.3.5/famous.min.js"></script>


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -