DEV Community

ShuGang Zhou
ShuGang Zhou

Posted on

HarmonyOS NEXT 实战系列08-案例微博导航设置

Image description


实现步骤:

首页 Tab 栏
导航设置页,实现切换
使用 PersistentStorage + AppStorage 实现全局UI状态且持久化
代码:

Index.ets 文件

import { router } from '@kit.ArkUI'

PersistentStorage.persistProp<boolean>('isVideo', true)

@Entry
@Component
struct Index {
  @StorageProp('isVideo') isVideo: boolean = true

  build() {
    Column() {
      Tabs({ barPosition: BarPosition.End }) {
        TabContent() {
          Text('首页')
        }
        .tabBar({
          text: '首页'
        })

        if (this.isVideo) {
          TabContent() {
            Text('视频')
          }
          .tabBar({
            text: '视频'
          })
        } else {
          TabContent() {
            Text('超话')
          }
          .tabBar({
            text: '超话'
          })
        }


        TabContent() {
          Text('发现')
        }
        .tabBar({
          text: '发现'
        })

        TabContent() {
          Text('消息')
        }
        .tabBar({
          text: '消息'
        })

        TabContent() {
          Column({ space: 24 }) {
            Button('导航栏设置')
              .onClick(() => {
                router.pushUrl({ url: 'pages/NavSetting' })
              })
            Text('')
          }
        }
        .tabBar({
          text: ''
        })
      }
    }
    .height('100%')
    .width('100%')
  }
}

Enter fullscreen mode Exit fullscreen mode

NavSetting.ets 文件

import { router } from '@kit.ArkUI'

@Entry
@Component
struct NavSetting {
  @StorageLink('isVideo') isVideo: boolean = true

  build() {
    Column() {
      Row({ space: 2 }) {
        Image($r('sys.media.ohos_ic_back'))
          .width(24)
          .aspectRatio(1)
        Text('返回')
      }
      .alignSelf(ItemAlign.Start)

      .onClick(() => {
        router.back()
      })

      Row() {
        Text('超话')
        Blank()
        if (!this.isVideo) {
          Image($r('sys.media.ohos_ic_public_ok'))
            .width(24)
            .aspectRatio(1)
            .fillColor('#00ff00')
        }
      }
      .height(60)
      .width('100%')
      .onClick(() => {
        this.isVideo = false
      })

      Row() {
        Text('视频')
        Blank()
        if (this.isVideo) {
          Image($r('sys.media.ohos_ic_public_ok'))
            .width(24)
            .aspectRatio(1)
            .fillColor('#00ff00')
        }
      }
      .height(60)
      .width('100%')
      .onClick(() => {
        this.isVideo = true
      })
    }
    .height('100%')
    .width('100%')
    .padding(15)
  }
}
Enter fullscreen mode Exit fullscreen mode

梳理:

Tabs 组件基础用法
alignSelf(ItemAlign.Start) 单独设置对齐方式

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

Top comments (0)

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

👋 Kindness is contagious

DEV shines when you're signed in, unlocking a customized experience with features like dark mode!

Okay