_YtHeader.ets 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { YTAvoid } from "basic"
  2. @ComponentV2
  3. export struct _YtHeader {
  4. @Param isShowBackComp: boolean = true
  5. @Param @Require title: string
  6. @Param _h: Length = 54
  7. @BuilderParam rightComp: () => void
  8. @BuilderParam leftComp: () => void
  9. @Event _onBackPress: () => void = () => { }
  10. @Event _onClickTitle: () => void = () => {}
  11. @Event _onClickRightComp: () => void = () => {}
  12. build() {
  13. RelativeContainer() {
  14. Row(){
  15. if(this.isShowBackComp) {
  16. Image($r('[basic].media.ic_back'))
  17. .width(24)
  18. .aspectRatio(1)
  19. .onClick(this._onBackPress)
  20. } else if(this.leftComp) {
  21. this.leftComp()
  22. } else {
  23. Text()
  24. }
  25. Row(){
  26. if(this.rightComp) {
  27. this.rightComp()
  28. }
  29. }
  30. .onClick(this._onClickRightComp)
  31. }
  32. .id('back_icon')
  33. .width("100%")
  34. .alignItems(VerticalAlign.Center)
  35. .justifyContent(FlexAlign.SpaceBetween)
  36. .alignRules({
  37. top: { anchor: "__container__", align: VerticalAlign.Top},
  38. left: { anchor: "__container__", align: HorizontalAlign.Start}
  39. })
  40. Text(this.title)
  41. .fontSize(20)
  42. .fontWeight(500)
  43. .alignRules({
  44. center: { anchor: "back_icon", align: VerticalAlign.Center},
  45. middle: { anchor: "back_icon", align: HorizontalAlign.Center}
  46. })
  47. .onClick(this._onClickTitle)
  48. }
  49. .width("100%")
  50. .height(this._h)
  51. .padding({top: 12, bottom: 12})
  52. }
  53. }