Skip to content

Commit 46b4fb6

Browse files
feat(PullDownRefresh): support disabled prop (#631)
* feat(PullDownRefresh): support disabled prop * fix(PullDownRefresh): fix cr * chore: update snapshot --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 0f1189e commit 46b4fb6

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

src/pull-down-refresh/PullDownRefresh.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { StyledProps } from '../common';
99
import useDefault from '../_util/useDefault';
1010
import type { TdPullDownRefreshProps } from './type';
1111
import { pullDownRefreshDefaultProps } from './defaultProps';
12-
12+
import { useLocaleReceiver } from '../locale/LocalReceiver';
1313
import { usePrefixClass } from '../hooks/useClass';
1414
import useDefaultProps from '../hooks/useDefaultProps';
1515
import { convertUnit, reconvertUnit } from '../_util/convertUnit';
@@ -48,6 +48,7 @@ const PullDownRefresh: React.FC<PullDownRefreshProps> = (originProps) => {
4848
className,
4949
style,
5050
children,
51+
disabled,
5152
loadingTexts,
5253
loadingProps,
5354
loadingBarHeight,
@@ -65,6 +66,8 @@ const PullDownRefresh: React.FC<PullDownRefreshProps> = (originProps) => {
6566
const [value, onChange] = useDefault(propsValue, defaultValue, propsOnChange);
6667

6768
const name = usePrefixClass('pull-down-refresh');
69+
const [locale, t] = useLocaleReceiver('pullDownRefresh');
70+
6871
const touch = useTouch();
6972
const loadingHeight = convertUnit(loadingBarHeight);
7073
const pureLoadingHeight = reconvertUnit(loadingBarHeight);
@@ -112,6 +115,7 @@ const PullDownRefresh: React.FC<PullDownRefreshProps> = (originProps) => {
112115
}, [run]);
113116

114117
const doRefresh = async () => {
118+
if (disabled) return;
115119
setStatus(PullStatusEnum.loading);
116120
setDistance(pureLoadingHeight);
117121
try {
@@ -138,7 +142,7 @@ const PullDownRefresh: React.FC<PullDownRefreshProps> = (originProps) => {
138142
}
139143
};
140144

141-
const statusText = getStatusText(status, loadingTexts);
145+
const statusText = getStatusText(status, loadingTexts.length ? loadingTexts : t(locale.loadingTexts));
142146
let statusNode: ReactNode = <div className={`${name}__text`}>{statusText}</div>;
143147
if (status === PullStatusEnum.loading) {
144148
statusNode = <Loading text={statusText} size="24px" {...loadingProps} />;
@@ -151,7 +155,7 @@ const PullDownRefresh: React.FC<PullDownRefreshProps> = (originProps) => {
151155

152156
const onTouchStart = (e: React.TouchEvent) => {
153157
e.stopPropagation();
154-
if (!isReachTop(e) || loading) return;
158+
if (!isReachTop(e) || loading || disabled) return;
155159

156160
setDistance(0);
157161
touch.start(e);
@@ -160,7 +164,7 @@ const PullDownRefresh: React.FC<PullDownRefreshProps> = (originProps) => {
160164

161165
const onTouchMove = (e: React.TouchEvent) => {
162166
e.stopPropagation();
163-
if (!isReachTop(e) || loading) return;
167+
if (!isReachTop(e) || loading || disabled) return;
164168
touch.move(e);
165169

166170
const { diffY, diffX } = touch;
@@ -190,7 +194,7 @@ const PullDownRefresh: React.FC<PullDownRefreshProps> = (originProps) => {
190194

191195
const onTouchEnd = (e: React.TouchEvent) => {
192196
e.stopPropagation();
193-
if (!isReachTop(e) || loading) return;
197+
if (!isReachTop(e) || loading || disabled) return;
194198

195199
if (status === PullStatusEnum.loosing) {
196200
doRefresh();

src/pull-down-refresh/defaultProps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import { TdPullDownRefreshProps } from './type';
66

77
export const pullDownRefreshDefaultProps: TdPullDownRefreshProps = {
8+
disabled: false,
89
loadingBarHeight: 50,
9-
loadingTexts: ['下拉刷新', '松手刷新', '正在刷新', '刷新完成'],
10+
loadingTexts: [],
1011
maxBarHeight: 80,
1112
refreshTimeout: 3000,
1213
defaultValue: false,

src/pull-down-refresh/pull-down-refresh.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## API
44

5-
65
### PullDownRefresh Props
76

87
name | type | default | description | required
98
-- | -- | -- | -- | --
109
className | String | - | className of component | N
1110
style | Object | - | CSS(Cascading Style Sheets),Typescript:`React.CSSProperties` | N
11+
disabled | Boolean | false | disabled pull down refresh | N
1212
loadingBarHeight | String / Number | 50 | \- | N
1313
loadingProps | Object | - | Typescript:`LoadingProps`[Loading API Documents](./loading?tab=api)[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/tree/develop/src/pull-down-refresh/type.ts) | N
1414
loadingTexts | Array | [] | Typescript:`string[]` | N

src/pull-down-refresh/pull-down-refresh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-- | -- | -- | -- | --
99
className | String | - | 类名 | N
1010
style | Object | - | 样式,TS 类型:`React.CSSProperties` | N
11+
disabled | Boolean | false | 是否禁用下拉刷新 | N
1112
loadingBarHeight | String / Number | 50 | 加载中下拉高度,如果值为数字则单位是:'px' | N
1213
loadingProps | Object | - | 加载loading样式。TS 类型:`LoadingProps`[Loading API Documents](./loading?tab=api)[详细类型定义](https://github.com/Tencent/tdesign-mobile-react/tree/develop/src/pull-down-refresh/type.ts) | N
1314
loadingTexts | Array | [] | 提示语,组件内部默认值为 ['下拉刷新', '松手刷新', '正在刷新', '刷新完成']。TS 类型:`string[]` | N

src/pull-down-refresh/type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import { LoadingProps } from '../loading';
88

99
export interface TdPullDownRefreshProps {
10+
/**
11+
* 是否禁用下拉刷新
12+
* @default false
13+
*/
14+
disabled?: boolean;
1015
/**
1116
* 加载中下拉高度,如果值为数字则单位是:'px'
1217
* @default 50

test/snap/__snapshots__/csr.test.jsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61272,7 +61272,7 @@ exports[`csr snapshot test > csr test src/list/_example/pull-refresh.tsx 1`] = `
6127261272
<div
6127361273
class="t-pull-down-refresh__text"
6127461274
>
61275-
刷新完成
61275+
Refresh completed
6127661276
</div>
6127761277
</div>
6127861278
</div>
@@ -69360,7 +69360,7 @@ exports[`csr snapshot test > csr test src/pull-down-refresh/_example/timeout.tsx
6936069360
<div
6936169361
class="t-pull-down-refresh__text"
6936269362
>
69363-
刷新完成
69363+
Refresh completed
6936469364
</div>
6936569365
</div>
6936669366
</div>
@@ -69399,7 +69399,7 @@ exports[`csr snapshot test > csr test src/pull-down-refresh/_example/top.tsx 1`]
6939969399
<div
6940069400
class="t-pull-down-refresh__text"
6940169401
>
69402-
刷新完成
69402+
Refresh completed
6940369403
</div>
6940469404
</div>
6940569405
</div>

0 commit comments

Comments
 (0)