Skip to content

Commit

Permalink
fix: 修复powerscrollview内只有一个元素的时候展示empty的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
三少 committed Sep 9, 2022
1 parent bd7982a commit a394213
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/vantui-doc/src/power-scroll-view/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ onLoad() {
| animationDuration | 动画时长 | _number \| string_ | `300` |
| headHeight | 顶部内容高度 | _number \| string_ | `50` |
| minTriggerTopDistance | 最小触发下拉距离顶部距离 | _number \| string_ | `150` |
| pullDistance `v3.0.8` | 触发下拉刷新的距离 | _number \| string_ |`headHeight` 一致 |
| pullDistance | 触发下拉刷新的距离 | _number \| string_ |`headHeight` 一致 |
| finished | 是否已加载完成,加载完成后不再触发 load 事件 | _boolean_ | `false` |
| finishedText | 加载完成后的提示文案 | _string_ | - |
| errorText | 加载失败后的提示文案 | _string_ | - |
Expand Down
15 changes: 10 additions & 5 deletions packages/vantui/src/power-scroll-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ export function PowerScrollView<T extends number | undefined>(
const startTop = useRef(0)

const [finished, setFinished] = useState<boolean>(_finished || false)
const currentCount = current ?? Array.from(children as any).length
const count = Array.isArray(children as any)
? Array.from(children as any).length
: toString.call(children) === '[object Object]'
? 1
: 0
const currentCount = current ?? count
const listCount = useRef(0)
useEffect(() => {
const { pageSize } = paginationRef.current
Expand Down Expand Up @@ -283,14 +288,14 @@ export function PowerScrollView<T extends number | undefined>(
[touch],
)

const isStartRef = useRef(false);
const isStartRef = useRef(false)

const onTouchStart = useCallback(
async (event: ITouchEvent) => {
if (isTouchable()) {
isStartRef.current = false;
isStartRef.current = false
const data = await getScrollTop()
isStartRef.current = true;
isStartRef.current = true
startTop.current = data
checkPosition(event)
}
Expand All @@ -303,7 +308,7 @@ export function PowerScrollView<T extends number | undefined>(
(event: ITouchEvent): void => {
if (isTouchable() && startTop.current < minTriggerTopDistance) {
if (!isStartRef.current) {
return;
return
}
const { deltaY } = touch
touch.move(event)
Expand Down

0 comments on commit a394213

Please sign in to comment.