【问题标题】:Is there a way to access the badgeValue of IOS for tabviews using nativescript有没有办法使用nativescript访问选项卡视图的IOS的badgeValue
【发布时间】:2020-01-24 18:28:07
【问题描述】:

我正在尝试为 ios 选项卡创建徽章,我知道通常您可以使用 badgeValue 变量快速访问它,在 nativescript 中有类似的方法吗

【问题讨论】:

    标签: nativescript nativescript-vue


    【解决方案1】:

    是的,您可以访问本机属性。你也可以在 Android 的 TabView 中嵌入一个 Label 来模仿 iOS 的徽章功能

    const tabView = <any>args.object;
    if (isIOS) {
        tabView.items.forEach((item) => {
            if (item.bageValue) {
                item.__controller.tabBarItem.badgeValue = item.bageValue;
            }
        });
    }
    if (isAndroid) {
        tabView._badges = {};
        const nativeTabView = tabView._tabLayout.getChildAt(0);
        for (let i = 0; i < nativeTabView.getChildCount(); i++) {
            addBadges(tabView, i, nativeTabView.getChildAt(i), tabView.items[i].bageValue);
        }
    }
    

    Playground Sample

    注意:示例是在 TypeScript 中,使用 Vue 只是添加侦听器/方法的框架语法可能会有所不同。

    【讨论】:

    • 抱歉来晚了,但这对您有很大帮助谢谢??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    相关资源
    最近更新 更多