著名:滚动视图中的滚动视图 [英] famous: scrollview within scrollview

查看:48
本文介绍了著名:滚动视图中的滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个类似于 BBC News 原生应用程序的布局(使用着名的.js);一个垂直 ScrollView,其中有许多水平 ScrollView.我已经工作"到一切都可以渲染和水平滚动条完美工作的程度.我的问题是,如果用户在水平 ScrollView 内滑动表面,则不会触发垂直滚动事件.如果我触摸水平滚动条之外的区域,垂直滚动条将完成其工作并滚动......垂直

I'm trying to create a layout (using famous.js) similar to the BBC News native app; a vertical ScrollView, within which are numerous horizontal ScrollViews. I've got both 'working' to the extent that everything renders and the horizontal scrollers work perfectly. My issue is that the vertical scroll event won't fire if the user swipes a surface within a horizontal ScrollView. If i touch an area outside the horizontal scrollers, the vertical scroller will do its job and scroll... vertically

有谁知道我错过了什么?我有一种感觉,可能需要一个 RenderNode,但到目前为止还没有运气.我刚刚开始了解 Famous.到目前为止我所看到的是惊人的,但无法弄清楚这一点真的让我感到...

Does anyone know what i'm missing? I have a feeling that a RenderNode may be needed, but have had no luck so far. I'm just getting to grips with Famous. What i've seen so far is amazing, but not being able to figure this out is really getting to me...

如果有人可以提供帮助,请先感谢优步...

Uber thanks in advance if anyone can help...

    /*globals define*/
    define(function(require, exports, module) {

        // import dependencies
        var Modifier           = require('famous/core/Modifier');
        var Engine             = require('famous/core/Engine');
        var Surface            = require('famous/core/Surface');
        var HeaderFooterLayout = require('famous/views/HeaderFooterLayout');
        var Scrollview         = require('famous/views/Scrollview');
        var ContainerSurface   = require('famous/surfaces/ContainerSurface');

        var mainContext = Engine.createContext();

        var layout = new HeaderFooterLayout({
            headerSize: 50,
            footerSize: 50
        });

        // create app header and add to layout
        var appHeader = new ContainerSurface({
            size: [undefined, 50],
            classes: ['app-header']
        });
        appHeader.add(new Surface({
            size: [undefined, 50],
            content: 'Site Name',
            classes: ['app-header__title'],
            properties: {
                lineHeight: '50px',
                textAlign: 'center'
            }
        }));
        layout.header.add(appHeader);

        // create page container surface
        var page = new ContainerSurface({
            properties: {
                top: '0'
            }
        });

        // returns a horizontal ScrollView containing 
        function createCategory() {
            var categoryScroll = new Scrollview({
                direction: 0,
            });
            var surfaces = [];
            categoryScroll.sequenceFrom(surfaces);
            for (var i = 0, temp; i < 7; i++) {
                var temp = new Surface({
                    size: [128, 128],
                    content: 'surface' + (i + 1),
                    properties: {
                        backgroundColor: '#fff',
                        borderColor: '#303030',
                        borderStyle: 'solid',
                        borderWidth: '0px',
                        borderRightWidth: '4px',
                        borderLeftWidth: '4px'
                    }
                });
                temp.pipe(categoryScroll);
                surfaces.push(temp);
            }
            return categoryScroll; 
        }

        // returns a vertical page scroll
        function createPageScroll() {

            // create array of horizontal ScrollViews
            categories = [];
            for (var i = 0; i < 7; i++) {
                categories.push(createCategory());
            };

            var pageScroll = new Scrollview();
            var surfaces = [];
            for (var i = 0; i < 7; i++) {
                temp = new ContainerSurface({
                    size: [window.innerWidth, 136],
                });
                temp.add(categories[i]);
                surfaces.push(temp);
                pageScroll.sequenceFrom(surfaces);
                temp.pipe(pageScroll);
            };

            return pageScroll;
        }

        layout.content.add(createPageScroll());
        mainContext.add(layout);

    });

推荐答案

我看到你想通了,但我想我会为任何需要一个起点的人发布一个干净的工作示例..所以这里是..

I see you figured it out, but I thought I would post a clean working example for anyone that needed a starting point.. So here it is..

要回答这个问题,是的,您需要将事件从表面传送到每个滚动视图

To answer the question, Yes, you needed to pipe your events from the surfaces to each of the scrollviews

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

var context = Engine.createContext();

var surfaces1 = [];
var surfaces2 = [];

var scrollers = [];

scroll_v_cont = new ContainerSurface({
    size:[300,300],
    properties: { overflow: 'hidden' }
});

var scroll_v = new Scrollview({ direction: 1 });

scroll_v.sequenceFrom(scrollers);

scroll_v_cont.add(scroll_v);

var scroll_h1_cont = new ContainerSurface({
    size:[300,300],
    properties: {overflow: 'hidden'}
});


var scroll_h1 = new Scrollview({ direction: 0});

scroll_h1.sequenceFrom(surfaces1);

scroll_h1_cont.add(scroll_h1);


var scroll_h2_cont = new ContainerSurface({
    size:[300,300],
    properties: { overflow: 'hidden'}
})


var scroll_h2 = new Scrollview({ direction: 0})

scroll_h2.sequenceFrom(surfaces2);

scroll_h2_cont.add(scroll_h2);

scrollers.push(scroll_h1_cont);
scrollers.push(scroll_h2_cont);

for (var i = 0; i < 4; i++) {
    var surface1 = new Surface({
         content: "Surface: " + (i + 1),
         size: [300, 300],
         properties: {
             backgroundColor: "hsl(" + (i * 360 / 8) + ", 100%, 50%)",
             lineHeight: "200px",
             textAlign: "center"
         }
    });

    surface1.pipe(scroll_v);
    surface1.pipe(scroll_h1);
    surfaces1.push(surface1);

    var surface2 = new Surface({
         content: "Surface: " + (i + 1),
         size: [300, 300],
         properties: {
             backgroundColor: "hsl(" + (i * 360 / 8 + (360 / 8)*4) + ", 100%, 50%)",
             lineHeight: "200px",
             textAlign: "center"
         }
    });

    surface2.pipe(scroll_v);
    surface2.pipe(scroll_h2);
    surfaces2.push(surface2);

};

context.add(scroll_v_cont);

这篇关于著名:滚动视图中的滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆