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,KAAK,CAAC,CAAC;iBACvC;aACJ;QACL,CAAC;QAED,WAAW,CAAC,KAAQ;YAChB,4BAA4B;YAC5B,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClC,CAAC;QACD,YAAY;QAEZ,wBAAwB;QACxB,WAAW;YACP,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;QAClC,CAAC;QAED,cAAc,CAAC,OAAO,GAAG,KAAK;YAC1B,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC9D,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;aAC7D;QACL,CAAC;QA+DD,gBAAgB,KAAK,CAAC;KACzB,CAAA;IA1GG;QADC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC;0DAC6B;IAEjD;QADC,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC;uDAC8B;IALpC,eAAe;QADpC,OAAO;OACc,eAAe,CA6GpC;IAAD,sBAAC;KAAA;AA7GqB,0CAAe","file":"","sourceRoot":"/","sourcesContent":["import { ListItemProps, ListViewProps, ListView } from \"../ListView\";\nimport { CCPureSubview, CCPureView } from \"../../../../common/classbase/CCViewBase\";\nimport { DummyLayout, DummyScrollView } from \"../../../../common/CCDummyObjects\";\nimport { shallowEqual, delay } from \"simba-utils\";\n\nconst { ccclass, property } = cc._decorator;\n\n@ccclass\nexport abstract class ListSubviewImpl<I extends ListItemProps, T extends ListViewProps<I>> extends CCPureSubview<T> implements ListView {\n //#region editor bindings\n @property(cc.Layout)\n protected contentLayout: cc.Layout = DummyLayout;\n @property(cc.ScrollView)\n protected scrollView: cc.ScrollView = DummyScrollView;\n //#endregion\n\n protected _refreshing = false;\n\n protected _itemViews: { [key: string]: CCPureView<I> & { index: number } } = {};\n\n private _viewCache: {[key: string] : CCPureView<I>[]} = {};\n\n protected abstract createListItemView(index: number): Promise<CCPureView<I>>;\n\n onLoad() {\n // console.log(\"ListViewImpl onLoad\", this.scrollView);\n }\n\n //#region base class overrides\n onPropsReceive() {\n (this._props as any).items = [...this._props.items];\n if (this._prevProps) {\n if (!shallowEqual(this._props.items, this._prevProps.items)) {\n this.refreshList(this._props.items);\n }\n }\n }\n\n onPropsLoad(props: T) {\n // super.onPropsLoad(props);\n this.refreshList(props.items);\n }\n //#endregion\n\n //#region interface impl\n scrollToTop() {\n this.scrollView.scrollToTop();\n }\n\n scrollToBottom(animate = false) {\n if (this.contentLayout.node.height > this.scrollView.node.height) {\n this.scrollView.scrollToBottom(animate ? 0.3 : undefined);\n }\n }\n //#endregion\n\n onItemClick = (key: string) => {\n return () => {\n if (this._props.onItemClick) {\n this._props.onItemClick(key);\n }\n }\n }\n\n refreshList = async (list: I[]) => {\n while (this._refreshing) {\n await delay(0.5);\n }\n this._refreshing = true;\n let allKeys = new Set(Object.keys(this._itemViews));\n for (let i = 0; i < list.length; i++) {\n let view = this._itemViews[list[i].key];\n allKeys.delete(list[i].key);\n if (!view) {\n view = await this.createItemView(list[i], i) as CCPureView<I> & {index: number};\n view.index = i;\n view.node.parent = this.contentLayout.node;\n view.node.setSiblingIndex(i);\n this._itemViews[list[i].key] = view;\n } else if (view.index !== i) {\n view.node.setSiblingIndex(i);\n view.index = i;\n }\n view.setProps({ ...list[i], onClick: this.onItemClick(list[i].key) });\n }\n for (let key of allKeys) {\n let view = this._itemViews[key];\n view.node.removeFromParent(false);\n delete this._itemViews[key];\n this.putItemView(view);\n }\n this._refreshing = false;\n this.onRefreshListEnd();\n }\n\n createItemView = async (item: I, i: number): Promise<CCPureView<I>> => {\n let key = item.itype + \"\";\n if (this._viewCache[key] && this._viewCache[key].length > 0) {\n let ret = this._viewCache[key].pop()!;\n (ret as any)._type = key;\n return ret;\n }\n let ret = this.createListItemView(i);\n (ret as any)._type = key;\n return ret;\n }\n\n putItemView = (view: CCPureView<I>) => {\n let key = (view as any)._type;\n let cacheArr = this._viewCache[key];\n if (!cacheArr) {\n this._viewCache[key] = cacheArr = [];\n }\n cacheArr.push(view);\n }\n\n onRefreshListEnd() { }\n}"]}