HarmonyOS 自定义tabs组件可以导入页面吗

目前是TabContent组件里面添加组件(非页面)

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

参考demo:

//Tabs:
import AnimateToExample from './Page'
@Entry
@Component
struct TabsExample {
  @State fontColor: string = '#182431'
  @State selectedFontColor: string = '#007DFF'
  @State currentIndex: number = 0
  private controller: TabsController = new TabsController()
  @State index:number = 0
  @Builder tabBuilder(index: number, name: string) {
    Column() {
      Text(name)
        .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
        .fontSize(16)
        .fontWeight(this.currentIndex === index ? 500 : 400)
        .lineHeight(22)
        .margin({ top: 17, bottom: 7 })

    }.width('100%').backgroundColor(Color.Green)
    .pixelRound({
      start:PixelRoundCalcPolicy.FORCE_CEIL,
      end:PixelRoundCalcPolicy.FORCE_CEIL,
      top:PixelRoundCalcPolicy.FORCE_CEIL,
      bottom:PixelRoundCalcPolicy.FORCE_CEIL
    }).onAreaChange((oldValue: Area, newValue: Area) => {
      console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`)
    })
  }

  build() {
    Column() {
      Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) {
        TabContent() {
          AnimateToExample()
        }.tabBar(this.tabBuilder(0, 'index')).backgroundColor(Color.Red)

        TabContent() {
        }.tabBar(this.tabBuilder(1, 'detail'))
      }
      .vertical(false)
      .barMode(BarMode.Fixed)
      .barWidth(360)
      .barHeight(56)
      .animationDuration(400)
      .onChange((index: number) => {
        this.currentIndex = index
      })
      .width(360)
      .height(296)
      .margin({ top: 52 })
      .backgroundColor('#F1F3F5')
      .onTabBarClick((index) =>{
        this.index = index
      })
    }.width('100%')
  }
}


//page:
@Entry
@Component
export default struct AnimateToExample {
  @State widthSize: number = 250
  @State heightSize: number = 100
  @State rotateAngle: number = 0
  private flag: boolean = true
  @State num :number = -1

  build() {
    Column() {
      Button('change size')
        .width(this.widthSize)
        .height(this.heightSize)
        .margin(30)
        .onClick(() => {
          if (this.flag) {
            animateTo({
              duration: 2000,
              curve: Curve.EaseOut,
              iterations: 3,
              playMode: PlayMode.Normal,
              onFinish: () => {
                console.info('play end')
              }
            }, () => {
              this.widthSize = 150
              this.heightSize = 60
            })
          } else {
            animateTo({}, () => {
              this.widthSize = 250
              this.heightSize = 100
            })
          }
          this.flag = !this.flag
        })
      Button('change rotate angle')
        .margin(50)
        .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
        .onClick(() => {
          animateTo({
            duration: 1200,
            curve: Curve.Friction,
            delay: 500,
            iterations: this.num, // 设置-1表示动画无限循环
            playMode: PlayMode.Alternate,
            onFinish: () => {
              console.info('play end')
            },
            expectedFrameRateRange: {
              min: 10,
              max: 120,
              expected: 60,
            }
          }, () => {
            this.rotateAngle = 90
          })
        })


      Button("click").onClick(() => {
        this.num = 0
      })
    }.width('100%').margin({ top: 5 })
  }
}
分享
微博
QQ
微信
回复
1天前
相关问题
如何自定义模拟Tabs组件
936浏览 • 1回复 待解决
Tabs组件自定义导航栏UI问题
842浏览 • 1回复 待解决
huks密钥库导入自定义密钥
271浏览 • 1回复 待解决
智慧推荐可以自定义app
7783浏览 • 1回复 待解决
HarmonyOS 自定义组件支持链式调用
63浏览 • 1回复 待解决
HarmonyOS 定义自定义组件
65浏览 • 1回复 待解决