Skip to content

Commit f20980f

Browse files
committed
feat (wrap ns components): Wrap a Vue component if no component is passed to the registerComponent function. Refactored Label component as it's the simpler case to refactor.
1 parent e450d2f commit f20980f

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

platform/nativescript/runtime/components/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { registerElement } from '../../element-registry'
1+
import { normalizeElementName, registerElement } from '../../element-registry'
22

33
import ActionBar from './action-bar'
44
import ActionItem from './action-item'
55
import android from './android'
66
import ios from './ios'
7-
import Label from './label'
87
import ListView from './list-view'
98
import NavigationButton from './navigation-button'
109
import TabView from './tab-view'
@@ -18,6 +17,18 @@ export function registerComponent(componentName, resolver, meta, component) {
1817
if (resolver) {
1918
registerElement(`Native${componentName}`, resolver, meta)
2019
}
20+
if (!component) {
21+
// if no Vue component is passed, wrap the simpler vue component
22+
// which bind the events and attributes to the NS one
23+
const tagName = 'native-' + normalizeElementName(componentName)
24+
component = {
25+
template: `
26+
<${tagName} ref="${componentName}" v-bind="$attrs" v-on="$listeners">
27+
<slot></slot>
28+
</${tagName}>
29+
`
30+
}
31+
}
2132
componentMap.set(componentName, component)
2233
}
2334

@@ -52,12 +63,7 @@ registerComponent('android', null, {}, android)
5263

5364
registerComponent('ios', null, {}, ios)
5465

55-
registerComponent(
56-
'Label',
57-
() => require('tns-core-modules/ui/label').Label,
58-
{},
59-
Label
60-
)
66+
registerComponent('Label', () => require('tns-core-modules/ui/label').Label, {})
6167

6268
registerComponent(
6369
'ListView',

platform/nativescript/runtime/components/label.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)