Skip to content

Commit 7ea6306

Browse files
committed
chore: save
1 parent 2cde759 commit 7ea6306

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

src/packages/infiniteloading/infiniteloading.taro.tsx

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useConfig } from '@/packages/configprovider/configprovider.taro'
1212

1313
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
1414
import { InfiniteLoadingType } from './types'
15+
import pxTransform from '@/utils/px-transform'
1516

1617
export interface InfiniteLoadingProps
1718
extends BasicComponent,
@@ -72,15 +73,16 @@ export const InfiniteLoading: FunctionComponent<
7273
const y = useRef(0)
7374
const refreshMaxH = useRef(0)
7475
const distance = useRef(0)
75-
76+
const classPrefix = 'nut-infinite'
7677
const classes = classNames(classPrefix, className, `${classPrefix}-${type}`)
7778

7879
useEffect(() => {
7980
refreshMaxH.current = threshold
80-
setTimeout(() => {
81+
const timer = setTimeout(() => {
8182
getScrollHeight()
8283
}, 200)
83-
}, [hasMore, isInfiniting])
84+
return () => clearTimeout(timer)
85+
}, [hasMore, isInfiniting, threshold])
8486

8587
/** 获取需要滚动的距离 */
8688
const getScrollHeight = () => {
@@ -94,7 +96,7 @@ export const InfiniteLoading: FunctionComponent<
9496

9597
const getStyle = () => {
9698
return {
97-
height: topDisScoll < 0 ? px : `${topDisScoll}px`,
99+
height: topDisScoll < 0 ? pxTransform(0) : pxTransform(topDisScoll),
98100
transition: `height 0.2s cubic-bezier(0.25,0.1,0.25,1)`,
99101
}
100102
}
@@ -164,7 +166,15 @@ export const InfiniteLoading: FunctionComponent<
164166
refreshDone()
165167
}
166168
}
167-
169+
function getBottomTipsText() {
170+
if (isInfiniting) {
171+
return loadingText || locale.infiniteloading.loadText
172+
}
173+
if (!hasMore) {
174+
return loadMoreText || locale.infiniteloading.loadMoreText
175+
}
176+
return null
177+
}
168178
return (
169179
<ScrollView
170180
{...rest}
@@ -179,24 +189,20 @@ export const InfiniteLoading: FunctionComponent<
179189
onTouchMove={touchMove}
180190
onTouchEnd={touchEnd}
181191
>
182-
<View className="nut-infinite-top" ref={refreshTop} style={getStyle()}>
183-
<View className="nut-infinite-top-tips">
192+
<View
193+
className={`${classPrefix}-top`}
194+
ref={refreshTop}
195+
style={getStyle()}
196+
>
197+
<View className={`${classPrefix}-top-tips`}>
184198
{pullingText || locale.infiniteloading.pullRefreshText}
185199
</View>
186200
</View>
187-
<View className="nut-infinite-container">{children}</View>
188-
<View className="nut-infinite-bottom">
189-
{isInfiniting ? (
190-
<View className="nut-infinite-bottom-tips">
191-
{loadingText || locale.infiniteloading.loadText}
192-
</View>
193-
) : (
194-
!hasMore && (
195-
<View className="nut-infinite-bottom-tips">
196-
{loadMoreText || locale.infiniteloading.loadMoreText}
197-
</View>
198-
)
199-
)}
201+
<View className={`${classPrefix}-container`}>{children}</View>
202+
<View className={`${classPrefix}-bottom`}>
203+
<View className={`${classPrefix}-bottom-tips`}>
204+
{getBottomTipsText()}
205+
</View>
200206
</View>
201207
</ScrollView>
202208
)

0 commit comments

Comments
 (0)