index.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {ScrollView, Text} from '@tarojs/components';
  2. import {useListEvent, useRefreshState, useScrollControl} from './hooks';
  3. import {Empty} from '@components';
  4. import classNames from 'classnames';
  5. const Refresh = function ({
  6. isRefreshing,
  7. onRefresh,
  8. onLoading,
  9. isLoading,
  10. children,
  11. style,
  12. className,
  13. background,
  14. refreshStyle,
  15. noMore,
  16. empty,
  17. emptyMsg,
  18. emptyClassName,
  19. emptyChildren,
  20. endClassName,
  21. }) {
  22. const [topRef, onScroll] = useScrollControl();
  23. const refreshState = useRefreshState(topRef, isRefreshing);
  24. const {onListRefresh, onListLoading} = useListEvent({
  25. isLoading,
  26. isRefreshing: refreshState,
  27. onRefresh,
  28. onLoading,
  29. noMore,
  30. });
  31. return (
  32. <ScrollView
  33. scrollY
  34. style={style}
  35. className={className}
  36. refresherEnabled
  37. refresherTriggered={refreshState}
  38. onRefresherRefresh={onListRefresh}
  39. onScrollToLower={onListLoading}
  40. refresherBackground={background ?? '#fff'}
  41. scrollTop={topRef.current}
  42. onScroll={onScroll}
  43. refresherDefaultStyle={refreshStyle}
  44. >
  45. {empty ? (
  46. <Empty msg={emptyMsg} className={emptyClassName}>
  47. {emptyChildren}
  48. </Empty>
  49. ) : (
  50. children
  51. )}
  52. <Text
  53. className={classNames('hidden text-sm text-center py-4 text-dark-3', {
  54. '!block': isLoading,
  55. })}
  56. >
  57. 正在加载中
  58. </Text>
  59. <Text
  60. className={classNames(
  61. 'hidden text-sm text-center py-4 text-dark-3',
  62. endClassName,
  63. {
  64. '!block': noMore && !isRefreshing && !isLoading && !empty,
  65. },
  66. )}
  67. >
  68. 已经到底了~~
  69. </Text>
  70. </ScrollView>
  71. );
  72. };
  73. export default Refresh;