chenquansheng

fix |> 修复在新闻详情页评论后自动弹回详情页顶部问题

... ... @@ -5,6 +5,7 @@ import {
EmitterUtils,
EmitterEventId,
NetworkUtil,
DisplayUtils
} from 'wdKit';
import {
Action,
... ... @@ -65,6 +66,9 @@ export struct ImageAndTextPageComponent {
@State isScrollTop: boolean = true
@State offsetY: number = 0
@State executedStartTime: number = new Date().getTime()
private screenHeight: number = 0
private topHeight: number = 32
private bottomHeight: number = 150
pageShowTime:number = 0;
pageHideTime:number = 0;
lastTimeoutId?: number
... ... @@ -160,7 +164,7 @@ export struct ImageAndTextPageComponent {
.onAreaChange((oldValue: Area, newValue: Area) => {
this.info = newValue
console.log(TAG, "总页面滑动偏移量", this.scroller.currentOffset().yOffset)
this.checkToScrollCommentArea()
})
// .onMeasureSize()
... ... @@ -206,7 +210,7 @@ export struct ImageAndTextPageComponent {
styleType: 1,
onCommentIconClick: () => {
const info = componentUtils.getRectangleById('comment');
console.log(JSON.stringify(info))
console.log(TAG, "点击滑动页面", JSON.stringify(info))
if (!this.offsetY) {
this.offsetY = componentUtils.getRectangleById('comment').windowOffset.y
... ... @@ -229,7 +233,7 @@ export struct ImageAndTextPageComponent {
.position({y:'85%'})
.width(CommonConstants.FULL_WIDTH)
.backgroundColor(Color.White)
.height(150)
.height(this.bottomHeight)
// 发布时间
Column() {
... ... @@ -244,7 +248,7 @@ export struct ImageAndTextPageComponent {
}
}
.width(CommonConstants.FULL_WIDTH)
.height(32)
.height(this.topHeight)
.padding({ left: 15, right: 15, })
.justifyContent(FlexAlign.SpaceBetween)
.alignItems(VerticalAlign.Bottom)
... ... @@ -444,6 +448,7 @@ export struct ImageAndTextPageComponent {
aboutToAppear() {
this.getDetail()
this.screenHeight = DisplayUtils.getDeviceHeight()
//注册通知,来自别的组件的评论成功通知
EmitterUtils.receiveEvent(EmitterEventId.COMMENT_PUBLISH, (targetId?: string) => {
if (targetId) {
... ... @@ -451,11 +456,22 @@ export struct ImageAndTextPageComponent {
// 滚动到评论列表
if (this.info) {
// let height = DisplayUtils.getDeviceHeight() / 2
let offSetY = this.info?.globalPosition.y as number
Logger.debug(TAG, "滚动至yOffset: " + (offSetY - 100))
//评论区当前位置
let currentCommonentOffSetY = this.info?.globalPosition.y as number
//当前页面滚动的位置
let currentScrollOffSetY = this.scroller.currentOffset().yOffset
if (currentCommonentOffSetY > 0 && currentCommonentOffSetY < (this.screenHeight-this.bottomHeight)){
return
}
let offSetY = currentScrollOffSetY
if (currentCommonentOffSetY > (this.screenHeight-this.bottomHeight) ) {
offSetY = currentCommonentOffSetY-200
}else {
offSetY = currentScrollOffSetY + currentCommonentOffSetY-100
}
//头部距离48
this.scroller.scrollTo({
yOffset: offSetY - 100,
yOffset: offSetY,
xOffset: 0,
animation: { duration: 1000, curve: Curve.Ease }
})
... ...