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 { rowsColumnsAndStackingDestination, rowsColumnsAndStackingRoute } from 'feature/src/main/ets/pages/RowsColumnsAndStacking' 21import { gridAndColumnLayoutDestination, gridAndColumnLayoutRoute } from 'feature/src/main/ets/pages/GridAndColumnLayout' 22import { scrollAndSwipeDestination, scrollAndSwipeRoute } from 'feature/src/main/ets/pages/ScrollAndSwipe' 23import { navigationAndSwitchingDestination, navigationAndSwitchingRoute } from 'feature/src/main/ets/pages/NavigationAndSwitching' 24import { buttonsAndSelectionsDestination, buttonsAndSelectionsRoute } from 'feature/src/main/ets/pages/ButtonsAndSelections' 25import { textAndInputDestination, textAndInputRoute } from 'feature/src/main/ets/pages/TextAndInput' 26import { imagesAndVideosDestination, imagesAndVideosRoute } from 'feature/src/main/ets/pages/ImagesAndVideos' 27import { informationDisplayDestination, informationDisplayRoute } from 'feature/src/main/ets/pages/InformationDisplay' 28import { menusDestination, menusRoute } from 'feature/src/main/ets/pages/Menus' 29import { dialogBoxesDestination, dialogBoxesRoute } from 'feature/src/main/ets/pages/DialogBoxes' 30@Styles 31function CardPressedStyle() { 32 .backgroundColor('rgba(0,0,0,0.1)') 33 .opacity(1) 34 .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 }) 35} 36 37@Styles 38function CardNormalStyle() { 39 .backgroundColor('rgba(0,0,0,0)') 40 .opacity(1) 41 .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 }) 42 43} 44 45@Styles 46function CardDisabledStyle() { 47 .backgroundColor('rgba(0,0,0,0)') 48 .opacity(0.5) 49 .animation({ curve: curves.cubicBezierCurve(0.33, 0, 0.67, 1), duration: 100 }) 50} 51 52@Builder 53function Destination(name: string, route: Route) { 54 if (name.startsWith('BlankAndDivider/')) { 55 blankAndDividerDestination(name, route) 56 } else if (name.startsWith('RowsColumnsAndStacking/')){ 57 rowsColumnsAndStackingDestination(name, route) 58 } else if (name.startsWith('GridAndColumnLayout/')){ 59 gridAndColumnLayoutDestination(name, route) 60 } else if (name.startsWith('ScrollAndSwipe/')){ 61 scrollAndSwipeDestination(name, route) 62 } else if (name.startsWith('NavigationAndSwitching/')){ 63 navigationAndSwitchingDestination(name, route) 64 } else if (name.startsWith('ButtonsAndSelections/')){ 65 buttonsAndSelectionsDestination(name, route) 66 } else if (name.startsWith('TextAndInput/')){ 67 textAndInputDestination(name, route) 68 } else if (name.startsWith('ImagesAndVideos/')){ 69 imagesAndVideosDestination(name, route) 70 }else if (name.startsWith('InformationDisplay/')){ 71 informationDisplayDestination(name, route) 72 }else if (name.startsWith('Menus/')){ 73 menusDestination(name, route) 74 }else if (name.startsWith('DialogBoxes/')){ 75 dialogBoxesDestination(name, route) 76 } 77} 78 79@Entry 80@Component 81struct Index { 82 @Provide('router') router: NavPathStack = new NavPathStack(); 83 @State routes: RouteGroup[] = [ 84 blankAndDividerRoute, 85 rowsColumnsAndStackingRoute, 86 gridAndColumnLayoutRoute, 87 scrollAndSwipeRoute, 88 navigationAndSwitchingRoute, 89 buttonsAndSelectionsRoute, 90 textAndInputRoute, 91 imagesAndVideosRoute, 92 informationDisplayRoute, 93 menusRoute, 94 dialogBoxesRoute 95 ]; 96 @State selection: string | null = null; 97 98 @Builder 99 ListItemGroupHeader(route: RouteGroup) { 100 Row() { 101 Text(route.label) 102 .fontColor($r('sys.color.ohos_id_color_text_primary')) 103 .fontWeight(FontWeight.Medium) 104 105 Blank() 106 107 Text(`${route.children.length}`) 108 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 109 .opacity(this.selection === route.name ? 0 : 1) 110 111 Image($r('sys.media.ohos_ic_public_arrow_right')) 112 .fillColor($r('sys.color.ohos_id_color_fourth')) 113 .height(24) 114 .width(24) 115 .rotate({ angle: this.selection === route.name ? 90 : 0 }) 116 .animation({ curve: curves.interpolatingSpring(0, 1, 228, 30) }) 117 } 118 .borderRadius(20) 119 .width('100%') 120 .padding({ 121 left: 8, 122 right: 8, 123 top: 18, 124 bottom: 18 125 }) 126 .enabled(!!route.children.length) 127 .stateStyles({ 128 pressed: CardPressedStyle, 129 normal: CardNormalStyle, 130 disabled: CardDisabledStyle, 131 }) 132 .onTouch((event) => { 133 if (event.type === TouchType.Up) { 134 animateTo( 135 { curve: curves.interpolatingSpring(0, 1, 228, 25) }, 136 () => { 137 if (this.selection === route.name) { 138 this.selection = null; 139 } else { 140 this.selection = route.name; 141 } 142 }); 143 } 144 }) 145 } 146 147 aboutToAppear(): void{ 148 this.getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE); 149 } 150 build() { 151 Navigation(this.router) { 152 Text('ArkUI 是 OpenHarmony 的控件底座,这是一个 ArkUI 控件检视应用,你可以查阅目前版本的控件能力与默认样式。') 153 .fontSize(16) 154 .margin({ left: 16, right: 10, bottom: 24 }) 155 156 List({ space: 12 }) { 157 ForEach(this.routes, (routeGroup: RouteGroup) => { 158 ListItemGroup({ 159 header: this.ListItemGroupHeader(routeGroup), 160 style: ListItemGroupStyle.CARD, 161 }) { 162 if (routeGroup.name === this.selection) { 163 ForEach(routeGroup.children, (route: Route) => { 164 ListItem() { 165 Row() { 166 Text(route.label).fontSize(16) 167 Blank() 168 Image($r('sys.media.ohos_ic_public_arrow_right')) 169 .fillColor($r('sys.color.ohos_id_color_fourth')) 170 .height(24) 171 .width(24) 172 } 173 .stateStyles({ 174 pressed: CardPressedStyle, 175 normal: CardNormalStyle, 176 disabled: CardDisabledStyle, 177 }) 178 .borderRadius(20) 179 .padding({ 180 left: 8, 181 right: 8, 182 top: 13, 183 bottom: 13 184 }) 185 .transition( 186 TransitionEffect.OPACITY.animation({ 187 curve: curves.interpolatingSpring(0, 1, 228, 30) 188 }) 189 ) 190 .width('100%') 191 .onClick(() => { 192 const name = `${routeGroup.name}/${route.name}`; 193 const pathNames = this.router.getAllPathName(); 194 if (pathNames[pathNames.length-1] !== name) { 195 this.router.pushPath({ name, param: route }); 196 } 197 }) 198 } 199 .width('100%') 200 }) 201 } 202 } 203 .padding(4) 204 .divider({ strokeWidth: 0.5 }) 205 }) 206 }.padding({bottom: 70}) 207 } 208 .title('Component') 209 .backgroundColor($r('sys.color.ohos_id_color_sub_background')) 210 .navDestination(Destination) 211 } 212}