How to Swipe between surfaces in Famo.us?

独自空忆成欢 提交于 2019-11-29 23:14:33

问题


Using the following Famo.us example code that adds 10 surfaces displayed vertically with 100% width and height, how can I add functionality to swipe between them, similar to how the swiping works on the iOS home screen?

define(function(require, exports, module) {
    var Engine           = require("famous/core/Engine");
    var Surface          = require("famous/core/Surface");
    var SequentialLayout = require("famous/views/SequentialLayout");

    var mainContext = Engine.createContext();

    var sequentialLayout = new SequentialLayout({
        direction: 0
    });
    var surfaces = [];

    sequentialLayout.sequenceFrom(surfaces);

    for (var i = 0; i < 10; i++) {
        surfaces.push(new Surface({
            content: "Surface: " + (i + 1),
            size: [window.innerWidth, window.innerHeight],
            properties: {
                backgroundColor: "hsl(" + (i * 360 / 10) + ", 100%, 50%)",
                lineHeight: window.innerHeight/10 + "px",
                textAlign: "center"
            }
        }));
    }

    mainContext.add(sequentialLayout);
});

回答1:


You can achieve the effect of an iOS homescreen using the Scrollview class with paging enabled. This allows you to actually drag from one page to another or swipe. I believe the EdgeSwapper class will only deal with the swipe.

Here is your example modified to use Scrollview with paging..

Hope this helps!

var Engine           = require("famous/core/Engine");
var Surface          = require("famous/core/Surface");
var Scrollview       = require("famous/views/Scrollview");

var mainContext = Engine.createContext();

var scrollview = new Scrollview({
    direction: 0,
    paginated: true
});
var surfaces = [];

scrollview.sequenceFrom(surfaces);

for (var i = 0; i < 10; i++) {
    surface = new Surface({
        content: "Surface: " + (i + 1),
        size: [window.innerWidth, window.innerHeight],
        properties: {
            backgroundColor: "hsl(" + (i * 360 / 10) + ", 100%, 50%)",
            lineHeight: window.innerHeight/10 + "px",
            textAlign: "center"
        }
    });

    surface.pipe(scrollview);

    surfaces.push(surface);
}

mainContext.add(scrollview);



回答2:


Have you looked into the EdgeSwapper? I think it might be an example of what you're looking for: https://github.com/Famous/examples/blob/master/src/examples/views/EdgeSwapper/example.js



来源:https://stackoverflow.com/questions/23649958/how-to-swipe-between-surfaces-in-famo-us

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