HarmonyOS 鸿蒙Next scroll嵌套list,list无法触发onReachEnd

HarmonyOS 鸿蒙Next scroll嵌套list,list无法触发onReachEnd

import { promptAction } from '@kit.ArkUI';

@Entry
@Component
struct RefreshPage {
  @State message: string = 'Hello World';

  build() {
    Column() {
      Scroll(){
        Column(){
          ForEach([1,1,1],()=>{
            Column(){
            }
            .backgroundColor(Color.Blue)
            .height(200)
            .width('100%')
            .margin({bottom:20})
          })
          List({space:20}){
            ForEach([1,1,1,1,1,1],()=>{
              ListItem(){
                Column(){

                }
                .backgroundColor(Color.Pink)
                .height(200)
                .width('100%')
              }
            })
          }
          .nestedScroll({
            scrollForward: NestedScrollMode.PARENT_FIRST,
            scrollBackward: NestedScrollMode.SELF_FIRST
          })
          .onReachEnd(()=>{
            console.log('触底')
            promptAction.showToast({message:'12c3'})
          })
        }

      }
      .layoutWeight(1)
    }
    .padding(20)
    .height('100%')
    .width('100%')
  }
}

更多关于HarmonyOS 鸿蒙Next scroll嵌套list,list无法触发onReachEnd的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复
给list加一个height('100%)

更多关于HarmonyOS 鸿蒙Next scroll嵌套list,list无法触发onReachEnd的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙系统中处理Next scroll嵌套list时,若list无法触发onReachEnd事件,通常是因为滚动事件被外层scroll组件拦截。以下是一些可能的解决方法:

  1. 检查事件传播:确保list组件的onReachEnd事件没有被外层scroll组件的触摸事件拦截。可以尝试调整事件监听器的优先级或设置事件冒泡属性。

  2. 调整滚动容器:检查scroll容器的滚动策略,确保内层list的滚动不受外层scroll影响。可以尝试调整scroll容器的scroll_direction属性,或设置list组件的is_nested_scrolling_enabled属性为true,以允许嵌套滚动。

  3. 动态加载数据:如果onReachEnd是为了实现数据的动态加载,确保数据加载逻辑正确,并且在事件触发时能够正确执行。

  4. 检查组件布局:确保list组件在布局中有足够的空间来触发onReachEnd事件。如果list组件被裁剪或隐藏,可能无法触发事件。

  5. 日志调试:通过日志输出检查onReachEnd事件是否被触发,以及触发时的上下文信息,有助于定位问题。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部