HarmonyOS NEXT ListItem侧滑菜单动态设置?

阅读 496
1 个回答

参考demo:

@Entry 
@Component 
struct ListItemExample2 { 
  @State arr: number[] = [0, 1, 2, 3, 4] 
  @State enterEndDeleteAreaString: string = "not enterEndDeleteArea" 
  @State exitEndDeleteAreaString: string = "not exitEndDeleteArea" 
  @State isShow:boolean = true; 
 
  @Builder itemEnd() { 
    Row() { 
      Button("Delete").margin("4vp") 
      Button("Set").margin("4vp") 
    }.padding("4vp").justifyContent(FlexAlign.SpaceEvenly) 
  } 
 
  build() { 
    Column() { 
      Button("点击").onClick(()=>{ 
        this.isShow=!this.isShow 
        console.log(this.isShow+"111111111") 
      }) 
      List({ space: 10 }) { 
        ForEach(this.arr, (item: number) => { 
          ListItem() { 
            Text("item" + item) 
              .width('100%') 
              .height(100) 
              .fontSize(16) 
              .textAlign(TextAlign.Center) 
              .borderRadius(10) 
              .backgroundColor(0xFFFFFF) 
          } 
          .transition({ type: TransitionType.Delete, opacity: 0 }) 
          .swipeAction({ 
            end: this.isShow?{ 
              builder: () => { this.itemEnd() }, 
              onAction: () => { 
                animateTo({ duration: 1000 }, () => { 
                  let index = this.arr.indexOf(item) 
                  this.arr.splice(index, 1) 
                }) 
              }, 
              actionAreaDistance: 56, 
              onEnterActionArea: () => { 
                this.enterEndDeleteAreaString = "enterEndDeleteArea" 
                this.exitEndDeleteAreaString = "not exitEndDeleteArea" 
              }, 
              onExitActionArea: () => { 
                this.enterEndDeleteAreaString = "not enterEndDeleteArea" 
                this.exitEndDeleteAreaString = "exitEndDeleteArea" 
              } 
            }:undefined 
          }) 
        }, (item: string) => item) 
      } 
      Text(this.enterEndDeleteAreaString).fontSize(20) 
      Text(this.exitEndDeleteAreaString).fontSize(20) 
    } 
    .padding(10) 
    .backgroundColor(0xDCDCDC) 
    .width('100%') 
    .height('100%') 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题