yuanfeiyang3_wd

feat: bug-18383 动态详情页,添加自动定位评论区域位置功能

@@ -6,6 +6,8 @@ import { @@ -6,6 +6,8 @@ import {
6 NumberFormatterUtils, 6 NumberFormatterUtils,
7 DisplayUtils, 7 DisplayUtils,
8 NetworkUtil, 8 NetworkUtil,
  9 + EmitterUtils,
  10 + EmitterEventId,
9 FastClickUtil 11 FastClickUtil
10 } from 'wdKit'; 12 } from 'wdKit';
11 import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel'; 13 import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel';
@@ -45,6 +47,7 @@ import { detailedSkeleton } from './skeleton/detailSkeleton'; @@ -45,6 +47,7 @@ import { detailedSkeleton } from './skeleton/detailSkeleton';
45 import { viewBlogItemInsightIntentShare } from '../utils/InsightIntentShare' 47 import { viewBlogItemInsightIntentShare } from '../utils/InsightIntentShare'
46 import { common } from '@kit.AbilityKit'; 48 import { common } from '@kit.AbilityKit';
47 import { ParamType, TrackConstants, TrackingButton, TrackingContent } from 'wdTracking/Index'; 49 import { ParamType, TrackConstants, TrackingButton, TrackingContent } from 'wdTracking/Index';
  50 +import { componentUtils, window } from '@kit.ArkUI';
48 const TAG = 'DynamicDetailComponent' 51 const TAG = 'DynamicDetailComponent'
49 const PATTERN_DATE_CN_RN: string = 'yyyy年MM月dd日 HH:mm'; 52 const PATTERN_DATE_CN_RN: string = 'yyyy年MM月dd日 HH:mm';
50 53
@@ -79,6 +82,8 @@ export struct DynamicDetailComponent { @@ -79,6 +82,8 @@ export struct DynamicDetailComponent {
79 @State operationButtonList: string[] = [] 82 @State operationButtonList: string[] = []
80 @State likesStyle: number | string = 1 // 赞样式 1红心(点赞) 2大拇指(祈福) 3蜡烛(默哀) 4置空 83 @State likesStyle: number | string = 1 // 赞样式 1红心(点赞) 2大拇指(祈福) 3蜡烛(默哀) 4置空
81 @State openLikes: boolean = false // 是否可以点赞 1:可以 0:不可以 84 @State openLikes: boolean = false // 是否可以点赞 1:可以 0:不可以
  85 + @State offsetY: number = 0
  86 + @State isScrollTop: boolean = true
82 87
83 pageParam: ParamType = {} 88 pageParam: ParamType = {}
84 commentListAreaInfo?: Area 89 commentListAreaInfo?: Area
@@ -91,6 +96,27 @@ export struct DynamicDetailComponent { @@ -91,6 +96,27 @@ export struct DynamicDetailComponent {
91 // 内容用 点赞样式 1红心(点赞) 2大拇指(祈福) 3蜡烛(默哀) 4置空 96 // 内容用 点赞样式 1红心(点赞) 2大拇指(祈福) 3蜡烛(默哀) 4置空
92 this.likesStyle = this.contentDetailData.likesStyle 97 this.likesStyle = this.contentDetailData.likesStyle
93 this.openLikes = this.contentDetailData.openLikes == 1 ? true : false 98 this.openLikes = this.contentDetailData.openLikes == 1 ? true : false
  99 +
  100 + //注册通知,来自别的组件的评论成功通知
  101 + EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, (targetId?: string) => {
  102 + if (targetId) {
  103 + if (targetId == this.publishCommentModel.targetId) {
  104 + // 滚动到评论列表
  105 + if (this.commentListAreaInfo) {
  106 + // let height = DisplayUtils.getDeviceHeight() / 2
  107 + let offSetY = this.commentListAreaInfo?.globalPosition.y as number
  108 + Logger.debug(TAG, "滚动至yOffset: " + (offSetY - 100))
  109 + //头部距离48
  110 + this.scroller.scrollTo({
  111 + yOffset: offSetY - 100,
  112 + xOffset: 0,
  113 + animation: { duration: 1000, curve: Curve.Ease }
  114 + })
  115 + }
  116 + }
  117 + }
  118 + })
  119 +
94 } 120 }
95 121
96 onPageHide() { 122 onPageHide() {
@@ -577,8 +603,28 @@ export struct DynamicDetailComponent { @@ -577,8 +603,28 @@ export struct DynamicDetailComponent {
577 publishCommentModel: this.publishCommentModel, 603 publishCommentModel: this.publishCommentModel,
578 operationButtonList: this.operationButtonList, 604 operationButtonList: this.operationButtonList,
579 styleType: 1, 605 styleType: 1,
  606 + onCommentIconClick:()=>{
  607 + const info = componentUtils.getRectangleById('comment');
  608 + console.log(JSON.stringify(info))
  609 +
  610 + if (!this.offsetY) {
  611 + this.offsetY = componentUtils.getRectangleById('comment').windowOffset.y
  612 + }
  613 + // 定位到评论区域
  614 + if (this.isScrollTop) {
  615 + this.scroller.scrollTo({
  616 + xOffset: 0,
  617 + yOffset: this.offsetY,
  618 + animation: true
  619 + })
  620 + } else {
  621 + this.scroller.scrollEdge(Edge.Top)
  622 + }
  623 + this.isScrollTop = !this.isScrollTop
  624 + }
580 }) 625 })
581 .height(100) 626 .height(100)
  627 +
582 } 628 }
583 .margin({bottom: 65}) 629 .margin({bottom: 65})
584 } 630 }