Skip to content

Commit ecdcf12

Browse files
authored
fix(PullToRefresh): 修复PullToRefresh组件disabled属性在taro中无效的问题 (#2538)
1 parent c30e44a commit ecdcf12

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/packages/pulltorefresh/demo.taro.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,27 @@ import { useTranslate } from '@/sites/assets/locale/taro'
55
import Demo1 from './demos/taro/demo1'
66
import Demo2 from './demos/taro/demo2'
77
import Demo3 from './demos/taro/demo3'
8+
import Demo4 from './demos/taro/demo4'
89

910
const PullToRefreshDemo = () => {
1011
const [translated] = useTranslate({
1112
'zh-CN': {
1213
basic: '基础用法',
1314
scrollView: 'ScrollView',
1415
primary: '反白模式',
16+
disabled: '禁用',
1517
},
1618
'zh-TW': {
1719
basic: '基礎用法',
1820
scrollView: 'ScrollView',
1921
primary: '反白模式',
22+
disabled: '禁用',
2023
},
2124
'en-US': {
2225
basic: 'Basic Usage',
2326
scrollView: 'ScrollView',
2427
primary: 'reverse',
28+
disabled: 'disabled',
2529
},
2630
})
2731
return (
@@ -36,6 +40,9 @@ const PullToRefreshDemo = () => {
3640

3741
<h2>{translated.primary}</h2>
3842
<Demo3 />
43+
44+
<h2>{translated.disabled}</h2>
45+
<Demo4 />
3946
</div>
4047
</>
4148
)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { useState } from 'react'
2+
import { ScrollView } from '@tarojs/components'
3+
import { PullToRefresh, Cell, Toast } from '@nutui/nutui-react-taro'
4+
5+
const Demo4 = () => {
6+
const [list] = useState([1, 2, 3, 4, 5, 6, 7])
7+
const [show, SetShow] = useState(false)
8+
const [toastMsg, SetToastMsg] = useState('')
9+
const toastShow = (msg: any) => {
10+
SetToastMsg(msg)
11+
SetShow(true)
12+
}
13+
const [scrollTop, setScrollTop] = useState(0)
14+
return (
15+
<>
16+
<ScrollView
17+
style={{ height: '150px' }}
18+
scrollY
19+
onScrollEnd={(e) => {
20+
// scrollTop > 0, PullToRefresh 不触发 touchmove 事件。
21+
if (e.detail?.scrollTop) {
22+
setScrollTop(e.detail?.scrollTop)
23+
}
24+
}}
25+
>
26+
<PullToRefresh
27+
scrollTop={scrollTop}
28+
onRefresh={() =>
29+
new Promise((resolve) => {
30+
toastShow('😊')
31+
resolve('done')
32+
})
33+
}
34+
disabled
35+
>
36+
{list.map((item) => (
37+
<Cell key={item}>{item}</Cell>
38+
))}
39+
</PullToRefresh>
40+
</ScrollView>
41+
<Toast
42+
type="text"
43+
visible={show}
44+
content={toastMsg}
45+
onClose={() => {
46+
SetShow(false)
47+
}}
48+
/>
49+
</>
50+
)
51+
}
52+
53+
export default Demo4

src/packages/pulltorefresh/pulltorefresh.taro.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ export const PullToRefresh: FunctionComponent<Partial<PullToRefreshProps>> = (
9595
return ''
9696
}
9797
const handleTouchStart: any = (e: ITouchEvent) => {
98+
if (props.disabled) return
9899
touch.start(e as any)
99100
}
100101
const handleTouchMove: any = (e: ITouchEvent) => {
101-
if (props.scrollTop > 0) {
102+
if (props.scrollTop > 0 || props.disabled) {
102103
return
103104
}
104105
if (status === 'refreshing' || status === 'complete') return
@@ -139,6 +140,7 @@ export const PullToRefresh: FunctionComponent<Partial<PullToRefreshProps>> = (
139140
setStatus('pulling')
140141
}
141142
const handleTouchEnd: any = () => {
143+
if (props.disabled) return
142144
pullingRef.current = false
143145
if (status === 'canRelease') {
144146
doRefresh()

0 commit comments

Comments
 (0)