-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(List): support scroll API (#3286)
* feat(list): support virtual scroll * feat(list): support virtual scroll * chore: fix docs and demo * chore: fix lint * chore: fix lint * chore: fix test * chore: fix test * chore: fix test
- Loading branch information
Showing
16 changed files
with
1,447 additions
and
182 deletions.
There are no files selected for viewing
Submodule _common
updated
5 files
+19 −0 | docs/mobile/api/image-viewer.en-US.md | |
+6 −5 | docs/mobile/api/image-viewer.md | |
+26 −0 | docs/web/api/list.en-US.md | |
+30 −0 | docs/web/api/list.md | |
+1 −1 | style/mobile/components/_index.less |
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,13 @@ | ||
<template> | ||
<t-list style="height: 300px" :scroll="{ type: 'virtual' }" | ||
><t-list-item v-for="(item, index) in list" :key="index"> | ||
<t-list-item-meta :image="imageUrl" title="列表标题" :description="item.content" /></t-list-item | ||
></t-list> | ||
</template> | ||
<script setup> | ||
const list = []; | ||
const imageUrl = 'https://tdesign.gtimg.com/site/avatar.jpg'; | ||
for (let i = 0; i < 3000; i++) { | ||
list.push({ content: `第${i + 1}个列表内容的描述性文字` }); | ||
} | ||
</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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<t-list style="height: 300px" :scroll="{ type: 'virtual' }" | ||
><t-list-item v-for="(item, index) in list" :key="index"> | ||
<t-list-item-meta :image="imageUrl" title="列表标题" :description="item.content" /></t-list-item | ||
></t-list> | ||
</template> | ||
<script> | ||
const list = []; | ||
const imageUrl = 'https://tdesign.gtimg.com/site/avatar.jpg'; | ||
for (let i = 0; i < 3000; i++) { | ||
list.push({ content: `第${i + 1}个列表内容的描述性文字` }); | ||
} | ||
export default { | ||
data() { | ||
return { | ||
list, | ||
imageUrl, | ||
}; | ||
}, | ||
}; | ||
</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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { VNode } from 'vue'; | ||
import { computed, getCurrentInstance } from '@vue/composition-api'; | ||
|
||
const useListItems = () => { | ||
const instance = getCurrentInstance(); | ||
const currentSlots = instance.proxy.$slots.default || []; | ||
|
||
const listItems = computed(() => { | ||
const computedListItems: VNode[] = []; | ||
currentSlots.forEach((child) => { | ||
if (child.componentOptions?.tag === 't-list-item') { | ||
computedListItems.push({ | ||
class: child.data.staticClass, | ||
style: child.data.staticStyle, | ||
...child.componentOptions.propsData, | ||
slots: () => child.componentOptions.children, | ||
} as unknown as VNode); | ||
} | ||
}); | ||
return computedListItems; | ||
}); | ||
|
||
return { | ||
listItems, | ||
}; | ||
}; | ||
|
||
export default useListItems; |
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,57 @@ | ||
import { Ref, computed } from '@vue/composition-api'; | ||
import useVirtualScroll from '../../hooks/useVirtualScrollNew'; | ||
import { TdListProps } from '../type'; | ||
import { Styles } from '../../common'; | ||
|
||
const useListVirtualScroll = (scroll: TdListProps['scroll'], listRef: Ref<HTMLElement>, listItems: Ref<any[]>) => { | ||
const virtualScrollParams = computed(() => ({ | ||
data: listItems.value, | ||
scroll, | ||
})); | ||
const virtualConfig = useVirtualScroll(listRef, virtualScrollParams); | ||
const isVirtualScroll = computed(() => virtualConfig.isVirtualScroll.value); | ||
let lastScrollY = -1; | ||
|
||
const onInnerVirtualScroll = (e: WheelEvent) => { | ||
const target = (e.target || e.srcElement) as HTMLElement; | ||
const top = target.scrollTop; | ||
if (lastScrollY !== top) { | ||
virtualConfig.isVirtualScroll.value && virtualConfig.handleScroll(); | ||
} else { | ||
lastScrollY = -1; | ||
} | ||
lastScrollY = top; | ||
}; | ||
|
||
const cursorStyle = computed( | ||
() => ({ | ||
position: 'absolute', | ||
width: '1px', | ||
height: '1px', | ||
transition: 'transform 0.2s', | ||
transform: `translate(0, ${virtualConfig.scrollHeight.value}px)`, | ||
'-ms-transform': `translate(0, ${virtualConfig.scrollHeight.value}px)`, | ||
'-moz-transform': `translate(0, ${virtualConfig.scrollHeight.value}px)`, | ||
'-webkit-transform': `translate(0, ${virtualConfig.scrollHeight.value}px)`, | ||
} as Styles), | ||
); | ||
|
||
const listStyle = computed( | ||
() => ({ | ||
transform: `translate(0, ${virtualConfig.translateY.value}px)`, | ||
'-ms-transform': `translate(0, ${virtualConfig.translateY.value}px)`, | ||
'-moz-transform': `translate(0, ${virtualConfig.translateY.value}px)`, | ||
'-webkit-transform': `translate(0, ${virtualConfig.translateY.value}px)`, | ||
} as Styles), | ||
); | ||
|
||
return { | ||
virtualConfig, | ||
cursorStyle, | ||
listStyle, | ||
isVirtualScroll, | ||
onInnerVirtualScroll, | ||
}; | ||
}; | ||
|
||
export default useListVirtualScroll; |
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
Oops, something went wrong.