How to lay between surfaces in Famo.us?

Using the following sample code Famo.us, which adds 10 surfaces displayed vertically with 100% width and height, how can I add functionality to scroll between them, similar to how 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);
});
+4
source share
2 answers

You can achieve the effect of the iOS desktop screen using the Scrollview class with paging enabled. This allows you to drag from one page to another or scroll. I believe that the EdgeSwapper class will only handle 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);
+6
source

Source: https://habr.com/ru/post/1540491/


All Articles