Showing
2 changed files
with
106 additions
and
11 deletions
| @@ -2,7 +2,7 @@ import { CommonConstants, ViewType } from 'wdConstant'; | @@ -2,7 +2,7 @@ import { CommonConstants, ViewType } from 'wdConstant'; | ||
| 2 | import { Logger } from 'wdKit'; | 2 | import { Logger } from 'wdKit'; |
| 3 | import { EmptyComponent } from '../view/EmptyComponent'; | 3 | import { EmptyComponent } from '../view/EmptyComponent'; |
| 4 | import PageModel from '../../viewmodel/PageModel'; | 4 | import PageModel from '../../viewmodel/PageModel'; |
| 5 | -import { autoRefresh, listTouchEvent } from '../../utils/PullDownRefresh'; | 5 | +import { autoRefresh, onActionEnd, onActionStart, onActionUpdate } from '../../utils/PullDownRefresh'; |
| 6 | import LoadMoreLayout from './LoadMoreLayout'; | 6 | import LoadMoreLayout from './LoadMoreLayout'; |
| 7 | import { CompParser } from '../CompParser'; | 7 | import { CompParser } from '../CompParser'; |
| 8 | import { CompDTO } from 'wdBean'; | 8 | import { CompDTO } from 'wdBean'; |
| @@ -14,9 +14,6 @@ import PageNoMoreLayout from './PageNoMoreLayout'; | @@ -14,9 +14,6 @@ import PageNoMoreLayout from './PageNoMoreLayout'; | ||
| 14 | import { NoMoreBean } from './NoMoreBean'; | 14 | import { NoMoreBean } from './NoMoreBean'; |
| 15 | import { RefreshLayoutBean } from '../refresh/RefreshLayoutBean'; | 15 | import { RefreshLayoutBean } from '../refresh/RefreshLayoutBean'; |
| 16 | import RefreshLayout from '../refresh/RefreshLayout'; | 16 | import RefreshLayout from '../refresh/RefreshLayout'; |
| 17 | -import json from '@ohos.util.json'; | ||
| 18 | -import { viewBlogInsightIntentShare, ActionMode } from '../../utils/InsightIntentShare' | ||
| 19 | -import { common } from '@kit.AbilityKit'; | ||
| 20 | const TAG = 'PageComponent'; | 17 | const TAG = 'PageComponent'; |
| 21 | 18 | ||
| 22 | @Component | 19 | @Component |
| @@ -31,6 +28,7 @@ export struct PageComponent { | @@ -31,6 +28,7 @@ export struct PageComponent { | ||
| 31 | // 自动刷新通知 | 28 | // 自动刷新通知 |
| 32 | @Prop @Watch('onAutoRefresh') autoRefresh: number = 0 | 29 | @Prop @Watch('onAutoRefresh') autoRefresh: number = 0 |
| 33 | private listScroller: Scroller = new Scroller(); | 30 | private listScroller: Scroller = new Scroller(); |
| 31 | + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down }) | ||
| 34 | needload: boolean = true; | 32 | needload: boolean = true; |
| 35 | build() { | 33 | build() { |
| 36 | Column() { | 34 | Column() { |
| @@ -51,13 +49,26 @@ export struct PageComponent { | @@ -51,13 +49,26 @@ export struct PageComponent { | ||
| 51 | } | 49 | } |
| 52 | .width(CommonConstants.FULL_PARENT) | 50 | .width(CommonConstants.FULL_PARENT) |
| 53 | .height(CommonConstants.FULL_PARENT) | 51 | .height(CommonConstants.FULL_PARENT) |
| 54 | - .onTouch((event: TouchEvent | undefined) => { | ||
| 55 | - if (event) { | ||
| 56 | - if (this.pageModel.viewType === ViewType.LOADED) { | ||
| 57 | - listTouchEvent(this.pageModel, this.pageAdvModel, event); | ||
| 58 | - } | ||
| 59 | - } | 52 | + // .onTouch((event: TouchEvent | undefined) => { |
| 53 | + // if (event) { | ||
| 54 | + // if (this.pageModel.viewType === ViewType.LOADED) { | ||
| 55 | + // listTouchEvent(this.pageModel, this.pageAdvModel, event); | ||
| 56 | + // } | ||
| 57 | + // } | ||
| 58 | + // }) | ||
| 59 | + // 对接新的下拉刷新手势,替换touch事件 | ||
| 60 | + .parallelGesture( | ||
| 61 | + PanGesture(this.panOption) | ||
| 62 | + .onActionStart((event?: GestureEvent) => { | ||
| 63 | + onActionStart(this.pageModel, this.pageAdvModel, event) | ||
| 64 | + }) | ||
| 65 | + .onActionUpdate((event?: GestureEvent) => { | ||
| 66 | + onActionUpdate(this.pageModel, this.pageAdvModel, event) | ||
| 67 | + }) | ||
| 68 | + .onActionEnd(() => { | ||
| 69 | + onActionEnd(this.pageModel, this.pageAdvModel) | ||
| 60 | }) | 70 | }) |
| 71 | + ) | ||
| 61 | 72 | ||
| 62 | } | 73 | } |
| 63 | 74 |
| @@ -4,7 +4,87 @@ import PageModel from '../viewmodel/PageModel'; | @@ -4,7 +4,87 @@ import PageModel from '../viewmodel/PageModel'; | ||
| 4 | import PageHelper from '../viewmodel/PageHelper'; | 4 | import PageHelper from '../viewmodel/PageHelper'; |
| 5 | import PageAdModel from '../viewmodel/PageAdvModel'; | 5 | import PageAdModel from '../viewmodel/PageAdvModel'; |
| 6 | import { LoadStatus } from '../components/refresh/RefreshLayoutBean'; | 6 | import { LoadStatus } from '../components/refresh/RefreshLayoutBean'; |
| 7 | +import { Logger } from 'wdKit/Index'; | ||
| 8 | + | ||
| 9 | +/***********新的下拉、上拉手势 start **********/ | ||
| 10 | +export function onActionStart(pageModel: PageModel, pageAdvModel: PageAdModel, event?: GestureEvent) { | ||
| 11 | + if (event === undefined) { | ||
| 12 | + return | ||
| 13 | + } | ||
| 14 | + pageModel.downY = event.offsetY; | ||
| 15 | + pageModel.lastMoveY = event.offsetY; | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +export function onActionUpdate(pageModel: PageModel, pageAdvModel: PageAdModel, event?: GestureEvent) { | ||
| 19 | + if (event === undefined) { | ||
| 20 | + return | ||
| 21 | + } | ||
| 22 | + if ((pageModel.isRefreshing === true) || (pageModel.isLoading === true)) { | ||
| 23 | + return; | ||
| 24 | + } | ||
| 25 | + let isDownPull = event.offsetY - pageModel.lastMoveY > 0; | ||
| 26 | + if (((isDownPull === true) || (pageModel.isPullRefreshOperation === true)) && | ||
| 27 | + (pageModel.isCanLoadMore === false)) { | ||
| 28 | + actionUpdatePullRefresh(pageModel, event); | ||
| 29 | + } else { | ||
| 30 | + actionUpdateLoadMore(pageModel, event); | ||
| 31 | + } | ||
| 32 | + pageModel.lastMoveY = event.offsetY; | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +export function onActionEnd(pageModel: PageModel, pageAdvModel: PageAdModel) { | ||
| 36 | + if ((pageModel.isRefreshing === true) || (pageModel.isLoading === true)) { | ||
| 37 | + return; | ||
| 38 | + } | ||
| 39 | + if ((pageModel.isPullRefreshOperation === true)) { | ||
| 40 | + touchUpPullRefresh(pageModel, pageAdvModel); | ||
| 41 | + } else { | ||
| 42 | + // touchUpLoadMore(pageModel); | ||
| 43 | + } | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +export function actionUpdatePullRefresh(pageModel: PageModel, event: GestureEvent) { | ||
| 47 | + if (pageModel.startIndex === 0) { | ||
| 48 | + pageModel.isPullRefreshOperation = true; | ||
| 49 | + let height = vp2px(Const.CUSTOM_REFRESH_DECIDE_HEIGHT); | ||
| 50 | + pageModel.offsetY = event.offsetY - pageModel.downY; | ||
| 51 | + if (pageModel.offsetY >= height) { | ||
| 52 | + pullRefreshState(pageModel, RefreshState.Release); | ||
| 53 | + pageModel.offsetY = height + pageModel.offsetY * Const.Y_OFF_SET_COEFFICIENT; | ||
| 54 | + } else { | ||
| 55 | + pullRefreshState(pageModel, RefreshState.DropDown); | ||
| 56 | + } | ||
| 57 | + if (pageModel.offsetY < 0) { | ||
| 58 | + pageModel.offsetY = 0; | ||
| 59 | + pageModel.isPullRefreshOperation = false; | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +export function actionUpdateLoadMore(model: PageModel, event: GestureEvent) { | ||
| 65 | + // list size +1 | ||
| 66 | + if (model.endIndex >= model.compList.totalCount() - 3 && model.endIndex <= model.compList.totalCount()) { | ||
| 67 | + // model.offsetY = event.touches[0].y - model.downY; | ||
| 68 | + // if (Math.abs(model.offsetY) > vp2px(model.pullUpLoadHeight) / 2) { | ||
| 69 | + // model.isCanLoadMore = true; | ||
| 70 | + // model.isVisiblePullUpLoad = true; | ||
| 71 | + // model.offsetY = -vp2px(model.pullUpLoadHeight) + model.offsetY * Const.Y_OFF_SET_COEFFICIENT; | ||
| 72 | + // } | ||
| 73 | + | ||
| 74 | + // 不用分页动画,直接预加载 | ||
| 75 | + model.isCanLoadMore = true; | ||
| 76 | + model.isVisiblePullUpLoad = true; | ||
| 77 | + touchUpLoadMore(model); | ||
| 78 | + } | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +/***********新的下拉、上拉手势 end **********/ | ||
| 82 | + | ||
| 83 | + | ||
| 7 | //下拉刷新上拉加载更多组件 | 84 | //下拉刷新上拉加载更多组件 |
| 85 | +/** | ||
| 86 | + * @deprecated | ||
| 87 | + */ | ||
| 8 | export function listTouchEvent(pageModel: PageModel, pageAdvModel: PageAdModel, event: TouchEvent) { | 88 | export function listTouchEvent(pageModel: PageModel, pageAdvModel: PageAdModel, event: TouchEvent) { |
| 9 | switch (event.type) { | 89 | switch (event.type) { |
| 10 | case TouchType.Down: | 90 | case TouchType.Down: |
| @@ -16,7 +96,8 @@ export function listTouchEvent(pageModel: PageModel, pageAdvModel: PageAdModel, | @@ -16,7 +96,8 @@ export function listTouchEvent(pageModel: PageModel, pageAdvModel: PageAdModel, | ||
| 16 | return; | 96 | return; |
| 17 | } | 97 | } |
| 18 | let isDownPull = event.touches[0].y - pageModel.lastMoveY > 0; | 98 | let isDownPull = event.touches[0].y - pageModel.lastMoveY > 0; |
| 19 | - if (((isDownPull === true) || (pageModel.isPullRefreshOperation === true)) && (pageModel.isCanLoadMore === false)) { | 99 | + if (((isDownPull === true) || (pageModel.isPullRefreshOperation === true)) && |
| 100 | + (pageModel.isCanLoadMore === false)) { | ||
| 20 | // Finger movement, processing pull-down refresh. | 101 | // Finger movement, processing pull-down refresh. |
| 21 | touchMovePullRefresh(pageModel, event); | 102 | touchMovePullRefresh(pageModel, event); |
| 22 | } else { | 103 | } else { |
| @@ -44,6 +125,9 @@ export function listTouchEvent(pageModel: PageModel, pageAdvModel: PageAdModel, | @@ -44,6 +125,9 @@ export function listTouchEvent(pageModel: PageModel, pageAdvModel: PageAdModel, | ||
| 44 | } | 125 | } |
| 45 | } | 126 | } |
| 46 | 127 | ||
| 128 | +/** | ||
| 129 | + * @deprecated | ||
| 130 | + */ | ||
| 47 | export function touchMovePullRefresh(pageModel: PageModel, event: TouchEvent) { | 131 | export function touchMovePullRefresh(pageModel: PageModel, event: TouchEvent) { |
| 48 | if (pageModel.startIndex === 0) { | 132 | if (pageModel.startIndex === 0) { |
| 49 | pageModel.isPullRefreshOperation = true; | 133 | pageModel.isPullRefreshOperation = true; |
-
Please register or login to post a comment