mirror of
https://github.com/568071718/creator-collection-view
synced 2025-12-10 22:58:50 +00:00
添加一些演示场景
This commit is contained in:
@@ -6,17 +6,12 @@ const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('home')
|
||||
export class home extends Component {
|
||||
|
||||
protected start(): void {
|
||||
this.setup_list1()
|
||||
this.setup_list2()
|
||||
this.setup_list3()
|
||||
}
|
||||
const listComp = this.node.getChildByName('list').getComponent(YXCollectionView)
|
||||
|
||||
setup_list1() {
|
||||
const listComp = this.node.getChildByName('list1').getComponent(YXCollectionView)
|
||||
|
||||
listComp.numberOfItems = () => 10000
|
||||
listComp.numberOfItems = () => {
|
||||
return 10000
|
||||
}
|
||||
listComp.cellForItemAt = (indexPath, collectionView) => {
|
||||
const cell = collectionView.dequeueReusableCell(`cell`)
|
||||
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
|
||||
@@ -30,89 +25,5 @@ export class home extends Component {
|
||||
|
||||
listComp.reloadData()
|
||||
}
|
||||
|
||||
setup_list2() {
|
||||
const listComp = this.node.getChildByName('list2').getComponent(YXCollectionView)
|
||||
|
||||
listComp.numberOfSections = () => 100
|
||||
listComp.supplementaryForItemAt = (indexPath, collectionView, kinds) => {
|
||||
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
|
||||
const supplementary = collectionView.dequeueReusableSupplementary('supplementary')
|
||||
supplementary.getChildByName('label').getComponent(Label).string = `header ${indexPath}`
|
||||
const shape = supplementary.getChildByName('shape')
|
||||
shape.getComponent(Sprite).color = new math.Color(100, 100, 150)
|
||||
return supplementary
|
||||
}
|
||||
if (kinds === YXTableLayout.SupplementaryKinds.FOOTER) {
|
||||
const supplementary = collectionView.dequeueReusableSupplementary('supplementary')
|
||||
supplementary.getChildByName('label').getComponent(Label).string = `footer ${indexPath}`
|
||||
const shape = supplementary.getChildByName('shape')
|
||||
shape.getComponent(Sprite).color = new math.Color(150, 100, 100)
|
||||
return supplementary
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
listComp.numberOfItems = () => 20
|
||||
listComp.cellForItemAt = (indexPath, collectionView) => {
|
||||
const cell = collectionView.dequeueReusableCell(`cell`)
|
||||
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
|
||||
return cell
|
||||
}
|
||||
|
||||
let layout = new YXTableLayout()
|
||||
layout.spacing = 20
|
||||
layout.top = 20
|
||||
layout.bottom = 20
|
||||
layout.rowHeight = 100
|
||||
layout.sectionHeaderHeight = 120
|
||||
layout.sectionFooterHeight = 120
|
||||
listComp.layout = layout
|
||||
|
||||
listComp.reloadData()
|
||||
}
|
||||
|
||||
setup_list3() {
|
||||
const listComp = this.node.getChildByName('list3').getComponent(YXCollectionView)
|
||||
|
||||
listComp.numberOfSections = () => 100
|
||||
listComp.supplementaryForItemAt = (indexPath, collectionView, kinds) => {
|
||||
if (kinds === YXTableLayout.SupplementaryKinds.HEADER) {
|
||||
const supplementary = collectionView.dequeueReusableSupplementary('supplementary')
|
||||
supplementary.getChildByName('label').getComponent(Label).string = `header ${indexPath}`
|
||||
const shape = supplementary.getChildByName('shape')
|
||||
shape.getComponent(Sprite).color = new math.Color(100, 100, 150)
|
||||
return supplementary
|
||||
}
|
||||
if (kinds === YXTableLayout.SupplementaryKinds.FOOTER) {
|
||||
const supplementary = collectionView.dequeueReusableSupplementary('supplementary')
|
||||
supplementary.getChildByName('label').getComponent(Label).string = `footer ${indexPath}`
|
||||
const shape = supplementary.getChildByName('shape')
|
||||
shape.getComponent(Sprite).color = new math.Color(150, 100, 100)
|
||||
return supplementary
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
listComp.numberOfItems = () => 20
|
||||
listComp.cellForItemAt = (indexPath, collectionView) => {
|
||||
const cell = collectionView.dequeueReusableCell(`cell`)
|
||||
cell.getChildByName('label').getComponent(Label).string = `${indexPath}`
|
||||
return cell
|
||||
}
|
||||
|
||||
let layout = new YXTableLayout()
|
||||
layout.spacing = 20
|
||||
layout.top = 20
|
||||
layout.bottom = 20
|
||||
layout.rowHeight = 100
|
||||
layout.sectionHeaderHeight = 120
|
||||
layout.sectionFooterHeight = 120
|
||||
layout.sectionHeadersPinToVisibleBounds = true
|
||||
layout.sectionFootersPinToVisibleBounds = true
|
||||
listComp.layout = layout
|
||||
|
||||
listComp.reloadData()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user