NATIVESCRIPT - 核心(JS) - 在TabView和BLANK页面之间切换

问题描述 投票:0回答:1

我正在开发一个基于TabViews的应用程序。但是如果用户没有登录,我想在应用程序启动时显示登录屏幕,分别在登出后显示登录屏幕。登录屏幕不应位于TabView的框架中。

TabView在app-root.xml中设置。

<TabView loaded="onLoadedTabView" id="tabView" androidTabsPosition="bottom">
    <TabViewItem title="Home">
        <Frame defaultPage="home/home-page"></Frame>
    </TabViewItem>

    <TabViewItem title="Second">
        <Frame defaultPage="second/second-page"></Frame>
    </TabViewItem>

    <TabViewItem title="Third">
        <Frame defaultPage="third/third-page"></Frame>
    </TabViewItem>
</TabView>

我有一个login-root.xml来加载登录页面

<Frame defaultPage="login/login-page"></Frame>

在app.js中,我想先决定是先启动“app-root”还是“login-root”。

const appSettings = require("application-settings");
let application = require("tns-core-modules/application");


if (typeof appSettings.getString('username') === 'undefined') {
    application.run({ moduleName: "login-root" });
} else {
    application.run({ moduleName: "app-root" });
}

如果我现在首先加载LOGIN,我运行带有application.run的TabView({moduleName:“app-root”});再次。我想,这不是最好的方法。

如何加载和渲染TabView?

我有一个NS-PLAYGROUND应用程序,希望能帮助我。我真的很感激解决方案:

https://play.nativescript.org/?template=play-js&id=fk1uUx

非常感谢你!!!

最好的问候,托比亚斯

javascript login nativescript core tabview
1个回答
0
投票

您可以简单地调用application._resetRootView(...)以使用TabView替换您的根视图,或根据需要返回登录框架。

Playground Sample

另一个选项是创建包含TabView的新页面并将页面加载到登录框架中。

© www.soinside.com 2019 - 2024. All rights reserved.