From de9ff911c48fa72b446bf5cba2f14d575394510e Mon Sep 17 00:00:00 2001 From: atanda rasheed Date: Sat, 14 Oct 2023 02:44:44 +0100 Subject: [PATCH] fix: include the tabview element --- src/nativescript/elements.ts | 36 +++++++++++++++++++++++++++++++++++- src/registry/index.ts | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/nativescript/elements.ts b/src/nativescript/elements.ts index 532224d2..b7db8482 100644 --- a/src/nativescript/elements.ts +++ b/src/nativescript/elements.ts @@ -1,4 +1,9 @@ -import { Frame as NSCFrame, Page as NSCPage } from '@nativescript/core'; +import { + Frame as NSCFrame, + Page as NSCPage, + TabView as NSCTabView, + TabViewItem as NSCTabViewItem, +} from '@nativescript/core'; import { warn } from '@vue/runtime-core'; @@ -217,4 +222,33 @@ export function registerCoreElements() { }, }, ); + + registerElement( + 'TabViewItem', + () => require('@nativescript/core').TabViewItem, + ); + + registerElement('TabView', () => require('@nativescript/core').TabView, { + model: { + prop: 'selectedIndex', + event: 'selectedIndexChange', + }, + nodeOps: { + insert(child, parent) { + const tabView = parent.nativeView as NSCTabView; + + if (child.nativeView instanceof NSCTabViewItem) { + const items = tabView.items || []; + + parent.setAttribute('items', items.concat([child.nativeView])); + } + }, + remove(child, parent) { + const tabView = parent.nativeView as NSCTabView; + const items = tabView.items.filter((item) => item !== child.nativeView); + + parent.setAttribute('items', items); + }, + }, + }); } diff --git a/src/registry/index.ts b/src/registry/index.ts index 377b5965..233032b6 100644 --- a/src/registry/index.ts +++ b/src/registry/index.ts @@ -1,4 +1,4 @@ -import { NSVElement, NSVViewFlags } from '../dom'; +import type { NSVElement, NSVViewFlags } from '../dom'; export type NSVElementResolver = () => any;