From 7489b6bbb17bc0b74429583f1d63752a7f6c980a Mon Sep 17 00:00:00 2001 From: liugang9704 <2745340733@qq.com> Date: Wed, 23 Jul 2025 11:04:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=8C=E6=BA=90=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NetworkKit/entry/src/main/ets/pages/SetCookie.ets | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/NetworkKit/entry/src/main/ets/pages/SetCookie.ets b/NetworkKit/entry/src/main/ets/pages/SetCookie.ets index 0b853ea..b239c74 100644 --- a/NetworkKit/entry/src/main/ets/pages/SetCookie.ets +++ b/NetworkKit/entry/src/main/ets/pages/SetCookie.ets @@ -20,16 +20,6 @@ // [Start SetCookie] import { http } from '@kit.NetworkKit'; -class Header { - public contentType: string; - public cookie: string; - - constructor(contentType: string, cookie: string) { - this.contentType = contentType; - this.cookie = cookie; - } -} - @Entry @Component struct HttpRequest { @@ -44,9 +34,10 @@ struct HttpRequest { priority: 1, // Developers add header fields according to their own business needs, with the first parameter being contentType // and the second parameter being cookie - header: new Header('application/json', 'key1=value1; key2=value2') + header: { + 'cookie': 'key1=value1;key2=value2' + } }; - console.info('Header:' + JSON.stringify(new Header('application/json', 'key1=value1; key2=value2'))); httpRequest.request("EXAMPLE_URL", options, (err: Error, data: http.HttpResponse) => { if (!err) { console.info('Result:' + data.result); -- Gitee From 203e97fe4a44c765001a44aab854dd64b16e6629 Mon Sep 17 00:00:00 2001 From: liugang9704 <2745340733@qq.com> Date: Wed, 23 Jul 2025 11:05:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=E6=96=B0=E5=A2=9EFAQ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/pages/HeightFollowsSlidingChanges.ets | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 ArkUI/entry/src/main/ets/pages/HeightFollowsSlidingChanges.ets diff --git a/ArkUI/entry/src/main/ets/pages/HeightFollowsSlidingChanges.ets b/ArkUI/entry/src/main/ets/pages/HeightFollowsSlidingChanges.ets new file mode 100644 index 0000000..7b57c93 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/HeightFollowsSlidingChanges.ets @@ -0,0 +1,163 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何实现一个Swiper根据内容高度随滑动距离变动的效果 +*/ + +// [Start height_follows_sliding_changes] +let COLUMN_NUMBER = 5; +let COLUMN_GAP = 20; +let ROWS_GAP = 20; + +@Entry +@Component +struct Index { + build() { + Column() { + Text('Head area') + .textAlign(TextAlign.Center) + .backgroundColor(Color.Yellow) + .width('100%') + .height(40) + GridDemo() + .width('90%') + Text('Tail area') + .textAlign(TextAlign.Center) + .backgroundColor(Color.Green) + .width('100%') + .height('30%') + } + } +} + +@Component +struct GridDemo { + @State gridHeights: number[] = []; + @State swiperHeight: number = 0; + @State tipList: string[] = ['Mathematics', 'Chinese Language', 'English', 'Biology']; + @State tipImageX: string = '0%'; + @State tipIndex: number = 0; + @State numberList: number[][] = [ + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30] + ]; + private swiperController: SwiperController = new SwiperController(); + + aboutToAppear(): void { + this.getHeights(); + } + + getHeights() { + for (let index = 0; index < this.numberList.length; index++) { + let rowNumer = Math.ceil(this.numberList[index].length / COLUMN_NUMBER); + let gridHeight = px2vp(122) * rowNumer + COLUMN_GAP * (rowNumer - 1); + this.gridHeights.push(gridHeight); + } + this.swiperHeight = this.gridHeights[0]; + } + + build() { + Column() { + Stack() { + Image($r('app.media.background')) + .objectFit(ImageFit.Contain) + .width((100 / this.tipList.length) + '%') + .offset({ x: this.tipImageX }) + Row() { + ForEach(this.tipList, (item: string, index: number) => { + ListItem() { + Text(item) + .backgroundImage(this.tipIndex == index ? $r('app.media.background') : null, ImageRepeat.NoRepeat) + .backgroundImageSize({ + width: '100%', + height: '100%' + }) + } + }, (item: string) => item) + } + .justifyContent(FlexAlign.SpaceAround) + .height(20) + .width('100%') + .margin({ + top: 5, + bottom: 5 + }) + } + .alignContent(Alignment.Start) + .height(30) + .backgroundColor(Color.Pink) + + Column() { + Swiper(this.swiperController) { + ForEach(this.numberList, (item: number, index: number) => { + Child({ numberList: this.numberList[index] }) + }) + } + .effectMode(EdgeEffect.None) + .indicator(false) + .loop(false) + .onContentDidScroll((selectedIndex: number, index: number, position: number, mainAxisLength: number) => { + // The direct scrolling positions of the two indices change the height of the parent control + if (selectedIndex != index && Math.abs(selectedIndex - index) == 1) { + let curHeight = this.gridHeights[selectedIndex]; + let targetHeight = this.gridHeights[index]; + this.swiperHeight = targetHeight + + (selectedIndex < index ? (curHeight - targetHeight) : (targetHeight = curHeight)) * position; + } + // Switch the subscript of the selected status + if (selectedIndex == index) { + let curIndex = -1 / this.tipList.length * position + selectedIndex / this.tipList.length; + this.tipImageX = (curIndex * 100).toFixed(2) + '%'; + this.tipIndex = Math.ceil(curIndex / 0.25 + 0.5) - 1; + } + }) + } + .height(this.swiperHeight) + } + .width('100%') + } +} + +@Component +struct Child { + @Prop numberList: number[]; + + build() { + Grid() { + ForEach(this.numberList, (item: number) => { + GridItem() { + Column() { + Image($r('app.media.startIcon')) + .width(20) + .height(20) + Text('Menu' + item) + .fontSize(15) + } + } + }) + } + .columnsGap(COLUMN_GAP) + .rowsGap(ROWS_GAP) + .scrollBar(BarState.Off) + .columnsTemplate('1fr '.repeat(COLUMN_NUMBER)) + .animation({ + duration: 1000 + }) + } +} +// [End height_follows_sliding_changes] \ No newline at end of file -- Gitee