-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ListView): initial LV implementation
A first pass of implementing a ListView, with vue slots.
- Loading branch information
Showing
5 changed files
with
133 additions
and
8 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,46 @@ | ||
import { ListView } from 'nativescript-vue' | ||
|
||
export default { | ||
components: { | ||
ListView, | ||
}, | ||
template: ` | ||
<ListView :items="items" _tap="items.push('Item ' + (items.length + 1))"> | ||
<template v-slot:default="{item, index, even, odd}"> | ||
<Label textWrap="true"> | ||
Item: {{ item }} | ||
Index: {{ index }} | ||
Even: {{ even }} | ||
Odd: {{ odd }} | ||
</Label> | ||
</template> | ||
<!--<template v-slot:other="{item}">--> | ||
<!-- <Label >{{ item }}Other</Label>--> | ||
<!--</template>--> | ||
</ListView>`, | ||
data() { | ||
return { | ||
items: [ | ||
'Item 1', | ||
'Item 2', | ||
'Item 3', | ||
'Item 4', | ||
'Item 5', | ||
'Item 6', | ||
'Item 7', | ||
'Item 8', | ||
'Item 9', | ||
'Item 10', | ||
'Item 11', | ||
'Item 12', | ||
'Item 13', | ||
'Item 14', | ||
'Item 15', | ||
'Item 16', | ||
'Item 17', | ||
'Item 18', | ||
'Item 19', | ||
], | ||
} | ||
}, | ||
} |
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,72 @@ | ||
import { FunctionalComponent, h } from '@vue/runtime-core' | ||
import { nodeOps, NSVRoot, render } from '@nativescript-vue/runtime' | ||
import { ItemEventData } from '@nativescript/core/ui/list-view' | ||
import { debug } from '@nativescript-vue/shared' | ||
|
||
type ListViewProps = { | ||
items: Array<string> | ||
} | ||
const NSV_LVR_REF = Symbol('NSV_LVR_REF') | ||
const isListViewThingSymbol = Symbol() | ||
|
||
interface ListViewRealized { | ||
[isListViewThingSymbol]: true | ||
container: NSVRoot | null | ||
} | ||
|
||
export const ListView: FunctionalComponent<ListViewProps> = (props, ctx) => { | ||
const defaultKeyedTemplate = { | ||
key: 'test', | ||
createView(): ListViewRealized { | ||
// debug('createView for test template') | ||
return { | ||
[isListViewThingSymbol]: true, | ||
container: null, | ||
} | ||
}, | ||
} | ||
|
||
return h('InternalListView', { | ||
items: props.items, | ||
itemTemplates: [defaultKeyedTemplate], | ||
itemTemplateSelector: (item: any, index: any) => { | ||
// debug('itemTemplateSelector', item, index) | ||
return 'test' | ||
}, | ||
|
||
onitemLoading(args: ItemEventData) { | ||
// debug('item loading', args.view) | ||
|
||
const item = props.items[args.index] | ||
|
||
const getSlotVnode = (slotName: string) => | ||
ctx.slots[slotName]!({ | ||
item, | ||
index: args.index, | ||
even: !!(args.index % 2), | ||
odd: !(args.index % 2), | ||
})[0] | ||
let view | ||
if ((args.view as any)[isListViewThingSymbol]) { | ||
debug('INITIAL LVR CREATING' + args.index, 'ListView') | ||
// it is an initial render into this view holder | ||
const lvr = (args.view as unknown) as ListViewRealized | ||
// lets create an initial root | ||
lvr.container = nodeOps.createRoot() | ||
render(getSlotVnode('default'), lvr.container) | ||
|
||
if (lvr.container.el) { | ||
lvr.container.el.nativeView[NSV_LVR_REF] = lvr | ||
view = lvr.container.el.nativeView | ||
} | ||
} else { | ||
debug('LVR UPDATING' + args.index, 'ListView') | ||
const lvr = (args.view as any)[NSV_LVR_REF] as ListViewRealized | ||
render(getSlotVnode('default'), lvr.container!) | ||
view = lvr.container!.el!.nativeView | ||
} | ||
|
||
args.view = view | ||
}, | ||
}) | ||
} |
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