-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Template component and tag along with ListViewElement
Rearrang dom folders, they were getting messy
- Loading branch information
1 parent
b2974b7
commit b854acd
Showing
18 changed files
with
170 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<svelte:options bind:props={props} /> | ||
<template {...props} component="{template}" xmlns="tns" /> | ||
<AsComponent bind:component="{template}" let:item> | ||
<slot item="{item}" /> | ||
</AsComponent> | ||
|
||
<script> | ||
import { AsComponent } from "./AsComponent" | ||
let template; | ||
let props; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { AsComponent } from "./AsComponent"; | ||
|
||
export { default as Template } from "./Template.svelte"; | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { ListView, ItemEventData, ItemsSource } from 'tns-core-modules/ui/list-view' | ||
import NativeElementNode from "./NativeElementNode"; | ||
import TemplateElement from '../svelte/TemplateElement'; | ||
import { createElement } from '../basicdom'; | ||
|
||
|
||
export default class ListViewElement extends NativeElementNode { | ||
constructor() { | ||
super('listview', ListView, null); | ||
|
||
this.nativeView.on(ListView.itemLoadingEvent, (args) => { this.updateListItem(args as ItemEventData) }); | ||
} | ||
|
||
updateListItem(args: ItemEventData) { | ||
let item; | ||
let listView = this.nativeView; | ||
let items = listView.items; | ||
|
||
if (args.index >= items.length) { | ||
console.log("Got request for item at index that didn't exists", items, args.index) | ||
return; | ||
} | ||
|
||
if ((items as ItemsSource).getItem) { | ||
item = (items as ItemsSource).getItem(args.index); | ||
} else { | ||
item = (items as any)[args.index] | ||
} | ||
|
||
if (!args.view || !(args.view as any).__SvelteComponent__) { | ||
console.log("creating view for ", args.index, item.name) | ||
let wrapper = createElement('StackLayout') as NativeElementNode; | ||
let componentInstance = new (this.itemTemplateComponent)({ | ||
target: wrapper, | ||
props: { | ||
item | ||
} | ||
}); | ||
|
||
let nativeEl = wrapper.nativeView; | ||
(nativeEl as any).__SvelteComponent__ = componentInstance; | ||
args.view = nativeEl; | ||
} else { | ||
let componentInstance: SvelteComponent = (args.view as any).__SvelteComponent__ | ||
console.log("updating view for ", args.index, item.name, args.view) | ||
componentInstance.$set({ item }) | ||
} | ||
} | ||
|
||
get itemTemplateComponent(): typeof SvelteComponent { | ||
const templateNode = this.childNodes.find(x => x instanceof TemplateElement) as TemplateElement | ||
return templateNode ? templateNode.component : null; | ||
} | ||
|
||
get nativeView(): ListView { | ||
return super.nativeView as ListView | ||
} | ||
|
||
set nativeView(view: ListView) { | ||
super.nativeView = view | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
src/dom/NativeElementNode.ts → src/dom/native/NativeElementNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.