HarmonyOS 拖拽排序以及控件平移效果是否有工具类可以用,当前控件数据数量上限无法满足

拖拽排序以及控件平移效果是否有工具类可以用,当前控件数据数量上限无法满足

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

动画效果可以参考以下demo:

@Entry
@Component
struct AnimationPage {
  @Provide desX: number = 0;
  @Provide desY: number = 0;

  @Builder
  TabBar(index: number) {
    Column() {
      Image($r("app.media.icon"))
        .width(38)
        .height(38)
      Text(index == 1 ? "分类" : index.toString())
    }
    .onAreaChange((oldValue: Area, newValue: Area) => {
      if (index == 1) {
        console.log("onAreaChange========= newValue:" + JSON.stringify(newValue))
        this.desX = newValue.globalPosition.x as number
        this.desY = newValue.globalPosition.y as number
      }
    })
  }

  build() {
    Column() {
      Category()
      Column() {
        Image($r("app.media.icon"))
          .width(38)
          .height(38)
      }
      .onAreaChange((oldValue: Area, newValue: Area) => {
        console.log("onAreaChange========= newValue:" + JSON.stringify(newValue))
        this.desX = newValue.globalPosition.x as number
        this.desY = newValue.globalPosition.y as number
      })
    }
    .width("100%")
    .height("100%")
  }
}

@Component
struct Category {

  @State dataList:number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

  build() {
    Column() {
      Flex({direction:FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, wrap: FlexWrap.Wrap}) {
        ForEach(this.dataList, (item:number) => {
          ListItemComponent()
        })
      }
      .width('100%')
      .height('80%')
      .backgroundColor(Color.White)
    }
  }
}

@Observed
class AnimationBean {
  animationAppear: Boolean = false;
  id:number = -1;
}

@Component
struct ListItemComponent {
  @State animationList: AnimationBean[] = []
  static index: number = 0;
  @Consume desX: number;
  @Consume desY: number;

  @Provide orgX: number = 0;
  @Provide orgY: number = 0;


  @Builder
  BuildAnimationItem() {
    Image($r("app.media.app_icon"))
      .width(41)
      .height(41)
      .id("test")
      .onClick(() => {
        this.startAnimation();
      })
      .onAreaChange((oldValue:Area, newValue:Area) => {
        this.orgX = newValue.globalPosition.x as number
        this.orgY = newValue.globalPosition.y as number
        console.log("onAreaChage==========" + JSON.stringify(newValue))
      })
  }

  startAnimation() {
    const animation = new AnimationBean();
    animation.id = ListItemComponent.index++
    this.animationList.push(animation)
    animateTo({
      duration: 800,
      curve: Curve.FastOutLinearIn,
      onFinish: () => {
        animation.animationAppear = false;
        this.animationList = this.animationList.filter((item: AnimationBean) => {
          return item.animationAppear
        })
      }
    }, () => {
      animation.animationAppear = true;
    })
  }

  @Builder
  BuildItem() {
    Row() {
      Stack() {
        this.BuildAnimationItem()

        ForEach(this.animationList, (item: AnimationBean) => {
          AnimationChild({ item: item , AnimationView:this.BuildAnimationItem})
        }, (item: AnimationBean, index: number) => {
          return item.id.toLocaleString()
        })
      }
    }
    .width("20%")
    .height(60)
  }

  build() {
    this.BuildItem()
  }
}


@Component
struct AnimationChild {
  @ObjectLink item: AnimationBean;
  @Consume desX: number;
  @Consume desY: number;
  @Consume orgX: number;
  @Consume orgY: number;

  @BuilderParam
  AnimationView:() => void;

  build() {
    Row() {
      this.AnimationView()
    }
    .zIndex(5)
    .translate(this.item.animationAppear ? { x: (this.desX - this.orgX -20), y: (this.desY - this.orgY) } : { x: 0 })
  }
}
分享
微博
QQ
微信
回复
2天前
相关问题
请问鸿蒙可以用什么控件开发短视频
6835浏览 • 1回复 待解决
HarmonyOS 是否全局loading这种控件
391浏览 • 1回复 待解决
如何去掉Toggle一控件的点击效果
431浏览 • 1回复 待解决
HarmonyOS 如何实现抽屉效果控件
54浏览 • 1回复 待解决
「多态控件」的效果样式确认
1670浏览 • 1回复 待解决
Button等控件设置点击效果
1044浏览 • 1回复 待解决
HarmonyOS 如何实现图中的input控件效果
413浏览 • 1回复 待解决
HarmonyOS table表格控件
19浏览 • 1回复 待解决
HarmonyOS 安全控件无法在弹窗中使用
488浏览 • 1回复 待解决