YtTiltleBar.ets 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. @Component
  2. export struct YTTitleBar {
  3. @Prop headerTitleList: string[]
  4. listScroller: ListScroller = new ListScroller()
  5. @Prop @Watch('currentIndexChange') currentIndex: number
  6. onCurrentIndexChange = (_: number) => {
  7. }
  8. currentIndexChange() {
  9. this.listScroller.scrollToIndex(this.currentIndex, true, ScrollAlign.CENTER)
  10. }
  11. build() {
  12. List({ space: 18, scroller: this.listScroller }) {
  13. ForEach(this.headerTitleList, (item: string, index) => {
  14. ListItem() {
  15. Column() {
  16. Text(item)
  17. .height(24)
  18. .fontColor(this.currentIndex == index ? '#FF171717' : '#B3333333')
  19. .fontSize(18)
  20. .fontWeight(this.currentIndex == index ? 700 : 500)
  21. .onClick(() => {
  22. this.currentIndex = index
  23. this.onCurrentIndexChange(this.currentIndex)
  24. })
  25. if (this.currentIndex == index) {
  26. Text()
  27. .width(14)
  28. .height(4)
  29. .borderRadius(12)
  30. .backgroundColor($r('app.color.main_ac_color_dark'))
  31. }
  32. }
  33. .justifyContent(FlexAlign.SpaceBetween)
  34. }
  35. })
  36. }
  37. .height(30)
  38. .width('100%')
  39. .listDirection(Axis.Horizontal)
  40. .scrollBar(BarState.Off)
  41. }
  42. }