Skip to content
This repository has been archived by the owner on Dec 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #50 from b2nil/dev
Browse files Browse the repository at this point in the history
1024 Specials
  • Loading branch information
b2nil authored Oct 24, 2020
2 parents eb553c9 + 1da1722 commit 4b563e3
Show file tree
Hide file tree
Showing 6 changed files with 339 additions and 171 deletions.
4 changes: 2 additions & 2 deletions src/components/divider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ const AtDivider = defineComponent({
default: '',
},
height: {
type: Number as PropType<AtDividerProps['height']>,
type: [Number, String] as PropType<AtDividerProps['height']>,
default: 0,
},
fontColor: {
type: String as PropType<AtDividerProps['fontColor']>,
default: '',
},
fontSize: {
type: Number as PropType<AtDividerProps['fontSize']>,
type: [Number, String] as PropType<AtDividerProps['fontSize']>,
default: 0,
},
lineColor: {
Expand Down
56 changes: 40 additions & 16 deletions src/components/virtual-scroll/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,26 @@ const AtVirtualScroll = defineComponent({

watch(() => props.height, updateFirstAndLast)
watch(() => props.itemHeight, updateFirstAndLast)
watch(() => props.scrollIntoItem, (index, prevIndex) => {
const parsedIndex = parseInt(`${index}`, 10)
if (parsedIndex >= 0 && parsedIndex < props.items.length) {
watch(() => props.scrollIntoItem, (itemIndex, prevItemIndex) => {
let parsedIndex = parseInt(`${itemIndex || 0}`, 10)

// make sure index is within length of items
parsedIndex = Math.min(props.items.length - 1, Math.max(0, parsedIndex))

scrollTop.value = parsedIndex * __itemHeight.value
updateFirstAndLast()
})

onMounted(() => {
if (Boolean(props.scrollIntoItem)) {
let parsedIndex = parseInt(`${props.scrollIntoItem || 0}`, 10)
scrollTop.value = parsedIndex * __itemHeight.value
updateFirstAndLast()
} else {
warn(`index should not exceed the length of items: ${index}`)
last.value = getLast(0)
}
})

onMounted(() => {
last.value = getLast(0)
})

function getChildren() {
return props.items.slice(
firstToRender.value,
Expand Down Expand Up @@ -163,14 +169,23 @@ const AtVirtualScroll = defineComponent({
}

return () => {
const content = h(View, {
class: 'at-virtual-scroll__container',
style: {
height: convertToUnit((props.items.length * __itemHeight.value)),
}
}, { default: () => getChildren() })

return h(ScrollView, mergeProps(
const content = h(View, null, {
default: () => [
h(View, {
class: 'at-virtual-scroll__container',
style: {
height: convertToUnit((props.items.length * __itemHeight.value)),
}
}, { default: () => getChildren() }),

h(View, {
class: 'at-virtual-scroll__footer'
}, { default: () => slots.footer && slots.footer() }),
]
})


const scrollViewNode = h(ScrollView, mergeProps(
isWeb.value
? {
scrollTop: scrollTop.value
Expand All @@ -190,6 +205,15 @@ const AtVirtualScroll = defineComponent({
onScrollToUpper: props.onReachTop,
onScrollToLower: props.onReachBottom,
}), { default: () => [content] })

return h(View, null, {
default: () => [
h(View, {
class: 'at-virtual-scroll__header',
}, { default: () => slots.header && slots.header() }),
scrollViewNode,
]
})
}
}
})
Expand Down
5 changes: 5 additions & 0 deletions src/pages/advanced/virtual-scroll/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
margin-bottom: 12px;
color: #333;
font-size: 24px;
}

.at-switch__title {
font-size: 24px;
color: red;
}
Loading

0 comments on commit 4b563e3

Please sign in to comment.