how best to create a single scrollable view in famo.us?

。_饼干妹妹 提交于 2019-12-03 17:29:12

I will assume you are using a true-sized surface for the dynamic length long form content. When doing so, scrollview can't understand a size of true, so you get no scrolling. We can instead wrap our surface in a RenderNode and Modifier and use the sizeFrom function of Modifier to wrap the true sized surface with an actual size in pixels. This way scrollview knows how long your content is and will scroll accordingly.

Here is the example! Hope it helps!

var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var RenderNode = require('famous/core/RenderNode');
var Modifier = require('famous/core/Modifier');
var Scrollview  = require('famous/views/Scrollview');

var context = Engine.createContext();

var content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod \
                tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, \
                quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo \
                consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse \
                cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non \
                proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

var scrollview = new Scrollview();

var surfaces = [];
scrollview.sequenceFrom(surfaces);

surface = new Surface({
    size:[undefined,true],
    content: content,
    properties:{
        fontSize:'100px'
    }
})

surface.pipe(scrollview);

surface.node = new RenderNode();
surface.mod = new Modifier();

surface.mod.sizeFrom(function(){
    target = surface._currTarget;
    if (target){
        return [undefined,target.offsetHeight];
    } else {
        return [undefined,true];
    }
})

surface.node.add(surface.mod).add(surface);

surfaces.push(surface.node);

context.add(scrollview);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!