文档管理中心
我的
您当前正在浏览新版开发者文档中心,目录分类和层级有所调整。点击左侧当前文档分类名称前的“☰”图标,可切换文档分类。 了解新版目录
问题处理与运维开发与测试问题应用框架开发UI框架组件使用如何禁用Refresh组件的下拉刷新

如何禁用Refresh组件的下拉刷新

问题现象

在使用Refresh组件时,开发者需要控制Refresh组件的下拉刷新功能,实现临时禁用或者开启下拉刷新。

解决措施

可以通过pullDownRatio设置跟手系数,当设置为0时,表示不跟随手势下拉,即可禁用下拉刷新。

禁用Refresh组件下拉刷新的示例如下:

收起
自动换行
深色代码主题
复制
  1. @Entry
  2. @Component
  3. struct Index {
  4. @State isRefreshing: boolean = false;
  5. @State arr: String[] = ['0', '1', '2', '3', '4', '5'];
  6. @State downRatio: number = 1;
  7. build() {
  8. Column() {
  9. Refresh({ refreshing: $$this.isRefreshing }) {
  10. Column() {
  11. Row({ space: 10 }) {
  12. Button('不允许下拉刷新')
  13. .onClick(() => {
  14. this.downRatio = 0;
  15. })
  16. Button('允许下拉刷新')
  17. .onClick(() => {
  18. this.downRatio = 1;
  19. })
  20. }
  21. List() {
  22. ForEach(this.arr, (item: string) => {
  23. ListItem() {
  24. Text('' + item)
  25. .width('70%')
  26. .height(80)
  27. .fontSize(16)
  28. .margin(10)
  29. .textAlign(TextAlign.Center)
  30. .borderRadius(10)
  31. .backgroundColor(0xFFFFFF)
  32. }
  33. }, (item: string) => item)
  34. }
  35. .onScrollIndex((first: number) => {
  36. console.info(first.toString());
  37. })
  38. .width('100%')
  39. .height('100%')
  40. .alignListItem(ListItemAlign.Center)
  41. .scrollBar(BarState.Off)
  42. }
  43. }
  44. .onRefreshing(() => {
  45. setTimeout(() => {
  46. this.isRefreshing = false;
  47. }, 2000)
  48. console.info('onRefreshing test');
  49. })
  50. .pullDownRatio(this.downRatio)
  51. .backgroundColor(0x89CFF0)
  52. .refreshOffset(64)
  53. .pullToRefresh(true)
  54. }
  55. }
  56. }