gpt4 book ai didi

javascript - 使用 famo.us RenderController 切换回来时表面顺序困惑

转载 作者:行者123 更新时间:2023-11-30 12:43:16 25 4
gpt4 key购买 nike

初学者问题。我正在尝试建立一个 famo.us 应用程序。到目前为止,我在一个简单的实验中得到了很好的结果。

现在我的应用程序正在增长,我想允许在“屏幕”之间移动:登陆屏幕 -> 信息屏幕 -> 返回登陆屏幕 -> 等等。

我的“屏幕”是 View(),在 View() 中添加了表面、修饰符等

我使用 RenderController() 通过它的 hide()show() 函数在屏幕之间切换。

问题是当返回到之前使用过的屏幕时,表面不再显示!

代码:
var app_render_controller = new RenderController();
app_render_controller.show(landing_screen);//好的
app_render_controller.hide(landing_screen);//好的
app_render_controller.show(信息屏幕);//好的
app_render_controller.hide(信息屏幕);//好的
app_render_controller.show(landing_screen);//不行 -> 我只看到我的背景表面!

在检查 DOM 时,我能够在它们应该在的位置看到我的表面的轮廓,但它们是隐藏的。看起来背景表面现在位于内容表面(ScrollView)的前面。如果我隐藏背景,我会再次看到 ScrollView 。

我读到元素的重叠与它们添加到渲染树的顺序相对应。因此,由于我基于 View() 的“屏幕”下的树没有改变,Scrollview 应该仍然像第一次一样绘制在背景之上?

这是预期的吗?难道我做错了什么 ?我错过了什么吗?

-------- 编辑------

我的代码(大致):

var main_context = Engine.createContext();

var root_render_controller = new RenderController();
main_context.add(root_render_controller);

var landing_screen = new View();
landing_screen.add(new Surface(...background texture...));
var scrollview = new Scrollview();
landing_screen.add(scrollview);
// (add stuff to the scrollview)

var info_screen = new View();
info_screen.add(new Surface(...background texture...));
info_screen.add(new Surface(...some message...));

root_render_controller.show(landing_screen);
// display is fine
root_render_controller.hide(landing_screen);
root_render_controller.show(info_screen);
// display is fine
root_render_controller.hide(info_screen);
root_render_controller.show(landing_screen); // again
// display is wrecked : the background surface is now hiding the scrollview !

查看 DOM 时,我们可以看到翻转:

登陆屏幕的第一个显示:背景然后是 ScrollView 及其 6 个元素

1st display of the landing screen : background then the scrollview and its 6 elements

登陆屏幕的第二次显示: ScrollView 及其 6 个元素,然后是背景!

2nd display of the landing screen : scrollview and its 6 elements then the background

最佳答案

I read that the overlap of elements was corresponding to the order they were added to the rendering tree

据我所知,元素的重叠是由创建顺序的倒数设置的(例如,最后一个在最上面),而不是添加到渲染树中。

创建 Surface 时,它​​会注册到 Entity: https://github.com/Famous/core/blob/master/Surface.js#L60

function Surface(options) {
...
this.id = Entity.register(this);
...
}

RenderNode 上的更改被提交时,它们将根据创建顺序应用(因为 Object.keys 以数字顺序返回数组中的索引): https://github.com/Famous/core/blob/master/RenderNode.js#L106

function _applyCommit(spec, context, cacheStorage) {
var result = SpecParser.parse(spec, context);
var keys = Object.keys(result);
for (var i = 0; i < keys.length; i++) {
var id = keys[i];
var childNode = Entity.get(id);
....
}

您可以通过创建两个 Surface 并将您创建的第二个添加到第一个之前的 Context 来对此进行测试。它仍然会在顶部:

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

var mainContext = Engine.createContext();

var surface1 = new Surface({
size: [200, 200],
content: "Red",
properties: {
lineHeight: "200px",
textAlign: "center",
backgroundColor: "#f00"
}
});

var surface2 = new Surface({
size: [200, 200],
content: "Green",
properties: {
lineHeight: "200px",
textAlign: "center",
backgroundColor: "#0f0"
}
});

// Doesn't matter what order you add these - surface2 will be on top
mainContext.add(surface2);
mainContext.add(surface1);
});

希望这能给您一个开始寻找的好地方。如果您分享您的背景添加到 Context 的位置以了解为什么它现在位于前面,这将会有所帮助。

关于javascript - 使用 famo.us RenderController 切换回来时表面顺序困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23583896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com