起始页配置

// 配置共享元素id
起始页面为NavDestination或者Navigation都行但是推荐前者后者会出现两段动画

Image($r("app.media.background"))
  .height(100)
  .width(100)
  .borderRadius(20)
  .geometryTransition("shareID");
Button("to hello").onClick((event: ClickEvent) => {
  // this.nav.pushPathByName('hello',this.helloParam,true)
  this.getUIContext().animateTo({ duration: 500 }, () => {
    this.nav.pushPathByName("hello", this.helloParam, false);
  });
});
目标页面
import { AppStorageV2 } from "@kit.ArkUI"

@Builder
function worldBuilder(){
  world()
}

@ComponentV2
export struct world{
  @Consumer('nav')nav:NavPathStack = new NavPathStack()
  build() {
    NavDestination(){
      Column(){
        Image($r('app.media.background'))
          .height(300)
          .width(300)
          .borderRadius(20)
          .geometryTransition("shareID") //关键
      }
    }
    .title("world")
  }
}
Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐