• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import curves from '@ohos.curves';
17import { Route, RouteGroup } from 'common/src/main/ets/common/route';
18import { KeyboardAvoidMode } from '@kit.ArkUI';
19import { blankAndDividerDestination, blankAndDividerRoute } from 'feature/src/main/ets/pages/BlankAndDivider';
20import {
21  rowsColumnsAndStackingDestination,
22  rowsColumnsAndStackingRoute
23} from 'feature/src/main/ets/pages/RowsColumnsAndStacking'
24import {
25  gridAndColumnLayoutDestination,
26  gridAndColumnLayoutRoute
27} from 'feature/src/main/ets/pages/GridAndColumnLayout'
28import { scrollAndSwipeDestination, scrollAndSwipeRoute } from 'feature/src/main/ets/pages/ScrollAndSwipe'
29import {
30  navigationAndSwitchingDestination,
31  navigationAndSwitchingRoute
32} from 'feature/src/main/ets/pages/NavigationAndSwitching'
33import {
34  buttonsAndSelectionsDestination,
35  buttonsAndSelectionsRoute
36} from 'feature/src/main/ets/pages/ButtonsAndSelections'
37import { textAndInputDestination, textAndInputRoute } from 'feature/src/main/ets/pages/TextAndInput'
38import { imagesAndVideosDestination, imagesAndVideosRoute } from 'feature/src/main/ets/pages/ImagesAndVideos'
39import { informationDisplayDestination, informationDisplayRoute } from 'feature/src/main/ets/pages/InformationDisplay'
40import { menusDestination, menusRoute } from 'feature/src/main/ets/pages/Menus'
41import { dialogBoxesDestination, dialogBoxesRoute } from 'feature/src/main/ets/pages/DialogBoxes'
42
43@Styles
44function CardPressedStyle() {
45  .backgroundColor('rgba(0,0,0,0.1)')
46  .opacity(1)
47  .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 })
48}
49
50@Styles
51function CardNormalStyle() {
52  .backgroundColor('rgba(0,0,0,0)')
53  .opacity(1)
54  .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 })
55
56}
57
58@Styles
59function CardDisabledStyle() {
60  .backgroundColor('rgba(0,0,0,0)')
61  .opacity(0.5)
62  .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 })
63}
64
65@Builder
66function Destination(name: string, route: Route) {
67  if (name.startsWith('BlankAndDivider/')) {
68    blankAndDividerDestination(name, route)
69  } else if (name.startsWith('RowsColumnsAndStacking/')) {
70    rowsColumnsAndStackingDestination(name, route)
71  } else if (name.startsWith('GridAndColumnLayout/')) {
72    gridAndColumnLayoutDestination(name, route)
73  } else if (name.startsWith('ScrollAndSwipe/')) {
74    scrollAndSwipeDestination(name, route)
75  } else if (name.startsWith('NavigationAndSwitching/')) {
76    navigationAndSwitchingDestination(name, route)
77  } else if (name.startsWith('ButtonsAndSelections/')) {
78    buttonsAndSelectionsDestination(name, route)
79  } else if (name.startsWith('TextAndInput/')) {
80    textAndInputDestination(name, route)
81  } else if (name.startsWith('ImagesAndVideos/')) {
82    imagesAndVideosDestination(name, route)
83  } else if (name.startsWith('InformationDisplay/')) {
84    informationDisplayDestination(name, route)
85  } else if (name.startsWith('Menus/')) {
86    menusDestination(name, route)
87  } else if (name.startsWith('DialogBoxes/')) {
88    dialogBoxesDestination(name, route)
89  }
90}
91
92@Entry
93@Component
94struct Index {
95  @Provide('router') router: NavPathStack = new NavPathStack();
96  @State routes: RouteGroup[] = [
97    blankAndDividerRoute,
98    rowsColumnsAndStackingRoute,
99    gridAndColumnLayoutRoute,
100    scrollAndSwipeRoute,
101    navigationAndSwitchingRoute,
102    buttonsAndSelectionsRoute,
103    textAndInputRoute,
104    imagesAndVideosRoute,
105    informationDisplayRoute,
106    menusRoute,
107    dialogBoxesRoute
108  ];
109  @State selection: string | null = null;
110
111  @Builder
112  ListItemGroupHeader(route: RouteGroup) {
113    Row() {
114      Text(route.label)
115        .fontColor($r('sys.color.ohos_id_color_text_primary'))
116        .fontWeight(FontWeight.Medium)
117
118      Blank()
119
120      Text(`${route.children.length}`)
121        .fontColor($r('sys.color.ohos_id_color_text_secondary'))
122        .opacity(this.selection === route.name ? 0 : 1)
123
124      Image($r('sys.media.ohos_ic_public_arrow_right'))
125        .fillColor($r('sys.color.ohos_id_color_fourth'))
126        .height(24)
127        .width(24)
128        .rotate({ angle: this.selection === route.name ? 90 : 0 })
129        .animation({ curve: curves.interpolatingSpring(0, 1, 228, 30) })
130    }
131    .borderRadius(20)
132    .width('100%')
133    .padding({
134      left: 8,
135      right: 8,
136      top: 18,
137      bottom: 18
138    })
139    .enabled(!!route.children.length)
140    .stateStyles({
141      pressed: CardPressedStyle,
142      normal: CardNormalStyle,
143      disabled: CardDisabledStyle,
144    })
145    .onClick(() => {
146      animateTo(
147        { curve: curves.interpolatingSpring(0, 1, 228, 25) },
148        () => {
149          if (this.selection === route.name) {
150            this.selection = null;
151          } else {
152            this.selection = route.name;
153          }
154        });
155    })
156  }
157
158  aboutToAppear(): void {
159    this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE);
160  }
161
162  build() {
163    Navigation(this.router) {
164      Text('ArkUI 是 OpenHarmony 的控件底座,这是一个 ArkUI 控件检视应用,你可以查阅目前版本的控件能力与默认样式。')
165        .fontSize(16)
166        .margin({ left: 16, right: 10, bottom: 24 })
167
168      List({ space: 12 }) {
169        ForEach(this.routes, (routeGroup: RouteGroup) => {
170          ListItemGroup({
171            header: this.ListItemGroupHeader(routeGroup),
172            style: ListItemGroupStyle.CARD,
173          }) {
174            if (routeGroup.name === this.selection) {
175              ForEach(routeGroup.children, (route: Route) => {
176                ListItem() {
177                  Row() {
178                    Text(route.label).fontSize(16)
179                    Blank()
180                    Image($r('sys.media.ohos_ic_public_arrow_right'))
181                      .fillColor($r('sys.color.ohos_id_color_fourth'))
182                      .height(24)
183                      .width(24)
184                  }
185                  .stateStyles({
186                    pressed: CardPressedStyle,
187                    normal: CardNormalStyle,
188                    disabled: CardDisabledStyle,
189                  })
190                  .borderRadius(20)
191                  .padding({
192                    left: 8,
193                    right: 8,
194                    top: 13,
195                    bottom: 13
196                  })
197                  .transition(
198                    TransitionEffect.OPACITY.animation({
199                      curve: curves.interpolatingSpring(0, 1, 228, 30)
200                    })
201                  )
202                  .width('100%')
203                  .onClick(() => {
204                    const name = `${routeGroup.name}/${route.name}`;
205                    const pathNames = this.router.getAllPathName();
206                    if (pathNames[pathNames.length-1] !== name) {
207                      this.router.pushPath({ name, param: route });
208                    }
209                  })
210                }
211                .width('100%')
212              })
213            }
214          }
215          .padding(4)
216          .divider({ strokeWidth: 0.5 })
217        })
218      }.padding({ bottom: 70 })
219    }
220    .title('Component')
221    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
222    .navDestination(Destination)
223  }
224}