11import { CollectionView as NSCollectionView } from '..' ;
22import { ItemEventData , Observable , ObservableArray } from '@nativescript/core' ;
3- import { PropType , VNode , computed , defineComponent , getCurrentInstance , h , ref , toRaw , warn , watch } from 'nativescript-vue' ;
3+ import { ELEMENT_REF , NSVElement , NSVRoot , PropType , VNode , computed , defineComponent , getCurrentInstance , h , ref , render , toRaw , warn , watch } from 'nativescript-vue' ;
44
55interface ListItem {
66 [ key : string ] : any ;
@@ -15,6 +15,7 @@ interface ItemCellData {
1515}
1616
1717const LIST_CELL_ID = Symbol ( 'list_cell_id' ) ;
18+ const LIST_CELL_CONTAINER = Symbol ( 'list_cell_container' ) ;
1819
1920function getItemCtx ( item : any , index : number , itemAlias : string , indexAlias : string ) : ListItem {
2021 return {
@@ -78,26 +79,35 @@ export const CollectionView = defineComponent({
7879 // const itemCtx: ListItem = getItemCtx(props.items instanceof ObservableArray ? props.items.getItem(index) : props.items[index], index, props.alias, props.itemIdGenerator);
7980
8081 // update the cell data with the current row
82+ const slotName = getSlotName ( itemCtx , index , event . object . items ) ;
8183 cells . value [ id ] = {
8284 itemCtx,
83- slotName : getSlotName ( itemCtx , index , event . object . items )
85+ slotName
8486 } ;
8587
8688 // trigger an update!
87- vm ?. update ( ) ;
89+ // vm?.update();
8890
8991 // find the vnode rendering this cell
90- const vnode = ( vm ?. subTree . children as VNode [ ] ) . find ( ( vnode ) => vnode . key === id ) ;
91- const cellEl = toRaw ( vnode ?. el ?. nativeView ) ;
92- cellEl [ LIST_CELL_ID ] = id ;
92+ const container = event . view ?. [ LIST_CELL_CONTAINER ] ?? new NSVRoot ( ) ;
93+ const vnode = ctx . slots [ slotName ] ?.( itemCtx ) [ 0 ] ;
9394
9495 if ( event . view ) {
9596 event . view . _batchUpdate ( ( ) => {
96- event . view = cellEl ;
97+ // todo: handle the case where the slot is not found
98+ render ( vnode ! , container ) ;
9799 } ) ;
98100 } else {
99- event . view = cellEl ;
101+ // todo: handle the case where the slot is not found
102+ render ( vnode ! , container ) ;
100103 }
104+
105+
106+ const cellEl = toRaw ( vnode ?. el ?. nativeView ) ;
107+ cellEl [ LIST_CELL_ID ] = id ;
108+ cellEl [ LIST_CELL_CONTAINER ] = container ;
109+ event . view = cellEl ;
110+
101111 }
102112
103113 // render all realized templates as children
@@ -129,8 +139,6 @@ export const CollectionView = defineComponent({
129139 items : props . items ,
130140 itemTemplates,
131141 onItemLoading
132- } ,
133- cellVNODES ( )
134- ) ;
142+ } ) ;
135143 }
136144} ) ;
0 commit comments