PowerScrollView

PowerScrollView 下拉刷新&加载更多的 ScrollView

代码示例

import { BfPowerScrollView } from '@bud-fe/react-taro-ui';
import { Text, View } from '@tarojs/components';
import { useEffect, useState } from 'react';
import './index.module.less';
const mockRequest = async (_startIndex, isRefresh, name) => {
const sleep = (t) =>
new Promise((resolve) => {
setTimeout(() => {
resolve();
}, t);
});
const TOTAL = 100;
let startIndex = _startIndex;
if (isRefresh) {
startIndex = 0;
}
if (startIndex >= TOTAL) {
return [];
}
console.log(`${name}:请求~`, 'isRefresh:', isRefresh);
await sleep(1200);
const list = [];
for (let i = 0; i < 20; i++) {
list.push(`${name}:`);
}
return list;
};
export default function () {
const [state, changeState] = useState({
basicsList: [],
basicsFinished: false,
});
const setState = (newState) => {
changeState({
...state,
...newState,
});
};
// 基础用法
const basicsDoRefresh = async (event = 0) => {
const append = await mockRequest(state.basicsList.length, true, '基础用法');
setState({
basicsList: append.map((item, index) => (
<View key={`${state.basicsList.length + index}append`} style={{ height: '40px', lineHeight: '40px' }}>
{item}
<Text>{`index:${state.basicsList.length + index + 1}`}</Text>
{/* <Tag type="success">{`index:${state.basicsList.length +
index +
1}`}</Tag> */}
</View>
)),
basicsFinished: append.length === 0,
});
};
const basicsLoadMore = async (event = 0, isRefresh = false) => {
let append = await mockRequest(state.basicsList.length, isRefresh, '基础用法');
append = append.map((item, index) => (
<View key={`${state.basicsList.length + index}append`} style={{ height: '40px', lineHeight: '40px' }}>
{item}
<Text>{`index:${state.basicsList.length + index + 1}`}</Text>
{/* <Tag type="success"></Tag> */}
</View>
));
setState({
basicsList: [...state.basicsList, ...append],
basicsFinished: append.length === 0,
});
};
useEffect(() => {
basicsLoadMore();
}, []);
return (
<>
<BfPowerScrollView
finishedText="没有更多了"
successText="刷新成功"
// refresherEnabled={false}
onScrollToUpper={basicsDoRefresh}
onScrollToLower={basicsLoadMore}
current={state.basicsList.length}
finished={state.basicsFinished}
header={<View style={{ lineHeight: '50px' }}>Head</View>}
footer={<View style={{ lineHeight: '50px' }}>Footer</View>}
lowerThreshold={300}
>
{state.basicsList.map((e, i) => (
<View key={i}>{e}</View>
))}
</BfPowerScrollView>
{/* */}
</>
);
}

API

属性名描述类型默认值
total列表总个数any--
children子元素any(必选)
current当前列表个数numberchildren.length
pageSize一页个数number20
minTriggerTopDistance最小触发下拉距离顶部距离number150
finished是否已加载完成,加载完成后不再触发 load 事件booleanfalse
errorText加载失败后的提示文案string--
loadingText加载过程提示文案string加载中...
finishedText加载完成后的提示文案string'没有更多了'
renderFinished自定义加载完成后的提示文案any--
renderLoading自定义底部加载中提示any--
renderError自定义加载失败后的提示文案any--
onScrollToUpper下拉刷新时触发(event: number | eventType) => Promise<void>--
onScrollToLower滚动条与底部距离小于 lowerThreshold 时触发(event: number | eventType) => Promise<void>--
header头部any--
footer尾部any--
id组件的唯一标示, 保持整个页面唯一string--
className同 `class`,在 React/Nerv 里一般使用 `className` 作为 `class` 的代称string--
style组件的内联样式, 可以动态设置的内联样式string | CSSProperties--
key如果列表中项目的位置会动态改变或者有新的项目添加到列表中, 需要使用 `wx:key` 来指定列表中项目的唯一的标识符。string | number--
hidden组件是否显示, 所有组件默认显示boolean--
animation动画属性{ actions: TaroGeneral.IAnyObject[]; }--
ref引用LegacyRef<any>--
dangerouslySetInnerHTML渲染 HTML @see /docs/html{ __html: string; }--
onTouchStart手指触摸动作开始(event: ITouchEvent) => void--
onTouchMove手指触摸后移动(event: ITouchEvent) => void--
onTouchCancel手指触摸动作被打断,如来电提醒,弹窗(event: ITouchEvent) => void--
onTouchEnd手指触摸动作结束(event: ITouchEvent) => void--
onClick手指触摸后马上离开(event: ITouchEvent) => void--
onLongPress手指触摸后,超过350ms再离开,如果指定了事件回调函数并触发了这个事件,tap事件将不被触发(event: CommonEvent<any>) => void--
onLongClick手指触摸后,超过350ms再离开(推荐使用 longpress 事件代替)(event: CommonEvent<any>) => void--
onTransitionEnd会在 WXSS transition 或 Taro.createAnimation 动画结束后触发(event: CommonEvent<any>) => void--
onAnimationStart会在一个 WXSS animation 动画开始时触发(event: CommonEvent<any>) => void--
onAnimationIteration会在一个 WXSS animation 一次迭代结束时触发(event: CommonEvent<any>) => void--
onAnimationEnd会在一个 WXSS animation 动画完成时触发(event: CommonEvent<any>) => void--
onTouchForceChange在支持 3D Touch 的 iPhone 设备,重按时会触发(event: CommonEvent<any>) => void--
headHeight顶部内容高度string | number--
successText刷新成功提示文案string--
pullingText下拉过程提示文案string'下拉即可刷新...'
loosingText释放过程提示文案string'释放即可刷新...'
pullDistance触发下拉刷新的距离string | number与 refresherThreshold || pullDistance 一致
successDuration刷新成功提示展示时长(ms)string | number500
animationDuration动画时长string | number300
renderHead自定义下拉刷新区域 {status: 下拉状态, distance: 当前下拉距离}(params: { status: PullRefreshStatus; distance: number; }) => any--
scrollX允许横向滚动 @supported weapp, swan, alipay, tt, h5, rn @rn 二选一booleanfalse
scrollY允许纵向滚动 @supported weapp, swan, alipay, tt, h5, rn @rn 二选一booleanfalse
upperThreshold距顶部/左边多远时(单位px),触发 scrolltoupper 事件 @supported weapp, swan, alipay, tt, h5, rnnumber50
lowerThreshold距底部/右边多远时(单位px),触发 scrolltolower 事件 @supported weapp, swan, alipay, tt, h5, rnnumber50
scrollTop设置竖向滚动条位置 @supported weapp, swan, alipay, tt, h5, rnnumber--
scrollLeft设置横向滚动条位置 @supported weapp, swan, alipay, tt, h5, rnnumber--
scrollIntoView值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素 @supported weapp, swan, alipay, tt, h5string--
scrollWithAnimation在设置滚动条位置时使用动画过渡 @supported weapp, swan, alipay, tt, h5, rnbooleanfalse
enableBackToTopiOS 点击顶部状态栏、安卓双击标题栏时,滚动条返回顶部,只支持竖向 @supported weapp, alipay, rnbooleanfalse
enableFlex启用 flexbox 布局。开启后,当前节点声明了 `display: flex` 就会成为 flex container,并作用于其孩子节点。 @supported weappbooleanfalse
scrollAnchoring开启 scroll anchoring 特性,即控制滚动位置不随内容变化而抖动,仅在 iOS 下生效,安卓下可参考 CSS `overflow-anchor` 属性。 @supported weappbooleanfalse
refresherEnabled开启自定义下拉刷新 @supported weappbooleanfalse
refresherThreshold设置自定义下拉刷新阈值 @supported weappnumber45
refresherDefaultStyle设置自定义下拉刷新默认样式,支持设置 `black | white | none`, none 表示不使用默认样式 @supported weappstring'black'
refresherBackground设置自定义下拉刷新区域背景颜色 @supported weappstring'#FFF'
refresherTriggered设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发 @supported weappbooleanfalse
enhanced启用 scroll-view 增强特性 @supported weappbooleanfalse
bouncesiOS 下 scroll-view 边界弹性控制 (同时开启 enhanced 属性后生效) @supported weappbooleantrue
showScrollbar滚动条显隐控制 (同时开启 enhanced 属性后生效) @supported weappbooleantrue
pagingEnabled分页滑动效果 (同时开启 enhanced 属性后生效) @supported weappbooleanfalse
fastDecelerationboolean false 滑动减速速率控制 (同时开启 enhanced 属性后生效) @supported weappbooleanfalse
onScroll滚动时触发 `event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}` @supported weapp, swan, alipay, tt, h5, rnBaseEventOrigFunction<onScrollDetail>--
onRefresherPulling自定义下拉刷新控件被下拉 @supported weappCommonEventFunction<any>--
onRefresherRefresh自定义下拉刷新被触发 @supported weappCommonEventFunction<any>--
onRefresherRestore自定义下拉刷新被复位 @supported weappCommonEventFunction<any>--
onRefresherAbort自定义下拉刷新被中止 @supported weappCommonEventFunction<any>--
onDragStart滑动开始事件 (同时开启 enhanced 属性后生效) @supported weappCommonEventFunction<any>--
onDragging滑动事件 (同时开启 enhanced 属性后生效) @supported weappCommonEventFunction<any>--
onDragEnd滑动结束事件 (同时开启 enhanced 属性后生效) @supported weappCommonEventFunction<any>--
dumi10:24