nativescript-community / ui-material-components

Monorepo that contains all of the NativeScript Material Design plugins.
https://nativescript-community.github.io/ui-material-components/
Apache License 2.0
218 stars 80 forks source link

MDTabContentItem already registered #457

Open scottix opened 10 months ago

scottix commented 10 months ago

Getting an error when using nativescript-vue, ui-material-bottom-navigation, and ui-material-tabs

  System.err: An uncaught Exception occurred on "main" thread.
  System.err: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: Error calling module function
  System.err: Error: Element for MDTabContentItem already registered.
  System.err: If this is intentional set 'overwriteExisting: true' in 'meta'

Which platform(s) does your issue occur on?

Tested on Emulator

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

tns plugin add @nativescript-community/ui-material-bottom-navigation tns plugin add @nativescript-community/ui-material-tabs

Is there any code involved?

import { createApp } from 'nativescript-vue';
import { createPinia } from 'pinia';
import ButtonPlugin from '@nativescript-community/ui-material-button/vue';
import CardViewPlugin from '@nativescript-community/ui-material-cardview/vue';
import BottomNavigation from '@nativescript-community/ui-material-bottom-navigation/vue';
import TabsPlugin from '@nativescript-community/ui-material-tabs/vue';
import BottomNavFrame from './frames/BottomNavFrame.vue'

const pinia = createPinia();

createApp(BottomNavFrame)
  .use(BottomNavigation)
  .use(ButtonPlugin)
  .use(CardViewPlugin)
  .use(TabsPlugin)
  .use(pinia)
  .start();

Seems like it is being registered twice or is there another way to include it?

farfromrefug commented 10 months ago

@scottix yes it is because you use both TabsPlugin and BottomNavigation which both use MDTabContentItem. The easy fix is to register components manually for one of them. But the best solution would be to create an issue on vue3 repo. This shoud not be an error. At best a warning. But there is nothing wrong with doing this.

scottix commented 10 months ago

Ok I was able to work around the issue. Since I only need MDTabs that hasn't been registered

import { createApp } from 'nativescript-vue';
import { createPinia } from 'pinia';
import ButtonPlugin from '@nativescript-community/ui-material-button/vue';
import BottomNavigation from '@nativescript-community/ui-material-bottom-navigation/vue';
import CardViewPlugin from '@nativescript-community/ui-material-cardview/vue';
import { Tabs } from '@nativescript-community/ui-material-tabs';
import FloatingActionButtonPlugin from '@nativescript-community/ui-material-floatingactionbutton/vue';
import BottomNavFrame from './frames/BottomNavFrame.vue'

const pinia = createPinia();
const app = createApp(BottomNavFrame);

app.use(BottomNavigation)
  .use(ButtonPlugin)
  .use(CardViewPlugin)
  .use(FloatingActionButtonPlugin)
  .use(pinia);

app.registerElement('MDTabs', () => Tabs, {
    model: {
        prop: 'selectedIndex',
        event: 'selectedIndexChange'
    },
    component: require('@nativescript-community/ui-material-tabs/vue/component').default
  });

app.start();

One thing you could change on your install script for each registerElement Vue.registerElement('MDTabStrip', () => TabStrip, { overwriteExisting: true });

farfromrefug commented 10 months ago

@scottix great you got it to work