访问HSP包中ArkUI组件的访问与开发

HSP包中的ArkUI开发

HarmonyOS
2024-05-26 16:16:59
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
jshyb

本文主要介绍访问HSP包中ArkUI组件的访问与开发

使用的核心API

核心代码解释

通过pushUrl页面路由至HSP包中,使用@Builder装饰器修饰组件,通过isShow中的height控制弹出页面高度,transition实现转场效果。

import router from '@ohos.router'; 
import { BusinessError } from '@ohos.base'; 
  
const module = import('library/src/main/ets/pages/Index') 
  
@Entry 
@Component 
struct Index { 
  @State message: string = 'Hello World' 
  
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
        // 添加按钮,以响应用户点击 
        Button() { 
          Text('click to pay') 
            .fontSize(30) 
            .fontWeight(FontWeight.Bold) 
        } 
        .type(ButtonType.Capsule) 
        .margin({ 
          top: 20 
        }) 
        .backgroundColor('#0D9FFB') 
        .width('40%') 
        .height('5%') 
        // 绑定点击事件 
        .onClick(() => { 
          router.pushUrl({url:"@bundle:com.example.test1109/library/ets/pages/Index" }) 
            .then(() => { 
            console.log("push page success"); 
          }).catch((err: BusinessError) => { 
            console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); 
          }) 
          // router.pushNamedRoute({name:"lib_page"}) 
          //   .then(() => { 
          //     console.log("push page success"); 
          //   }).catch((err: BusinessError) => { 
          //   console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); 
          // }) 
        }) 
        .width('100%') 
      } 
      .height('100%') 
    } 
  } 
} 
import { PayComponent } from '.components/PayComponent'; 
  
@Entry({routeName: 'lib_page'}) 
@Component 
export struct Index { 
  @State isShow: boolean = false 
  @State sheetHeight: number = 500; 
  @State showDragBar: boolean = true; 
  
  @Builder 
  myBuilder() { 
    Column() { 
      PayComponent({isShow: $isShow}); 
    } 
    .backgroundColor(Color.Blue) 
  } 
  
  build() { 
    Column() { 
      Button("打开二维码") 
        .onClick(() => { 
          this.isShow = true 
        }) 
        .fontSize(20) 
        .margin(10) 
        .bindSheet(this.isShow, 
          this.myBuilder(), 
          { 
            height: this.sheetHeight, 
            dragBar: this.showDragBar, 
            backgroundColor: Color.Blue, 
            onAppear: () => { 
              console.log("BindSheet onAppear.") 
            }, 
            onDisappear: () => { 
              console.log("BindSheet onDisappear.") 
            } 
          }) 
    } 
    .padding(100) 
    .backgroundColor(Color.White) 
    .width('100%') 
    .height('100%') 
  } 
} 
import curves from '@ohos.curves'; 
  
@Component 
export struct PayComponent { 
  
  @State isShowFirst: boolean = false; 
  @State firstFloorWidth: string = '100%'; 
  @State firstFloorHeight: string = '70%'; 
  
  private effect: TransitionEffect = 
  TransitionEffect.OPACITY.animation({ curve: curves.springMotion(0.3, 1) }) 
    .combine(TransitionEffect.move(TransitionEdge.BOTTOM)) 
  
  @Link isShow: boolean; 
  
  build() { 
    Row() { 
      Stack({ alignContent: Alignment.Bottom }) { 
        Stack() { 
          Column() { 
            Image($r('app.media.img')) 
              .height(200) 
              .width(200) 
  
            Button('确认') 
              .onClick(() => { 
                this.isShow = false 
              }) 
          } 
        } 
        .height(this.firstFloorHeight) 
        .width(this.firstFloorWidth) 
        .borderRadius({ 
          topLeft: 16, 
          topRight: 16 
        }) 
      } 
      .height('100%') 
      .width('100%') 
    } 
    .width('100%') 
    .height(500) 
  } 
}

实现效果

分享
微博
QQ
微信
回复
2024-05-27 21:43:30
相关问题
求大佬告知如何访问hsp页面?
325浏览 • 1回复 待解决
Web组件访问本地资源并传递参数。
391浏览 • 1回复 待解决
Stage模型如何申请网络访问权限
720浏览 • 1回复 待解决
在php几种不同访问数据库方法
1685浏览 • 1回复 待解决
访问控制开发指导,有谁知道吗?
432浏览 • 1回复 待解决
基于原生跨模块资源访问
266浏览 • 1回复 待解决
静态路由访问外网不通
1336浏览 • 0回复 待解决
从HAP,如何区分是HAR和HSP
756浏览 • 1回复 待解决
ArkUI 如何设置组件悬停状态?
465浏览 • 1回复 待解决
SkyWalking访问问题有懂吗?
858浏览 • 1回复 待解决
如何访问自定义文件?
320浏览 • 1回复 待解决
TaskPool是否可以访问静态成员
584浏览 • 1回复 待解决
如何动态访问media目录下资源
681浏览 • 1回复 待解决
鸿蒙如何访问华为云对象存储?
2483浏览 • 1回复 待解决