Showing
1 changed file
with
23 additions
and
7 deletions
| @@ -5,6 +5,7 @@ import { | @@ -5,6 +5,7 @@ import { | ||
| 5 | EmitterUtils, | 5 | EmitterUtils, |
| 6 | EmitterEventId, | 6 | EmitterEventId, |
| 7 | NetworkUtil, | 7 | NetworkUtil, |
| 8 | + DisplayUtils | ||
| 8 | } from 'wdKit'; | 9 | } from 'wdKit'; |
| 9 | import { | 10 | import { |
| 10 | Action, | 11 | Action, |
| @@ -65,6 +66,9 @@ export struct ImageAndTextPageComponent { | @@ -65,6 +66,9 @@ export struct ImageAndTextPageComponent { | ||
| 65 | @State isScrollTop: boolean = true | 66 | @State isScrollTop: boolean = true |
| 66 | @State offsetY: number = 0 | 67 | @State offsetY: number = 0 |
| 67 | @State executedStartTime: number = new Date().getTime() | 68 | @State executedStartTime: number = new Date().getTime() |
| 69 | + private screenHeight: number = 0 | ||
| 70 | + private topHeight: number = 32 | ||
| 71 | + private bottomHeight: number = 150 | ||
| 68 | pageShowTime:number = 0; | 72 | pageShowTime:number = 0; |
| 69 | pageHideTime:number = 0; | 73 | pageHideTime:number = 0; |
| 70 | lastTimeoutId?: number | 74 | lastTimeoutId?: number |
| @@ -160,7 +164,7 @@ export struct ImageAndTextPageComponent { | @@ -160,7 +164,7 @@ export struct ImageAndTextPageComponent { | ||
| 160 | 164 | ||
| 161 | .onAreaChange((oldValue: Area, newValue: Area) => { | 165 | .onAreaChange((oldValue: Area, newValue: Area) => { |
| 162 | this.info = newValue | 166 | this.info = newValue |
| 163 | - | 167 | + console.log(TAG, "总页面滑动偏移量", this.scroller.currentOffset().yOffset) |
| 164 | this.checkToScrollCommentArea() | 168 | this.checkToScrollCommentArea() |
| 165 | }) | 169 | }) |
| 166 | // .onMeasureSize() | 170 | // .onMeasureSize() |
| @@ -206,7 +210,7 @@ export struct ImageAndTextPageComponent { | @@ -206,7 +210,7 @@ export struct ImageAndTextPageComponent { | ||
| 206 | styleType: 1, | 210 | styleType: 1, |
| 207 | onCommentIconClick: () => { | 211 | onCommentIconClick: () => { |
| 208 | const info = componentUtils.getRectangleById('comment'); | 212 | const info = componentUtils.getRectangleById('comment'); |
| 209 | - console.log(JSON.stringify(info)) | 213 | + console.log(TAG, "点击滑动页面", JSON.stringify(info)) |
| 210 | 214 | ||
| 211 | if (!this.offsetY) { | 215 | if (!this.offsetY) { |
| 212 | this.offsetY = componentUtils.getRectangleById('comment').windowOffset.y | 216 | this.offsetY = componentUtils.getRectangleById('comment').windowOffset.y |
| @@ -229,7 +233,7 @@ export struct ImageAndTextPageComponent { | @@ -229,7 +233,7 @@ export struct ImageAndTextPageComponent { | ||
| 229 | .position({y:'85%'}) | 233 | .position({y:'85%'}) |
| 230 | .width(CommonConstants.FULL_WIDTH) | 234 | .width(CommonConstants.FULL_WIDTH) |
| 231 | .backgroundColor(Color.White) | 235 | .backgroundColor(Color.White) |
| 232 | - .height(150) | 236 | + .height(this.bottomHeight) |
| 233 | 237 | ||
| 234 | // 发布时间 | 238 | // 发布时间 |
| 235 | Column() { | 239 | Column() { |
| @@ -244,7 +248,7 @@ export struct ImageAndTextPageComponent { | @@ -244,7 +248,7 @@ export struct ImageAndTextPageComponent { | ||
| 244 | } | 248 | } |
| 245 | } | 249 | } |
| 246 | .width(CommonConstants.FULL_WIDTH) | 250 | .width(CommonConstants.FULL_WIDTH) |
| 247 | - .height(32) | 251 | + .height(this.topHeight) |
| 248 | .padding({ left: 15, right: 15, }) | 252 | .padding({ left: 15, right: 15, }) |
| 249 | .justifyContent(FlexAlign.SpaceBetween) | 253 | .justifyContent(FlexAlign.SpaceBetween) |
| 250 | .alignItems(VerticalAlign.Bottom) | 254 | .alignItems(VerticalAlign.Bottom) |
| @@ -444,6 +448,7 @@ export struct ImageAndTextPageComponent { | @@ -444,6 +448,7 @@ export struct ImageAndTextPageComponent { | ||
| 444 | 448 | ||
| 445 | aboutToAppear() { | 449 | aboutToAppear() { |
| 446 | this.getDetail() | 450 | this.getDetail() |
| 451 | + this.screenHeight = DisplayUtils.getDeviceHeight() | ||
| 447 | //注册通知,来自别的组件的评论成功通知 | 452 | //注册通知,来自别的组件的评论成功通知 |
| 448 | EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, (targetId?: string) => { | 453 | EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, (targetId?: string) => { |
| 449 | if (targetId) { | 454 | if (targetId) { |
| @@ -451,11 +456,22 @@ export struct ImageAndTextPageComponent { | @@ -451,11 +456,22 @@ export struct ImageAndTextPageComponent { | ||
| 451 | // 滚动到评论列表 | 456 | // 滚动到评论列表 |
| 452 | if (this.info) { | 457 | if (this.info) { |
| 453 | // let height = DisplayUtils.getDeviceHeight() / 2 | 458 | // let height = DisplayUtils.getDeviceHeight() / 2 |
| 454 | - let offSetY = this.info?.globalPosition.y as number | ||
| 455 | - Logger.debug(TAG, "滚动至yOffset: " + (offSetY - 100)) | 459 | + //评论区当前位置 |
| 460 | + let currentCommonentOffSetY = this.info?.globalPosition.y as number | ||
| 461 | + //当前页面滚动的位置 | ||
| 462 | + let currentScrollOffSetY = this.scroller.currentOffset().yOffset | ||
| 463 | + if (currentCommonentOffSetY > 0 && currentCommonentOffSetY < (this.screenHeight-this.bottomHeight)){ | ||
| 464 | + return | ||
| 465 | + } | ||
| 466 | + let offSetY = currentScrollOffSetY | ||
| 467 | + if (currentCommonentOffSetY > (this.screenHeight-this.bottomHeight) ) { | ||
| 468 | + offSetY = currentCommonentOffSetY-200 | ||
| 469 | + }else { | ||
| 470 | + offSetY = currentScrollOffSetY + currentCommonentOffSetY-100 | ||
| 471 | + } | ||
| 456 | //头部距离48 | 472 | //头部距离48 |
| 457 | this.scroller.scrollTo({ | 473 | this.scroller.scrollTo({ |
| 458 | - yOffset: offSetY - 100, | 474 | + yOffset: offSetY, |
| 459 | xOffset: 0, | 475 | xOffset: 0, |
| 460 | animation: { duration: 1000, curve: Curve.Ease } | 476 | animation: { duration: 1000, curve: Curve.Ease } |
| 461 | }) | 477 | }) |
-
Please register or login to post a comment