From ddad3c008d8f599632ffd4c9538ddad59fe0ad4f Mon Sep 17 00:00:00 2001 From: zhoulisheng1 Date: Tue, 23 May 2023 14:12:18 +0800 Subject: [PATCH 1/4] =?UTF-8?q?1.=E7=94=B1=E4=BA=8EPanGesture=E4=BC=9A?= =?UTF-8?q?=E4=BD=BF=E4=B8=8A=E5=B1=82=E7=9A=84Tab=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=B7=A6=E5=8F=B3=E6=BB=91=E5=8A=A8,?= =?UTF-8?q?=E6=89=80=E4=BB=A5=E8=BF=99=E9=87=8C=E5=BA=94=E8=AF=A5=E9=99=90?= =?UTF-8?q?=E5=88=B6PanGesture=E5=8F=AA=E6=94=AF=E6=8C=81=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=BB=91=E5=8A=A8=E8=83=BD=E5=8A=9B=E3=80=82=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E7=88=B6=E5=AE=B9=E5=99=A8=E5=B7=A6=E5=8F=B3=E6=BB=91?= =?UTF-8?q?=E5=8A=A8=E6=97=A0=E5=93=8D=E5=BA=94=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng1 --- .../src/main/ets/components/PullToRefresh/PullToRefresh.ets | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PullToRefresh/src/main/ets/components/PullToRefresh/PullToRefresh.ets b/PullToRefresh/src/main/ets/components/PullToRefresh/PullToRefresh.ets index 3d1278c..9844743 100644 --- a/PullToRefresh/src/main/ets/components/PullToRefresh/PullToRefresh.ets +++ b/PullToRefresh/src/main/ets/components/PullToRefresh/PullToRefresh.ets @@ -79,6 +79,8 @@ export struct PullToRefresh { private refreshPoint2x?: number = 0; private refreshPoint2y?: number = 0; + private panOption: PanGestureOptions = new PanGestureOptions({direction: PanDirection.Up | PanDirection.Down}) + aboutToAppear() { if (!this.refreshConfigurator) { this.refreshConfigurator = new PullToRefreshConfigurator(); @@ -130,7 +132,7 @@ export struct PullToRefresh { this.mHeightNumber = Math.round(newValue.height as number); }) .parallelGesture( - PanGesture() + PanGesture(this.panOption) .onActionStart((event: GestureEvent) => { this.touchYOld = event.offsetY; }) -- Gitee From af7a498cdc1effc5a7fd25e942f3d4c3a1738391 Mon Sep 17 00:00:00 2001 From: zhoulisheng1 Date: Wed, 24 May 2023 14:49:13 +0800 Subject: [PATCH 2/4] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E6=89=8B=E5=8A=BF=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8A=E6=8B=89=E6=89=8B=E5=8A=BF=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E4=B8=8B=E6=8B=89=E5=9B=9E=E5=BC=B9=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng1 --- .../main/ets/components/PullToRefresh/PullToRefresh.ets | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PullToRefresh/src/main/ets/components/PullToRefresh/PullToRefresh.ets b/PullToRefresh/src/main/ets/components/PullToRefresh/PullToRefresh.ets index 9844743..c389064 100644 --- a/PullToRefresh/src/main/ets/components/PullToRefresh/PullToRefresh.ets +++ b/PullToRefresh/src/main/ets/components/PullToRefresh/PullToRefresh.ets @@ -233,7 +233,12 @@ export struct PullToRefresh { return; } this.touchYNew = event.offsetY; - if ((this.state == IS_FREE && this.scroller.currentOffset().yOffset == 0) || // 处于自由状态且列表处于顶部位置 + + // 当前手势是否下拉 + let distanceY = this.touchYNew - this.touchYOld; + let isPullAction = distanceY > 0; + + if ((this.state == IS_FREE && this.scroller.currentOffset().yOffset == 0 && isPullAction) || // 处于自由状态且列表处于顶部位置 并且 当前手势是下拉手势 this.state == IS_PULL_DOWN_1 || this.state == IS_PULL_DOWN_2) { // 处于下拉状态中 if (this.refreshConfigurator.getHasRefresh()) { // 获取最新位移距离 -- Gitee From 3e6ad4cb5ec679e65656692704e266e8c5996761 Mon Sep 17 00:00:00 2001 From: zhoulisheng1 Date: Tue, 23 May 2023 15:18:46 +0800 Subject: [PATCH 3/4] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4Tab=E4=B8=AD=E4=BD=BF=E7=94=A8PullToRefresh?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng1 --- entry/src/main/ets/pages/index.ets | 5 + entry/src/main/ets/pages/tabsTestPage.ets | 137 ++++++++++++++++++ .../resources/base/profile/main_pages.json | 3 +- 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 entry/src/main/ets/pages/tabsTestPage.ets diff --git a/entry/src/main/ets/pages/index.ets b/entry/src/main/ets/pages/index.ets index b31544a..2ef2fc0 100644 --- a/entry/src/main/ets/pages/index.ets +++ b/entry/src/main/ets/pages/index.ets @@ -34,6 +34,11 @@ struct Index { .onClick(() => { router.push({ url: 'pages/customRefreshAnim' }) }) + Button('Tab配合PullToRefresh') + .margin({ top: 10 }) + .onClick(() => { + router.push({ url: 'pages/tabsTestPage' }) + }) } .width('100%') } diff --git a/entry/src/main/ets/pages/tabsTestPage.ets b/entry/src/main/ets/pages/tabsTestPage.ets new file mode 100644 index 0000000..43f7671 --- /dev/null +++ b/entry/src/main/ets/pages/tabsTestPage.ets @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2022 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. + */ +import { PullToRefresh } from '@ohos/pulltorefresh' + +@Entry +@Component +struct TabsExample { + @State fontColor: string = '#182431' + @State selectedFontColor: string = '#007DFF' + @State currentIndex: number = 0 + private controller: TabsController = new TabsController() + + @Builder TabBuilder(index: number, name: string) { + Column() { + Text(name) + .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor) + .fontSize(16) + .fontWeight(this.currentIndex === index ? 500 : 400) + .lineHeight(22) + .margin({ top: 17, bottom: 7 }) + Divider() + .strokeWidth(2) + .color('#007DFF') + .opacity(this.currentIndex === index ? 1 : 0) + }.width('100%') + } + + build() { + Column() { + Tabs({ barPosition: BarPosition.Start, controller: this.controller }) { + TabContent() { + // Column().width('100%').height('100%').backgroundColor('#00CB87') + PullToRefreshDemo() + }.tabBar(this.TabBuilder(0, 'green')) + + TabContent() { + Column().width('100%').height('100%').backgroundColor('#007DFF') + }.tabBar(this.TabBuilder(1, 'blue')) + + TabContent() { + Column().width('100%').height('100%').backgroundColor('#FFBF00') + }.tabBar(this.TabBuilder(2, 'yellow')) + + TabContent() { + Column().width('100%').height('100%').backgroundColor('#E67C92') + }.tabBar(this.TabBuilder(3, 'pink')) + } + .vertical(false) + .barMode(BarMode.Fixed) + .barWidth(360) + .barHeight(56) + .animationDuration(400) + .onChange((index: number) => { + this.currentIndex = index + }) + .width('100%').height('100%') + .margin({ top: 52 }) + .backgroundColor('#F1F3F5') + }.width('100%') + } +} + +@Component +struct PullToRefreshDemo { + @State refreshText: string = ''; + private dataNumbers: string[] = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']; + private dataStrings: string[] = ['我的评论', '与我相关', '个人中心1', '个人中心2', '个人中心3', '我的发布', '设置', '退出登录']; + @State data: string[] = this.dataStrings; + // 需绑定列表或宫格组件 + private scroller: Scroller = new Scroller(); + + build() { + Column() { + PullToRefresh({ + // 必传项,列表组件所绑定的数据 + data: $data, + // 必传项,需绑定传入主体布局内的列表或宫格组件 + scroller: this.scroller, + // 必传项,自定义主体布局,内部有列表或宫格组件 + customList: this.getListView, + // 可选项,下拉刷新回调 + onRefresh: () => { + return new Promise((resolve, reject) => { + // 模拟网络请求操作,请求网络2秒后得到数据,通知组件,变更列表数据 + setTimeout(() => { + resolve('刷新成功'); + this.data = this.dataNumbers; + }, 2000); + }); + }, + // 可选项,上拉加载更多回调 + onLoadMore: () => { + return new Promise((resolve, reject) => { + // 模拟网络请求操作,请求网络2秒后得到数据,通知组件,变更列表数据 + setTimeout(() => { + resolve(''); + this.data.push("增加的条目" + this.data.length); + }, 2000); + }); + }, + customLoad: null, + customRefresh: null, + }) + } + } + + @Builder + private getListView() { + List({ space: 20, scroller: this.scroller }) { + ForEach(this.data, (item: string) => { + ListItem() { + Text(item) + .width('100%') + .height(150) + .fontSize(20) + .textAlign(TextAlign.Center) + .backgroundColor('#95efd2') + } + }) + } + .backgroundColor('#eeeeee') + .divider({ strokeWidth: 1, color: 0x222222 }) + .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果 + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index ec61b37..b408a90 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -3,6 +3,7 @@ "pages/index", "pages/quickStart", "pages/customConfig", - "pages/customRefreshAnim" + "pages/customRefreshAnim", + "pages/tabsTestPage" ] } -- Gitee From 9869dcc17820b1582c4f28db183075a4ca9dde7e Mon Sep 17 00:00:00 2001 From: zhoulisheng1 Date: Wed, 24 May 2023 15:34:01 +0800 Subject: [PATCH 4/4] =?UTF-8?q?1.oh-package.json5=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E8=87=B32.0.1=202.changlog.md=20?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E7=89=88=E6=9C=AC2.0.1=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=9A=84=E8=8B=A5=E5=B9=B2=E9=97=AE=E9=A2=98=E5=8E=9F=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoulisheng1 --- PullToRefresh/oh-package.json5 | 2 +- changelog.md | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/PullToRefresh/oh-package.json5 b/PullToRefresh/oh-package.json5 index 9f0a576..9b8c05a 100644 --- a/PullToRefresh/oh-package.json5 +++ b/PullToRefresh/oh-package.json5 @@ -14,7 +14,7 @@ "main": "index.ets", "repository": "https://gitee.com/openharmony-sig/PullToRefresh", "type": "module", - "version": "2.0.0", + "version": "2.0.1", "dependencies": {}, "tags": [ "UI" diff --git a/changelog.md b/changelog.md index 4957db4..94e959b 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,14 @@ +## 2.0.1 + +1.修复上拉加载后上划到顶部无法触发下拉加载的问题。 +2.修复在TabContent组件中使用PullToRefresh,Tab无法左右滑动的问题。 +3.修复在PullToRefresh顶部的时候,上拉手势误触发下拉刷新的回弹动画效果问题。 + ## 2.0.0 -1.包管理工具由npm切换为ohpm -2.适配DevEco Studio: 3.1Beta2(3.1.0.400) -3.适配SDK: API9 Release(3.2.11.9) +1.包管理工具由npm切换为ohpm。 +2.适配DevEco Studio: 3.1Beta2(3.1.0.400)。 +3.适配SDK: API9 Release(3.2.11.9)。 ## 1.0.2 -- Gitee