zhangbo1_wd

首页下拉刷新,结束加动画缓慢收起

@@ -11,14 +11,17 @@ export default struct CustomLayout { @@ -11,14 +11,17 @@ export default struct CustomLayout {
11 static readonly REFRESH_HEIGHT: number = 90; 11 static readonly REFRESH_HEIGHT: number = 90;
12 @ObjectLink @Watch('onOffsetChange') refreshBean: RefreshLayoutBean; 12 @ObjectLink @Watch('onOffsetChange') refreshBean: RefreshLayoutBean;
13 private mainRenderingSettings: RenderingContextSettings = new RenderingContextSettings(true) 13 private mainRenderingSettings: RenderingContextSettings = new RenderingContextSettings(true)
14 - private mainCanvasRenderingContext: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.mainRenderingSettings) 14 + private mainCanvasRenderingContext: CanvasRenderingContext2D =
  15 + new CanvasRenderingContext2D(this.mainRenderingSettings)
15 private mainRenderingSettings2: RenderingContextSettings = new RenderingContextSettings(true) 16 private mainRenderingSettings2: RenderingContextSettings = new RenderingContextSettings(true)
16 - private mainCanvasRenderingContext2: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.mainRenderingSettings2) 17 + private mainCanvasRenderingContext2: CanvasRenderingContext2D =
  18 + new CanvasRenderingContext2D(this.mainRenderingSettings2)
17 private animateItem: AnimationItem | null = null; 19 private animateItem: AnimationItem | null = null;
18 private animateItem2: AnimationItem | null = null; 20 private animateItem2: AnimationItem | null = null;
19 private animateName: string = "refresh"; 21 private animateName: string = "refresh";
20 private animateName2: string = "refreshing"; 22 private animateName2: string = "refreshing";
21 @State private layoutHeight: number = 0; 23 @State private layoutHeight: number = 0;
  24 + @State private textVisible: boolean = false
22 25
23 build() { 26 build() {
24 Stack({ alignContent: Alignment.Center }) { 27 Stack({ alignContent: Alignment.Center }) {
@@ -58,8 +61,13 @@ export default struct CustomLayout { @@ -58,8 +61,13 @@ export default struct CustomLayout {
58 .fontColor('#676767') 61 .fontColor('#676767')
59 .backgroundColor('#f6f6f6') 62 .backgroundColor('#f6f6f6')
60 .borderRadius(20) 63 .borderRadius(20)
61 - .padding({ left: 19, right: 19, top: 10, bottom: 10 })  
62 - .visibility(this.refreshBean.loadStatus != LoadStatus.LOADED ? Visibility.Hidden : Visibility.Visible) 64 + .padding({
  65 + left: 19,
  66 + right: 19,
  67 + top: 10,
  68 + bottom: 10
  69 + })
  70 + .visibility(this.textVisible ? Visibility.Visible : Visibility.Hidden)
63 71
64 } 72 }
65 .clip(true) 73 .clip(true)
@@ -130,15 +138,32 @@ export default struct CustomLayout { @@ -130,15 +138,32 @@ export default struct CustomLayout {
130 let maxH = CustomLayout.REFRESH_HEIGHT 138 let maxH = CustomLayout.REFRESH_HEIGHT
131 let tmpHeight = this.refreshBean.offset > maxH ? maxH : this.refreshBean.offset 139 let tmpHeight = this.refreshBean.offset > maxH ? maxH : this.refreshBean.offset
132 if (this.refreshBean.loadStatus === LoadStatus.LOADED) { 140 if (this.refreshBean.loadStatus === LoadStatus.LOADED) {
  141 + this.textVisible = true
133 if (tmpHeight <= 0) { 142 if (tmpHeight <= 0) {
134 setTimeout(() => { 143 setTimeout(() => {
135 // 延时设置0,让“已更新到最新”展示 144 // 延时设置0,让“已更新到最新”展示
136 - this.layoutHeight = 0  
137 - }, 1500) 145 + this.textVisible = false
  146 + this.setHeight0WithAnimation()
  147 + }, 800)
138 } 148 }
139 } else { 149 } else {
140 // 直接设置高度 150 // 直接设置高度
141 this.layoutHeight = tmpHeight 151 this.layoutHeight = tmpHeight
142 } 152 }
143 } 153 }
  154 +
  155 + /**
  156 + * 下拉刷新UI,高度慢慢变为0
  157 + */
  158 + setHeight0WithAnimation() {
  159 + // this.layoutHeight = 0
  160 + animateTo({
  161 + duration: 500, // 动画时长
  162 + curve: Curve.Linear, // 动画曲线
  163 + iterations: 1, // 播放次数
  164 + playMode: PlayMode.Normal, // 动画模式
  165 + }, () => {
  166 + this.layoutHeight = 0
  167 + })
  168 + }
144 } 169 }
@@ -24,7 +24,7 @@ export class RefreshConstants { @@ -24,7 +24,7 @@ export class RefreshConstants {
24 */ 24 */
25 static readonly RefreshConstant_DELAY_PULL_DOWN_REFRESH: number = 50; 25 static readonly RefreshConstant_DELAY_PULL_DOWN_REFRESH: number = 50;
26 static readonly RefreshConstant_CLOSE_PULL_DOWN_REFRESH_TIME: number = 150; 26 static readonly RefreshConstant_CLOSE_PULL_DOWN_REFRESH_TIME: number = 150;
27 - static readonly RefreshConstant_DELAY_SHRINK_ANIMATION_TIME: number = 500; 27 + static readonly RefreshConstant_DELAY_SHRINK_ANIMATION_TIME: number = 1500;
28 28
29 /** 29 /**
30 * The page size. 30 * The page size.