提交 0ab1f949 编写于 作者: O openharmony_ci 提交者: Gitee

!341 修复UIList滑到端点后再反复滑出现严重回弹问题

Merge pull request !341 from YueBiang/drag_master
......@@ -198,7 +198,7 @@ void UIAbstractScroll::StopAnimator()
isDragging_ = false;
}
bool UIAbstractScroll::DragThrowAnimator(Point currentPos, Point lastPos)
bool UIAbstractScroll::DragThrowAnimator(Point currentPos, Point lastPos, uint8_t dragDirection)
{
if (!throwDrag_ && (reboundSize_ == 0)) {
return false;
......@@ -206,7 +206,7 @@ bool UIAbstractScroll::DragThrowAnimator(Point currentPos, Point lastPos)
int16_t dragDistanceX = 0;
int16_t dragDistanceY = 0;
if (throwDrag_) {
CalculateDragDistance(currentPos, lastPos, dragDistanceX, dragDistanceY);
CalculateDragDistance(currentPos, lastPos, dragDirection, dragDistanceX, dragDistanceY);
}
if (reboundSize_ != 0) {
CalculateReboundDistance(dragDistanceX, dragDistanceY);
......@@ -230,14 +230,15 @@ void UIAbstractScroll::StartAnimator(int16_t dragDistanceX, int16_t dragDistance
void UIAbstractScroll::CalculateDragDistance(Point currentPos,
Point lastPos,
uint8_t dragDirection,
int16_t& dragDistanceX,
int16_t& dragDistanceY)
{
if ((direction_ == VERTICAL) || (direction_ == HORIZONTAL_AND_VERTICAL)) {
dragDistanceY = (currentPos.y - lastPos.y) * DRAG_DISTANCE_COEFFICIENT;
if (dragDistanceY > 0) {
if (dragDistanceY > 0 || (dragDistanceY == 0 && dragDirection == DragEvent::DIRECTION_TOP_TO_BOTTOM)) {
dragDistanceY += GetMaxDeltaY() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
} else {
} else if (dragDistanceY < 0 || (dragDistanceY == 0 && dragDirection == DragEvent::DIRECTION_BOTTOM_TO_TOP)) {
dragDistanceY -= GetMaxDeltaY() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
}
}
......
......@@ -223,7 +223,7 @@ bool UIList::OnDragEndEvent(const DragEvent& event)
current = event.GetCurrentPos();
}
isReCalculateDragEnd_ = false;
if (!DragThrowAnimator(current, last)) {
if (!DragThrowAnimator(current, last, event.GetDragDirection())) {
if (scrollListener_ && (scrollListener_->GetScrollState() == ListScrollListener::SCROLL_STATE_MOVE)) {
scrollListener_->SetScrollState(ListScrollListener::SCROLL_STATE_STOP);
scrollListener_->OnScrollEnd(onSelectedIndex_, onSelectedView_);
......@@ -267,6 +267,16 @@ bool UIList::OnRotateEndEvent(const RotateEvent& event)
needVibration_ = false;
isReCalculateDragEnd_ = false;
for (uint8_t i = 0; i < MAX_DELTA_Y_SIZE; i++) {
lastDeltaY_[i] = 0;
}
uint8_t dir;
if (direction_ == VERTICAL) {
dir = (lastRotateLen_ >= 0) ? DragEvent::DIRECTION_TOP_TO_BOTTOM : DragEvent::DIRECTION_BOTTOM_TO_TOP;
} else {
dir = (lastRotateLen_ >= 0) ? DragEvent::DIRECTION_LEFT_TO_RIGHT : DragEvent::DIRECTION_RIGHT_TO_LEFT;
}
bool triggerAnimator = (MATH_ABS(lastRotateLen_) >= (GetWidth() / threshold_)) ||
(MATH_ABS(lastRotateLen_) >= (GetHeight() / threshold_));
if (throwDrag_ && triggerAnimator) {
......@@ -276,9 +286,9 @@ bool UIList::OnRotateEndEvent(const RotateEvent& event)
} else {
current = {lastRotateLen_, 0};
}
DragThrowAnimator(current, {0, 0});
DragThrowAnimator(current, {0, 0}, dir);
} else {
DragThrowAnimator({0, 0}, {0, 0});
DragThrowAnimator({0, 0}, {0, 0}, dir);
}
lastRotateLen_ = 0;
return UIView::OnRotateEndEvent(event);
......
......@@ -67,7 +67,7 @@ bool UIScrollView::OnDragEndEvent(const DragEvent& event)
current = event.GetCurrentPos();
}
if (!DragThrowAnimator(current, last)) {
if (!DragThrowAnimator(current, last, event.GetDragDirection())) {
if (scrollListener_ && (scrollListener_->GetScrollState() == OnScrollListener::SCROLL_STATE_MOVE)) {
scrollListener_->OnScrollEnd();
scrollListener_->SetScrollState(OnScrollListener::SCROLL_STATE_STOP);
......@@ -143,6 +143,15 @@ bool UIScrollView::OnRotateEvent(const RotateEvent& event)
bool UIScrollView::OnRotateEndEvent(const RotateEvent& event)
{
for (uint8_t i = 0; i < MAX_DELTA_Y_SIZE; i++) {
lastDeltaY_[i] = 0;
}
uint8_t dir;
if (direction_ == VERTICAL) {
dir = (lastRotateLen_ >= 0) ? DragEvent::DIRECTION_TOP_TO_BOTTOM : DragEvent::DIRECTION_BOTTOM_TO_TOP;
} else {
dir = (lastRotateLen_ >= 0) ? DragEvent::DIRECTION_LEFT_TO_RIGHT : DragEvent::DIRECTION_RIGHT_TO_LEFT;
}
bool triggerAnimator = (MATH_ABS(lastRotateLen_) >= (GetWidth() / threshold_)) ||
(MATH_ABS(lastRotateLen_) >= (GetHeight() / threshold_));
if (throwDrag_ && triggerAnimator) {
......@@ -152,9 +161,9 @@ bool UIScrollView::OnRotateEndEvent(const RotateEvent& event)
} else {
current = {lastRotateLen_, 0};
}
DragThrowAnimator(current, {0, 0});
DragThrowAnimator(current, {0, 0}, dir);
} else {
DragThrowAnimator({0, 0}, {0, 0});
DragThrowAnimator({0, 0}, {0, 0}, dir);
}
lastRotateLen_ = 0;
return UIView::OnRotateEndEvent(event);
......
......@@ -348,7 +348,7 @@ protected:
int16_t previousValueY_;
};
bool DragThrowAnimator(Point currentPos, Point lastPos);
bool DragThrowAnimator(Point currentPos, Point lastPos, uint8_t dragDirection);
virtual void StopAnimator();
virtual bool DragXInner(int16_t distance) = 0;
virtual bool DragYInner(int16_t distance) = 0;
......@@ -358,7 +358,8 @@ protected:
deltaYIndex_++;
}
void CalculateDragDistance(Point currentPos, Point lastPos, int16_t& dragDistanceX, int16_t& dragDistanceY);
void CalculateDragDistance(Point currentPos, Point lastPos, uint8_t dragDirection,
int16_t& dragDistanceX, int16_t& dragDistanceY);
void StartAnimator(int16_t dragDistanceX, int16_t dragDistanceY);
virtual void CalculateReboundDistance(int16_t& dragDistanceX, int16_t& dragDistanceY) {};
int16_t GetMaxDeltaY() const;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册