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

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

HarmonyOS
2024-12-20 16:38:28
964浏览
收藏 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 })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
分享
微博
QQ
微信
回复
2024-12-20 18:06:10


相关问题
请问鸿蒙可以用什么控件开发短视频
7611浏览 • 1回复 待解决
HarmonyOS 是否自带吸顶效果的UI控件
588浏览 • 1回复 待解决
HarmonyOS是否刻度控件
651浏览 • 1回复 待解决
如何去掉Toggle一控件的点击效果
1002浏览 • 1回复 待解决
HarmonyOS 是否封装的数据工具
1037浏览 • 1回复 待解决
HarmonyOS 是否全局loading这种控件
1450浏览 • 1回复 待解决
HarmonyOS 如何实现抽屉效果控件
546浏览 • 1回复 待解决
「多态控件」的效果样式确认
2203浏览 • 1回复 待解决