Skip to content

Commit e681175

Browse files
authored
Merge pull request halfnelson#91 from halfnelson/feature/support-config-elements
Feature/support config elements
2 parents 7ffb970 + 151261e commit e681175

25 files changed

+754
-551
lines changed

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.6.0]
8+
9+
### Breaking Changes
10+
- Renamed NativeElementNode to NativeViewElementNode and added a parent class NativeElementNode which handles nativescript entities not derived from View
11+
- Removed "meta" legacy onInsert and Remove hook container
12+
13+
### Added
14+
- support for `prop:` directive to set the value of the containing node to the nativeView of the current node e.g `<gridLayout prop:mainContent>` for sideDrawer
15+
- Added a parameter to NativeElementNode that configures the prop: behaviour and defines the correct casing of any property
16+
- Added a parameter `setsParentProp` to NativeElementNode that specifies a property on the perent node to set to constructed element when inserted.
17+
- Added registerNativeViewElement and registerNativeConfigElement exports. These help change:
18+
```
19+
registerElement('myTag', () => new NativeViewElementNode('myTag', require('some-tns-plugin/mytag').MyTag))
20+
```
21+
into
22+
```
23+
registerNativeViewElement('myTag', () => require('some-tns-plugin/mytag').MyTag )
24+
```
25+
- Added `svelteNativeNoFrame` which allows you to launch your app without an implicit root frame. Great for when you are using RadSidebar
26+
27+
28+
### Changes
29+
- Refactored property name normalization to cache based on object prototype so we aren't walking all defined properties every time we get or set.
30+
- Use the new 'scoped styles' boolean parameter when calling addCss if we don't detect any :global() styles. This should improve perf.
31+
32+
733
## [0.5.3]
834
- Add support for itemTemplateSelector closes [#86](https://github.com/halfnelson/svelte-native/issues/86)
935

@@ -59,4 +85,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5985
- Introduced a Changelog
6086

6187
### Changed
62-
- Bumped versions to use freshly released Svelte 3.0.0
88+
- Bumped versions to use freshly released Svelte 3.0.0

demo/app/tests/components/Template.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Template } from "svelte-native/components"
22
import TemplateHarness from './TemplateHarness.svelte'
33
import { createElement, NativeElementNode } from "svelte-native/dom";
4+
import { Label } from "tns-core-modules/ui/label/label";
5+
import { NativeViewElementNode } from "svelte-native/dom";
46

57
describe('Template', function () {
68

@@ -49,7 +51,7 @@ describe('Template', function () {
4951
});
5052

5153
it('uses the provided props', function () {
52-
let el = mount_point.firstElement() as NativeElementNode;
54+
let el = mount_point.firstElement() as NativeViewElementNode<Label>;
5355
assert.equal(el.getAttribute('text'), 'test text prop_value')
5456
});
5557

@@ -60,8 +62,8 @@ describe('Template', function () {
6062
props: { item: "prop_value2" }
6163
})
6264

63-
let el1 = mount_point.firstElement() as NativeElementNode;
64-
let el2 = mount_point2.firstElement() as NativeElementNode;
65+
let el1 = mount_point.firstElement() as NativeViewElementNode<Label>;
66+
let el2 = mount_point2.firstElement() as NativeViewElementNode<Label>;
6567
assert.equal(el1.getAttribute('text'), 'test text prop_value')
6668
assert.equal(el2.getAttribute('text'), 'test text prop_value2')
6769
})

demo/app/tests/dom/ListViewNode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { createElement, NativeElementNode } from 'svelte-native/dom'
1+
import { createElement, NativeViewElementNode } from 'svelte-native/dom'
22
import { ListView } from 'tns-core-modules/ui/list-view'
33

44
import ListViewMultiTemplate from './ListViewMultiTemplate.svelte'
55

66
describe('ListViewNode', function () {
7-
let test_subject: NativeElementNode
7+
let test_subject: NativeViewElementNode<ListView>
88
before(async function () {
99
let el = createElement('fragment');
1010
let harness = new ListViewMultiTemplate({ target: el });
@@ -13,7 +13,7 @@ describe('ListViewNode', function () {
1313
})
1414

1515
it('detects keyed templates', async function () {
16-
let listview = test_subject.nativeView as ListView;
16+
let listview = test_subject.nativeView;
1717
assert.equal(listview.itemTemplates.length, 2, `expected 2 keyed item templates`)
1818
})
1919

demo/app/tests/dom/NativeElement.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { createElement, NativeElementNode } from 'svelte-native/dom'
1+
import { createElement, NativeElementNode, NativeViewElementNode } from 'svelte-native/dom'
22
import NativeElementHarness from './NativeElementHarness.svelte'
33
import MountParent from './MountParent.svelte'
44
import MountChild from './MountChild.svelte'
55
import { LayoutBase } from 'tns-core-modules/ui/layouts/layout-base'
66
import { Label } from 'tns-core-modules/ui/label'
7+
import { StackLayout } from 'tns-core-modules/ui/layouts/stack-layout'
78

89
describe('NativeElementNode', function () {
9-
let test_subject: NativeElementNode;
10+
let test_subject: NativeViewElementNode<Label>;
1011
before(async function () {
1112
let el = createElement('fragment');
1213
let harness = new NativeElementHarness({ target: el });
@@ -15,31 +16,31 @@ describe('NativeElementNode', function () {
1516
})
1617

1718
it('sets known properties onto its nativeView', function () {
18-
assert.equal((test_subject.nativeView as any).textWrap, true);
19+
assert.equal(test_subject.nativeElement.textWrap, true);
1920
})
2021

2122
it('sets text node children as text property of nativeView', function () {
22-
assert.equal((test_subject.nativeView as any).text, 'Text Content');
23+
assert.equal(test_subject.nativeElement.text, 'Text Content');
2324
})
2425

2526
it('sets class property on nativeView', function () {
26-
assert.isTrue((test_subject.nativeView as any).cssClasses.has("testlabel"));
27+
assert.isTrue(test_subject.nativeElement.cssClasses.has("testlabel"));
2728
})
2829

2930
it('supports class directive', function () {
30-
assert.isTrue((test_subject.nativeView as any).cssClasses.has('boolclass'));
31-
assert.isFalse((test_subject.nativeView as any).cssClasses.has('boolclassf'))
31+
assert.isTrue(test_subject.nativeElement.cssClasses.has('boolclass'));
32+
assert.isFalse(test_subject.nativeElement.cssClasses.has('boolclassf'))
3233
})
3334

3435

3536
it('sets style properties on native view', function () {
36-
assert.equal((test_subject.nativeView as any).style.color.name, 'red');
37-
assert.equal((test_subject.nativeView as any).color.name, 'red');
37+
assert.equal(test_subject.nativeElement.style.color.name, 'red');
38+
assert.equal(test_subject.nativeElement.color.name, 'red');
3839
})
3940
});
4041

4142
describe('NativeElementNode mounting', function () {
42-
let mount_parent: { $destroy: any, stack: NativeElementNode, first: NativeElementNode, last: NativeElementNode } = null;
43+
let mount_parent: { $destroy: any, stack: NativeViewElementNode<StackLayout>, first: NativeViewElementNode<Label>, last: NativeViewElementNode<Label> } = null;
4344
beforeEach(async function () {
4445
let el = createElement('fragment');
4546
let harness = new MountParent({ target: el });
@@ -58,13 +59,13 @@ describe('NativeElementNode mounting', function () {
5859
}
5960

6061
it('can mount child element at the end', function () {
61-
let mount_child: { $destroy: any, childA: NativeElementNode, childB: NativeElementNode } = new MountChild({ target: mount_parent.stack }) as any;
62+
let mount_child: { $destroy: any, childA: NativeViewElementNode<Label>, childB: NativeViewElementNode<Label> } = new MountChild({ target: mount_parent.stack }) as any;
6263
try {
63-
assertChildrenMatch(mount_parent.stack.nativeView as LayoutBase, [
64-
mount_parent.first.nativeView as Label,
65-
mount_parent.last.nativeView as Label,
66-
mount_child.childA.nativeView as Label,
67-
mount_child.childB.nativeView as Label
64+
assertChildrenMatch(mount_parent.stack.nativeView, [
65+
mount_parent.first.nativeView,
66+
mount_parent.last.nativeView,
67+
mount_child.childA.nativeView,
68+
mount_child.childB.nativeView
6869
])
6970
} finally {
7071
mount_child.$destroy()
@@ -73,13 +74,13 @@ describe('NativeElementNode mounting', function () {
7374
})
7475

7576
it('can mount child element before an anchor', function () {
76-
let mount_child: { $destroy: any, childA: NativeElementNode, childB: NativeElementNode } = new MountChild({ target: mount_parent.stack, anchor: mount_parent.last }) as any;
77+
let mount_child: { $destroy: any, childA: NativeViewElementNode<Label>, childB: NativeViewElementNode<Label> } = new MountChild({ target: mount_parent.stack, anchor: mount_parent.last }) as any;
7778
try {
78-
assertChildrenMatch(mount_parent.stack.nativeView as LayoutBase, [
79-
mount_parent.first.nativeView as Label,
80-
mount_child.childA.nativeView as Label,
81-
mount_child.childB.nativeView as Label,
82-
mount_parent.last.nativeView as Label,
79+
assertChildrenMatch(mount_parent.stack.nativeView, [
80+
mount_parent.first.nativeView,
81+
mount_child.childA.nativeView,
82+
mount_child.childB.nativeView,
83+
mount_parent.last.nativeView,
8384
])
8485
} finally {
8586
mount_child.$destroy()
@@ -88,13 +89,13 @@ describe('NativeElementNode mounting', function () {
8889
})
8990

9091
it('can mount child element at the start', function () {
91-
let mount_child: { $destroy: any, childA: NativeElementNode, childB: NativeElementNode } = new MountChild({ target: mount_parent.stack, anchor: mount_parent.first }) as any;
92+
let mount_child: { $destroy: any, childA: NativeViewElementNode<Label>, childB: NativeViewElementNode<Label> } = new MountChild({ target: mount_parent.stack, anchor: mount_parent.first }) as any;
9293
try {
93-
assertChildrenMatch(mount_parent.stack.nativeView as LayoutBase, [
94-
mount_child.childA.nativeView as Label,
95-
mount_child.childB.nativeView as Label,
96-
mount_parent.first.nativeView as Label,
97-
mount_parent.last.nativeView as Label,
94+
assertChildrenMatch(mount_parent.stack.nativeView, [
95+
mount_child.childA.nativeView,
96+
mount_child.childB.nativeView,
97+
mount_parent.first.nativeView,
98+
mount_parent.last.nativeView,
9899
])
99100
} finally {
100101
mount_child.$destroy()

demo/app/tests/dom/PropDirective.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { createElement, NativeViewElementNode } from 'svelte-native/dom'
2+
import PropDirectiveHarness from './PropDirectiveHarness.svelte'
3+
import { Label } from 'tns-core-modules/ui/label/label';
4+
import { StackLayout } from 'tns-core-modules/ui/layouts/stack-layout/stack-layout';
5+
6+
describe('PropDirective', function () {
7+
let test_subject: NativeViewElementNode<StackLayout>
8+
let harness;
9+
before(async function () {
10+
let el = createElement('fragment');
11+
harness = new PropDirectiveHarness({ target: el });
12+
test_subject = (harness as any).test_subject
13+
assert.isNotNull(test_subject)
14+
})
15+
16+
it('sets a property on its parent element', async function () {
17+
assert.isNotNull(test_subject.getAttribute('testproperty'))
18+
})
19+
20+
it('the property set is an nativeelement', async function () {
21+
assert.instanceOf(test_subject.getAttribute('testproperty'), Label);
22+
})
23+
24+
it('is not added to the native parent view', async function () {
25+
assert.equal(test_subject.nativeView.getChildrenCount(), 0);
26+
})
27+
28+
29+
it('sets a property to null when removed', async function () {
30+
harness.enabled = false;
31+
assert.isNull(test_subject.getAttribute('testproperty'))
32+
})
33+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<svelte:options accessors={true}/>
2+
3+
<stackLayout bind:this={test_subject}>
4+
{#if enabled}
5+
<label prop:testproperty text="test label"/>
6+
{/if}
7+
</stackLayout>
8+
9+
<script>
10+
export let test_subject;
11+
export let enabled = true;
12+
</script>

demo/app/tests/dom/Tabs.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { createElement, TabsElement, TabStripElement } from 'svelte-native/dom'
1+
import { createElement, TabsElement, NativeViewElementNode } from 'svelte-native/dom'
22
import { tick } from 'svelte';
33
import TabsHarness from './TabsHarness.svelte'
4+
import { TabStrip } from 'tns-core-modules/ui/tab-navigation-base/tab-strip'
45

56

67
describe('Tabs', function () {
@@ -41,7 +42,7 @@ describe('Tabs', function () {
4142
});
4243

4344
describe('TabStrip', function () {
44-
let test_subject: TabStripElement;
45+
let test_subject: NativeViewElementNode<TabStrip>;
4546
let harness: TabsHarness;
4647
before(async function () {
4748
let el = createElement('fragment');

demo/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"emitDecoratorMetadata": true,
77
"noEmitHelpers": true,
88
"noEmitOnError": true,
9+
"skipLibCheck": true,
910
"lib": [
10-
"es6",
11-
"dom"
11+
"es6"
1212
],
1313
"baseUrl": ".",
1414
"paths": {

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte-native",
3-
"version": "0.5.3",
3+
"version": "0.6.0",
44
"description": "Svelte integration for NativeScript",
55
"private": true,
66
"repository": {
@@ -21,7 +21,7 @@
2121
"author": "David Pershouse",
2222
"license": "MIT",
2323
"peerDependencies": {
24-
"tns-core-modules": "^6.1.1",
24+
"tns-core-modules": "^6.1.2",
2525
"svelte": "^3.12.1"
2626
},
2727
"devDependencies": {
@@ -31,7 +31,7 @@
3131
"rollup-plugin-svelte": "^5.1.0",
3232
"rollup-plugin-typescript2": "^0.24.0",
3333
"svelte": "^3.12.1",
34-
"tns-core-modules": "^6.1.1",
34+
"tns-core-modules": "^6.1.2",
3535
"typescript": "^3.5.3",
3636
"rimraf": "^2.6.3"
3737
}

0 commit comments

Comments
 (0)