bug fix and performance improvements

This commit is contained in:
quantulr
2023-08-18 17:32:18 +08:00
parent 3c6ab550cf
commit e750b9be9c
923 changed files with 46650 additions and 9 deletions

View File

@ -0,0 +1,36 @@
:: BASE_DOC ::
## API
### PullDownRefresh Props
name | type | default | description | required
-- | -- | -- | -- | --
enable-back-to-top | Boolean | true | `1.1.5` | N
enable-passive | Boolean | false | `1.1.5` | N
external-classes | Array | - | `['t-class', 't-class-loading','t-class-text', 't-class-indicator']` | N
loading-bar-height | String / Number | 50 | \- | N
loading-props | Object | - | Typescript`LoadingProps`[Loading API Documents](./loading?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/pull-down-refresh/type.ts) | N
loading-texts | Array | [] | Typescript`string[]` | N
lower-threshold | String / Number | 50 | `1.1.5` | N
max-bar-height | String / Number | 80 | \- | N
refresh-timeout | Number | 3000 | \- | N
scroll-into-view | String | - | `1.1.5` | N
show-scrollbar | Boolean | true | \- | N
upper-threshold | String / Number | 50 | `1.1.5` | N
value | Boolean | false | \- | N
default-value | Boolean | undefined | uncontrolled property | N
### PullDownRefresh Events
name | params | description
-- | -- | --
change | `(value: boolean)` | \-
refresh | \- | \-
timeout | \- | \-
### CSS Variables
The component provides the following CSS variables, which can be used to customize styles.
Name | Default Value | Description
-- | -- | --
--td-pull-down-refresh-color | @font-gray-3 | -

View File

@ -0,0 +1,70 @@
---
title: PullDownRefresh 下拉刷新
description: 用于快速刷新页面信息,刷新可以是整页刷新也可以是页面的局部刷新。
spline: message
isComponent: true
---
<span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20lines-96%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20functions-81%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20statements-94%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20branches-81%25-blue" /></span>
## 引入
全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。
```json
"usingComponents": {
"t-pull-down-refresh": "tdesign-miniprogram/pull-down-refresh/pull-down-refresh"
}
```
## 代码演示
### 顶部下拉刷新
由于组件内无法监听页面滚动,需要由页面获取组件实例,并将页面滚动事件传递到组件。
{{ base }}
> 在使用 pull-down-refresh 组件的页面,建议开启 `disableScroll: true`
## API
### PullDownRefresh Props
名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
enable-back-to-top | Boolean | true | `1.1.5`。iOS点击顶部状态栏、安卓双击标题栏时滚动条返回顶部只支持竖向。自 2.27.3 版本开始,若非显式设置为 false则在显示尺寸大于屏幕 90% 时自动开启 | N
enable-passive | Boolean | false | `1.1.5`。开启 passive 特性,能优化一定的滚动性能 | N
loading-bar-height | String / Number | 50 | 加载中下拉高度,如果值为数字则单位是:'px' | N
loading-props | Object | - | 加载loading样式。TS 类型:`LoadingProps`[Loading API Documents](./loading?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/pull-down-refresh/type.ts) | N
loading-texts | Array | [] | 提示语,组件内部默认值为 ['下拉刷新', '松手刷新', '正在刷新', '刷新完成']。TS 类型:`string[]` | N
lower-threshold | String / Number | 50 | `1.1.5`。距底部/右边多远时,触发 scrolltolower 事件 | N
max-bar-height | String / Number | 80 | 最大下拉高度,如果值为数字则单位是:'px' | N
refresh-timeout | Number | 3000 | 刷新超时时间 | N
scroll-into-view | String | - | `1.1.5`。值应为某子元素idid不能以数字开头。设置哪个方向可滚动则在哪个方向滚动到该元素 | N
show-scrollbar | Boolean | true | 滚动条显隐控制 (同时开启 enhanced 属性后生效) | N
upper-threshold | String / Number | 50 | `1.1.5`。距顶部/左边多远时,触发 scrolltoupper 事件 | N
value | Boolean | false | 组件状态,值为 `true` 表示下拉状态,值为 `false` 表示收起状态 | N
default-value | Boolean | undefined | 组件状态,值为 `true` 表示下拉状态,值为 `false` 表示收起状态。非受控属性 | N
### PullDownRefresh Events
名称 | 参数 | 描述
-- | -- | --
change | `(value: boolean)` | 下拉或收起时触发,用户手势往下滑动触发下拉状态,手势松开触发收起状态
refresh | \- | 结束下拉时触发
timeout | \- | 刷新超时触发
### PullDownRefresh 外部样式类
类名 | 说明
-- | --
t-class | 根节点样式类
t-class-loading | 加载样式类
t-class-text | 文本样式类
t-class-indicator | 指示样式类
### CSS 变量
组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--td-pull-down-refresh-color | @font-gray-3 | -

View File

@ -0,0 +1,3 @@
import { TdPullDownRefreshProps } from './type';
declare const props: TdPullDownRefreshProps;
export default props;

View File

@ -0,0 +1,57 @@
const props = {
enableBackToTop: {
type: Boolean,
value: true,
},
enablePassive: {
type: Boolean,
value: false,
},
externalClasses: {
type: Array,
},
loadingBarHeight: {
type: null,
value: 50,
},
loadingProps: {
type: Object,
},
loadingTexts: {
type: Array,
value: [],
},
lowerThreshold: {
type: null,
value: 50,
},
maxBarHeight: {
type: null,
value: 80,
},
refreshTimeout: {
type: Number,
value: 3000,
},
scrollIntoView: {
type: String,
value: '',
},
showScrollbar: {
type: Boolean,
value: true,
},
upperThreshold: {
type: null,
value: 50,
},
value: {
type: Boolean,
value: null,
},
defaultValue: {
type: Boolean,
value: false,
},
};
export default props;

View File

@ -0,0 +1,46 @@
import { SuperComponent, RelationsOptions } from '../common/src/index';
export default class PullDownRefresh extends SuperComponent {
pixelRatio: number;
startPoint: {
pageX: number;
pageY: number;
} | null;
isPulling: boolean;
loadingBarHeight: number;
maxRefreshAnimateTimeFlag: number;
closingAnimateTimeFlag: number;
externalClasses: string[];
options: {
multipleSlots: boolean;
};
relations: RelationsOptions;
properties: import("./type").TdPullDownRefreshProps;
data: {
prefix: string;
classPrefix: string;
barHeight: number;
refreshStatus: number;
loosing: boolean;
enableToRefresh: boolean;
scrollTop: number;
};
lifetimes: {
attached(): void;
detached(): void;
};
observers: {
value(val: any): void;
};
methods: {
onScrollToBottom(): void;
onScrollToTop(): void;
onScroll(e: any): void;
onTouchStart(e: WechatMiniprogram.Component.TrivialInstance): void;
onTouchMove(e: WechatMiniprogram.Component.TrivialInstance): void;
onTouchEnd(e: WechatMiniprogram.Component.TrivialInstance): void;
doRefresh(): void;
setRefreshBarHeight(value: number): Promise<unknown>;
setScrollTop(scrollTop: number): void;
scrollToTop(): void;
};
}

View File

@ -0,0 +1,185 @@
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import props from './props';
import { unitConvert } from '../common/utils';
const { prefix } = config;
const name = `${prefix}-pull-down-refresh`;
let PullDownRefresh = class PullDownRefresh extends SuperComponent {
constructor() {
super(...arguments);
this.pixelRatio = 1;
this.startPoint = null;
this.isPulling = false;
this.loadingBarHeight = 100;
this.maxRefreshAnimateTimeFlag = 0;
this.closingAnimateTimeFlag = 0;
this.externalClasses = [`${prefix}-class`, `${prefix}-class-loading`, `${prefix}-class-text`, `${prefix}-class-indicator`];
this.options = {
multipleSlots: true,
};
this.relations = {
'../back-top/back-top': {
type: 'descendant',
},
};
this.properties = props;
this.data = {
prefix,
classPrefix: name,
barHeight: 0,
refreshStatus: -1,
loosing: false,
enableToRefresh: true,
scrollTop: 0,
};
this.lifetimes = {
attached() {
const { screenWidth } = wx.getSystemInfoSync();
const { loadingBarHeight, loadingTexts } = this.properties;
this.setData({
loadingTexts: Array.isArray(loadingTexts) && loadingTexts.length >= 4
? loadingTexts
: ['下拉刷新', '松手刷新', '正在刷新', '刷新完成'],
});
this.pixelRatio = 750 / screenWidth;
Object.defineProperty(this, 'maxBarHeight', {
get() {
return unitConvert(this.data.maxBarHeight);
},
});
Object.defineProperty(this, 'loadingBarHeight', {
get() {
return unitConvert(this.data.loadingBarHeight);
},
});
if (loadingBarHeight) {
this.setData({
computedLoadingBarHeight: unitConvert(loadingBarHeight),
});
}
},
detached() {
clearTimeout(this.maxRefreshAnimateTimeFlag);
clearTimeout(this.closingAnimateTimeFlag);
},
};
this.observers = {
value(val) {
if (!val) {
clearTimeout(this.maxRefreshAnimateTimeFlag);
if (this.data.refreshStatus > 0) {
this.setData({
refreshStatus: 3,
});
}
this.setData({ barHeight: 0 });
}
else {
this.doRefresh();
}
},
};
this.methods = {
onScrollToBottom() {
this.triggerEvent('scrolltolower');
},
onScrollToTop() {
this.setData({
enableToRefresh: true,
});
},
onScroll(e) {
const { scrollTop } = e.detail;
this.setData({
enableToRefresh: scrollTop === 0,
});
this.triggerEvent('scroll', { scrollTop });
},
onTouchStart(e) {
if (this.isPulling || !this.data.enableToRefresh)
return;
const { touches } = e;
if (touches.length !== 1)
return;
const { pageX, pageY } = touches[0];
this.setData({ loosing: false });
this.startPoint = { pageX, pageY };
this.isPulling = true;
},
onTouchMove(e) {
if (!this.startPoint)
return;
const { touches } = e;
if (touches.length !== 1)
return;
const { pageY } = touches[0];
const offset = pageY - this.startPoint.pageY;
if (offset > 0) {
this.setRefreshBarHeight(offset);
}
},
onTouchEnd(e) {
if (!this.startPoint)
return;
const { changedTouches } = e;
if (changedTouches.length !== 1)
return;
const { pageY } = changedTouches[0];
const barHeight = pageY - this.startPoint.pageY;
this.startPoint = null;
this.isPulling = false;
this.setData({ loosing: true });
if (barHeight > this.loadingBarHeight) {
this._trigger('change', { value: true });
this.triggerEvent('refresh');
}
else {
this.setData({ barHeight: 0 });
}
},
doRefresh() {
this.setData({
barHeight: this.loadingBarHeight,
refreshStatus: 2,
loosing: true,
});
this.maxRefreshAnimateTimeFlag = setTimeout(() => {
this.maxRefreshAnimateTimeFlag = null;
if (this.data.refreshStatus === 2) {
this.triggerEvent('timeout');
this._trigger('change', { value: false });
}
}, this.properties.refreshTimeout);
},
setRefreshBarHeight(value) {
const barHeight = Math.min(value, this.maxBarHeight);
const data = { barHeight };
if (barHeight >= this.loadingBarHeight) {
data.refreshStatus = 1;
}
else {
data.refreshStatus = 0;
}
return new Promise((resolve) => {
this.setData(data, () => resolve(barHeight));
});
},
setScrollTop(scrollTop) {
this.setData({ scrollTop });
},
scrollToTop() {
this.setScrollTop(0);
},
};
}
};
PullDownRefresh = __decorate([
wxComponent()
], PullDownRefresh);
export default PullDownRefresh;

View File

@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"t-loading": "../loading/loading"
}
}

View File

@ -0,0 +1,50 @@
<wxs src="../common/utils.wxs" module="_" />
<scroll-view
style="{{_._style([style, customStyle])}}"
class="{{classPrefix}} class {{prefix}}-class"
scroll-top="{{scrollTop}}"
scroll-y
enable-back-to-top="{{enableBackToTop}}"
enable-passive="{{enablePassive}}"
lower-threshold="{{lowerThreshold}}"
upper-threshold="{{upperThreshold}}"
scroll-into-view="{{scrollIntoView}}"
show-scrollbar="{{showScrollbar}}"
enhanced
scroll-with-animation
bounces="{{false}}"
bind:touchstart="onTouchStart"
bind:touchmove="onTouchMove"
bind:touchend="onTouchEnd"
bind:scroll="onScroll"
bindscrolltoupper="onScrollToTop"
bindscrolltolower="onScrollToBottom"
>
<view
class="{{classPrefix}}__track {{classPrefix + '__track--' + (loosing ? 'loosing' : '')}}"
style="{{barHeight > 0 ? 'transform: translate3d(0, ' + barHeight + 'px, 0);' : ''}}"
>
<view class="{{classPrefix}}__tips" style="height: {{computedLoadingBarHeight}}px" aria-live="polite">
<t-loading
wx:if="{{refreshStatus === 2}}"
delay="{{loadingProps.delay || 0}}"
duration="{{loadingProps.duration || 800}}"
indicator="{{loadingProps.indicator || true}}"
layout="{{loadingProps.layout || 'horizontal'}}"
loading="{{loadingProps.loading || true}}"
pause="{{loadingProps.pause || false}}"
progress="{{loadingProps.progress || 0}}"
reverse="{{loadingProps.reverse || false}}"
size="{{loadingProps.size || '50rpx'}}"
text="{{loadingProps.text || loadingTexts[refreshStatus]}}"
theme="{{loadingProps.theme || 'circular'}}"
t-class-indicator="{{prefix}}-class-indicator"
/>
<view wx:elif="{{refreshStatus >= 0}}" class="{{classPrefix}}__text {{prefix}}-class-text"
>{{loadingTexts[refreshStatus]}}</view
>
</view>
<slot />
</view>
</scroll-view>

View File

@ -0,0 +1,57 @@
.t-float-left {
float: left;
}
.t-float-right {
float: right;
}
@keyframes tdesign-fade-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
.hotspot-expanded.relative {
position: relative;
}
.hotspot-expanded::after {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
transform: scale(1.5);
}
.t-pull-down-refresh {
overflow: hidden;
max-height: 100vh;
height: 100%;
}
.t-pull-down-refresh__track {
position: relative;
}
.t-pull-down-refresh__track--loosing {
transition: transform ease 0.24s;
}
.t-pull-down-refresh__tips {
position: absolute;
color: var(--td-pull-down-refresh-color, var(--td-font-gray-3, rgba(0, 0, 0, 0.4)));
font-size: 24rpx;
top: 0;
width: 100%;
transform: translateY(-100%);
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
overflow: hidden;
}
.t-pull-down-refresh__text {
margin: 16rpx 0 0;
}
.t-pull-down-refresh__wrap {
position: relative;
}

View File

@ -0,0 +1,59 @@
import { LoadingProps } from '../loading/index';
export interface TdPullDownRefreshProps {
enableBackToTop?: {
type: BooleanConstructor;
value?: boolean;
};
enablePassive?: {
type: BooleanConstructor;
value?: boolean;
};
externalClasses?: {
type: ArrayConstructor;
value?: ['t-class', 't-class-loading', 't-class-text', 't-class-indicator'];
};
loadingBarHeight?: {
type: null;
value?: string | number;
};
loadingProps?: {
type: ObjectConstructor;
value?: LoadingProps;
};
loadingTexts?: {
type: ArrayConstructor;
value?: string[];
};
lowerThreshold?: {
type: null;
value?: string | number;
};
maxBarHeight?: {
type: null;
value?: string | number;
};
refreshTimeout?: {
type: NumberConstructor;
value?: number;
};
scrollIntoView?: {
type: StringConstructor;
value?: string;
};
showScrollbar?: {
type: BooleanConstructor;
value?: boolean;
};
upperThreshold?: {
type: null;
value?: string | number;
};
value?: {
type: BooleanConstructor;
value?: boolean;
};
defaultValue?: {
type: BooleanConstructor;
value?: boolean;
};
}

View File

@ -0,0 +1 @@
export {};