ui_swipe_view.cpp 18.3 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "components/ui_swipe_view.h"
#include "dock/focus_manager.h"
Y
YueBiang 已提交
18
#include "dock/vibrator_manager.h"
Y
YueBiang 已提交
19 20
#include "gfx_utils/graphic_log.h"

M
mamingshuai 已提交
21 22
namespace OHOS {
UISwipeView::UISwipeView(uint8_t direction)
Y
YueBiang 已提交
23
    : swipeListener_(nullptr), curIndex_(0), blankSize_(DEFAULT_BLANK_SIZE), curView_(nullptr), loop_(false)
M
mamingshuai 已提交
24 25
{
#if ENABLE_ROTATE_INPUT
26
    rotateFactor_ = DEFAULT_SWIPE_VIEW_ROTATE_FACTOR;
M
mamingshuai 已提交
27 28 29 30 31 32
#endif
    direction_ = direction;
    tickTime_ = ANIMATOR_TIME;
    swipeAccCoefficient_ = DRAG_ACC_FACTOR;
}

P
pssea 已提交
33
UISwipeView::~UISwipeView() {}
M
mamingshuai 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

void UISwipeView::Add(UIView* view)
{
    if (view == nullptr) {
        return;
    }
    view->SetDragParentInstead(true);
    UIViewGroup::Add(view);
    SortChild();
    Invalidate();
}

void UISwipeView::Insert(UIView* prevView, UIView* insertView)
{
    if (insertView == nullptr) {
        return;
    }
    insertView->SetDragParentInstead(true);
    UIViewGroup::Insert(prevView, insertView);
    SortChild();
    Invalidate();
}

void UISwipeView::Remove(UIView* view)
{
    if (view == nullptr) {
        return;
    }
    UIViewGroup::Remove(view);
63 64 65
    if (curView_ == view) {
        curView_ = nullptr;
    }
M
mamingshuai 已提交
66 67 68 69
    SortChild();
    Invalidate();
}

L
liqiang 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
void UISwipeView::MoveHeadOrTailChild()
{
    if (loop_) {
        if (direction_ == HORIZONTAL) {
            while (childrenHead_->GetX() >= 0) {
                MoveLastChildToFirst();
            }
            while (childrenTail_->GetX() + childrenTail_->GetWidth() <= GetWidth()) {
                MoveFirstChildToLast();
            }
        } else {
            while (childrenHead_->GetY() >= 0) {
                MoveLastChildToFirst();
            }
            while (childrenTail_->GetY() + childrenTail_->GetHeight() <= GetHeight()) {
                MoveFirstChildToLast();
            }
        }
    }
}

M
mamingshuai 已提交
91 92
void UISwipeView::SetCurrentPage(uint16_t index, bool needAnimator)
{
L
liqiang 已提交
93 94 95
    if (needAnimator) {
        MoveHeadOrTailChild();
    }
M
mamingshuai 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    SwitchToPage(index, needAnimator);
    Invalidate();
}

bool UISwipeView::DragXInner(int16_t distance)
{
    if (distance == 0) {
        return true;
    }
    if (!loop_) {
        if ((distance > 0) && (childrenHead_ != nullptr)) {
            if (childrenHead_->GetX() >= blankSize_) {
                distance = 0;
            } else if (childrenHead_ && (childrenHead_->GetX() + distance > blankSize_)) {
                distance = blankSize_ - childrenHead_->GetX();
            }
        } else if (childrenTail_ != nullptr) {
            int16_t width = GetWidth();
            if (childrenTail_->GetRelativeRect().GetRight() < width - blankSize_) {
                distance = 0;
            } else if (width - (childrenTail_->GetX() + childrenTail_->GetWidth() + distance) > blankSize_) {
                distance = width - blankSize_ - childrenTail_->GetX() - childrenTail_->GetWidth();
            }
        }
    }
    CalculateInvalidate();
    MoveChildByOffset(distance, 0);
    CalculateInvalidate();
    return true;
}

bool UISwipeView::DragYInner(int16_t distance)
{
    if (distance == 0) {
        return true;
    }
    if (!loop_) {
        if ((distance > 0) && (childrenHead_ != nullptr)) {
            if (childrenHead_->GetY() >= blankSize_) {
                distance = 0;
            } else if ((childrenHead_ != nullptr) && (childrenHead_->GetY() + distance > blankSize_)) {
                distance = blankSize_ - childrenHead_->GetY();
            }
        } else if (childrenTail_ != nullptr) {
            int16_t height = GetHeight();
            if (childrenTail_->GetRelativeRect().GetBottom() < height - blankSize_) {
                distance = 0;
            } else if (height - (childrenTail_->GetY() + childrenTail_->GetHeight() + distance) > blankSize_) {
                distance = height - blankSize_ - childrenTail_->GetY() - childrenTail_->GetHeight();
            }
        }
    }
    CalculateInvalidate();
    MoveChildByOffset(0, distance);
    CalculateInvalidate();
    return true;
}

bool UISwipeView::OnDragEvent(const DragEvent& event)
{
    UIView* currentView = GetViewByIndex(curIndex_);
    if (currentView == nullptr) {
        return UIView::OnDragEvent(event);
    }
    if (scrollAnimator_.GetState() != Animator::STOP) {
        UIAbstractScroll::StopAnimator();
    }

    if (direction_ == HORIZONTAL) {
        DragXInner(event.GetDeltaX());
L
liqiang 已提交
166
        RefreshDelta(event.GetDeltaX());
167
        RefreshCurrentViewByPosition(&UIView::GetX, &UIView::GetWidthWithMargin);
M
mamingshuai 已提交
168 169
    } else {
        DragYInner(event.GetDeltaY());
L
liqiang 已提交
170
        RefreshDelta(event.GetDeltaY());
171
        RefreshCurrentViewByPosition(&UIView::GetY, &UIView::GetHeightWithMargin);
M
mamingshuai 已提交
172 173 174 175 176 177 178 179 180
    }
    return UIView::OnDragEvent(event);
}

bool UISwipeView::OnDragEndEvent(const DragEvent& event)
{
    int16_t distance = 0;
    if (direction_ == HORIZONTAL) {
        distance = event.GetCurrentPos().x - event.GetPreLastPoint().x;
181
        RefreshCurrentViewByThrow(distance, event.GetDragDirection(), &UIView::GetX, &UIView::GetWidthWithMargin);
M
mamingshuai 已提交
182 183
    } else {
        distance = event.GetCurrentPos().y - event.GetPreLastPoint().y;
184
        RefreshCurrentViewByThrow(distance, event.GetDragDirection(), &UIView::GetY, &UIView::GetHeightWithMargin);
M
mamingshuai 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197
    }

    if (curView_ == nullptr) {
        return UIView::OnDragEndEvent(event);
    }

    SwitchToPage(curIndex_);

    Invalidate();
    return UIView::OnDragEndEvent(event);
}

#if ENABLE_ROTATE_INPUT
Y
YueBiang 已提交
198

199 200
bool UISwipeView::OnRotateEvent(const RotateEvent& event)
{
G
guyuanzhang 已提交
201 202
    int16_t rotateLen = static_cast<int16_t>(event.GetRotate() * rotateFactor_);
    RefreshRotate(rotateLen);
203
    if (direction_ == HORIZONTAL) {
G
guyuanzhang 已提交
204
        DragXInner(rotateLen);
205 206
        RefreshCurrentViewByPosition(&UIView::GetX, &UIView::GetWidthWithMargin);
    } else {
G
guyuanzhang 已提交
207
        DragYInner(rotateLen);
208 209 210 211 212 213
        RefreshCurrentViewByPosition(&UIView::GetY, &UIView::GetHeightWithMargin);
    }

    return UIView::OnRotateEvent(event);
}

Y
YueBiang 已提交
214 215
bool UISwipeView::OnRotateEndEvent(const RotateEvent& event)
{
216
    uint8_t dir;
G
guyuanzhang 已提交
217
    int16_t lastRotateLen = GetMaxRotate();
218
    if (direction_ == HORIZONTAL) {
G
guyuanzhang 已提交
219
        dir = (lastRotateLen >= 0) ? DragEvent::DIRECTION_LEFT_TO_RIGHT : DragEvent::DIRECTION_RIGHT_TO_LEFT;
220
    } else {
G
guyuanzhang 已提交
221
        dir = (lastRotateLen >= 0) ? DragEvent::DIRECTION_TOP_TO_BOTTOM : DragEvent::DIRECTION_BOTTOM_TO_TOP;
222
    }
223
    if (direction_ == HORIZONTAL) {
G
guyuanzhang 已提交
224
        RefreshCurrentViewByThrow(lastRotateLen, dir, &UIView::GetX, &UIView::GetWidthWithMargin);
225
    } else {
G
guyuanzhang 已提交
226
        RefreshCurrentViewByThrow(lastRotateLen, dir, &UIView::GetY, &UIView::GetHeightWithMargin);
227
    }
228 229 230
    if (curView_ == nullptr) {
        return UIView::OnRotateEndEvent(event);
    }
Y
YueBiang 已提交
231
    SwitchToPage(curIndex_);
232
    isRotating_ = false;
Y
YueBiang 已提交
233
    return UIView::OnRotateEndEvent(event);
M
mamingshuai 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
}
#endif

UIView* UISwipeView::GetViewByIndex(uint16_t index) const
{
    UIView* child = childrenHead_;
    while (child != nullptr) {
        if (child->GetViewIndex() == index) {
            return child;
        }
        child = child->GetNextSibling();
    }
    return nullptr;
}

void UISwipeView::SetAnimatorTime(uint16_t time)
{
    tickTime_ = time / DEFAULT_TASK_PERIOD;
    if (tickTime_ == 0) {
        tickTime_ = 1;
    }
    animatorCallback_.SetDragTimes(tickTime_);
}

void UISwipeView::SwitchToPage(int16_t dst, bool needAnimator)
{
260
    if (IsNeedLoop()) {
M
mamingshuai 已提交
261 262 263 264 265 266 267 268 269 270 271 272
        dst = (dst + childrenNum_) % childrenNum_;
    } else if (dst < 0) {
        dst = 0;
    } else if (dst >= childrenNum_) {
        dst = childrenNum_ - 1;
    }

    UIView* dstView = GetViewByIndex(dst);
    if (dstView == nullptr) {
        return;
    }
    curIndex_ = dst;
273
    curView_ = dstView;
M
mamingshuai 已提交
274 275 276 277 278 279 280
    int16_t xOffset = 0;
    int16_t yOffset = 0;

    if (direction_ == HORIZONTAL) {
        if (alignMode_ == ALIGN_LEFT) {
            xOffset = -dstView->GetX();
        } else if (alignMode_ == ALIGN_RIGHT) {
281
            xOffset = GetWidth() - (dstView->GetX() + dstView->GetWidthWithMargin());
M
mamingshuai 已提交
282
        } else {
283
            xOffset = (GetWidth() >> 1) - (dstView->GetX() + (dstView->GetWidthWithMargin() >> 1));
M
mamingshuai 已提交
284 285
        }
    } else {
286
        yOffset = (GetHeight() >> 1) - (dstView->GetY() + (dstView->GetHeightWithMargin() >> 1));
M
mamingshuai 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
    }

    if ((xOffset != 0) || (yOffset != 0)) {
        if (scrollAnimator_.GetState() != Animator::STOP) {
            scrollAnimator_.Stop();
        }
        if (needAnimator) {
            animatorCallback_.SetDragTimes(tickTime_);
            animatorCallback_.SetDragStartValue(0, 0);
            animatorCallback_.SetDragEndValue(xOffset, yOffset);
            scrollAnimator_.Start();
        } else {
            MoveChildByOffset(xOffset, yOffset);
        }
    }
}

void UISwipeView::StopAnimator()
{
    UIAbstractScroll::StopAnimator();
    if (swipeListener_ != nullptr) {
        swipeListener_->OnSwipe(*this);
    }
}

void UISwipeView::SortChild()
{
    if (childrenHead_ == nullptr) {
        return;
    }
    int16_t index = 0;
    UIView* pre = childrenHead_;
    UIView* next = childrenHead_->GetNextSibling();
    if (direction_ == HORIZONTAL) {
        pre->SetX(0);
    } else {
        pre->SetY(0);
    }
    pre->SetViewIndex(index);
    index++;

    while (next != nullptr) {
        if (direction_ == HORIZONTAL) {
L
liqiang 已提交
330
            next->SetX(pre->GetRelativeRect().GetRight() + pre->GetStyle(STYLE_MARGIN_RIGHT) + 1);
M
mamingshuai 已提交
331
        } else {
L
liqiang 已提交
332
            next->SetY(pre->GetRelativeRect().GetBottom() + pre->GetStyle(STYLE_MARGIN_BOTTOM) + 1);
M
mamingshuai 已提交
333 334 335 336 337 338 339 340 341 342 343 344
        }
        pre = next;
        next->SetViewIndex(index);
        next = next->GetNextSibling();
        index++;
    }
    bool tmpLoop = loop_;
    loop_ = false;
    SwitchToPage(curIndex_, false);
    loop_ = tmpLoop;
}

345 346
void UISwipeView::RefreshCurrentViewByPosition(int16_t (UIView::*pfnGetXOrY)() const,
                                               int16_t (UIView::*pfnGetWidthOrHeight)())
M
mamingshuai 已提交
347 348 349 350 351 352 353
{
    if (childrenHead_ == nullptr) {
        curIndex_ = 0;
        curView_ = nullptr;
        return;
    }

354 355 356
#if ENABLE_VIBRATOR
    uint16_t lastIndex = curIndex_;
#endif
M
mamingshuai 已提交
357 358 359
    curIndex_ = 0;
    curView_ = nullptr;

360 361 362 363
    /*
     * It needs to be modified that swipemid should be calculated by the width and height of the current
     * sub view itself, not the width and height of the parent, especially for ALIGN_LEFT and ALIGN_RIGHT.
     */
M
mamingshuai 已提交
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
    uint16_t swipeMid;
    if (alignMode_ == ALIGN_LEFT) {
        swipeMid = 0;
    } else if (alignMode_ == ALIGN_RIGHT) {
        swipeMid = (this->*pfnGetWidthOrHeight)();
    } else {
        swipeMid = (this->*pfnGetWidthOrHeight)() >> 1;
    }
    UIView* view = childrenHead_;

    if ((childrenHead_->*pfnGetXOrY)() > swipeMid) {
        curIndex_ = childrenHead_->GetViewIndex();
        curView_ = childrenHead_;
    } else if ((childrenTail_->*pfnGetXOrY)() + (childrenHead_->*pfnGetWidthOrHeight)() < swipeMid) {
        curIndex_ = childrenTail_->GetViewIndex();
        curView_ = childrenTail_;
    } else {
        while (view != nullptr) {
            if ((swipeMid >= (view->*pfnGetXOrY)()) &&
                (swipeMid <= (view->*pfnGetXOrY)() + (view->*pfnGetWidthOrHeight)())) {
                curIndex_ = view->GetViewIndex();
                curView_ = view;
                break;
            }
            view = view->GetNextSibling();
        }
    }
391 392 393 394 395 396 397 398 399 400 401 402
#if ENABLE_VIBRATOR
    if (lastIndex != curIndex_) {
        Vibrator();
    }
#endif
}

void UISwipeView::RefreshCurrentViewByThrow(int16_t distance,
                                            uint8_t dragDirection,
                                            int16_t (UIView::*pfnGetXOrY)() const,
                                            int16_t (UIView::*pfnGetWidthOrHeight)())
{
M
mamingshuai 已提交
403 404 405
    if (curView_ == nullptr) {
        return;
    }
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
#if ENABLE_VIBRATOR
    uint16_t lastIndex = curIndex_;
#endif

    /*
     * It needs to be modified that swipemid should be calculated by the width and height of the current
     * sub view itself, not the width and height of the parent, especially for ALIGN_LEFT and ALIGN_RIGHT.
     */
    uint16_t swipeMid;
    if (alignMode_ == ALIGN_LEFT) {
        swipeMid = 0;
    } else if (alignMode_ == ALIGN_RIGHT) {
        swipeMid = (this->*pfnGetWidthOrHeight)();
    } else {
        swipeMid = (this->*pfnGetWidthOrHeight)() >> 1;
    }
M
mamingshuai 已提交
422

L
liqiang 已提交
423
    int16_t accelerationOffset = GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
M
mamingshuai 已提交
424 425 426 427 428 429
    if (distance < 0) {
        /*
         * 7, 10 : Check whether the current view is dragged by more than 1/5,
         * that is, the x or y coordinate plus 7/10 width or height.
         */
        if (((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() >> 1) < swipeMid) &&
Y
YueBiang 已提交
430
            ((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() * 7 / 10) - accelerationOffset <
431 432
             swipeMid)) {
            CurrentIndexInc();
M
mamingshuai 已提交
433 434 435 436 437 438 439
        }
    } else if (distance > 0) {
        /*
         * 3, 10 : Check whether the current view is dragged by more than 1/5,
         * that is, the x or y coordinate plus 3/10 width or height.
         */
        if (((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() >> 1) > swipeMid) &&
Y
YueBiang 已提交
440
            ((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() * 3 / 10) + accelerationOffset >
441 442
             swipeMid)) {
            CurrentIndexDec();
M
mamingshuai 已提交
443 444 445 446
        }
    } else {
        if (alignMode_ == ALIGN_LEFT) {
            if (((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() >> 1) < swipeMid)) {
447
                CurrentIndexInc();
M
mamingshuai 已提交
448 449 450
            }
        } else if (alignMode_ == ALIGN_RIGHT) {
            if ((curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() >> 1) > swipeMid) {
451
                CurrentIndexDec();
M
mamingshuai 已提交
452
            }
453 454 455 456 457 458 459 460 461
        } else {
            /*
             * If the absolute value of the offset is greater than the page turning threshold,
             * page turning is considered.
             */
            int16_t offset = (curView_->*pfnGetXOrY)() + ((curView_->*pfnGetWidthOrHeight)() >> 1) - swipeMid;
            int16_t threshold = (this->*pfnGetWidthOrHeight)() >> 2; // 2: 1/4 width or height
            if (offset > threshold && (dragDirection == DragEvent::DIRECTION_TOP_TO_BOTTOM ||
                                       dragDirection == DragEvent::DIRECTION_LEFT_TO_RIGHT)) {
462
                CurrentIndexDec();
463 464
            } else if ((offset < -threshold) && (dragDirection == DragEvent::DIRECTION_BOTTOM_TO_TOP ||
                                                 dragDirection == DragEvent::DIRECTION_RIGHT_TO_LEFT)) {
465
                CurrentIndexInc();
466
            }
M
mamingshuai 已提交
467 468
        }
    }
L
liqiang 已提交
469
    curView_ = GetViewByIndex(curIndex_);
Y
YueBiang 已提交
470
#if ENABLE_VIBRATOR
471 472
    if (lastIndex != curIndex_) {
        Vibrator();
Y
YueBiang 已提交
473 474
    }
#endif
M
mamingshuai 已提交
475 476 477 478 479
}

void UISwipeView::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
{
    UIViewGroup::MoveChildByOffset(xOffset, yOffset);
L
liqiang 已提交
480
    MoveHeadOrTailChild();
M
mamingshuai 已提交
481 482
}

483
bool UISwipeView::IsNeedLoop()
M
mamingshuai 已提交
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
{
    if (!loop_ || (childrenHead_ == nullptr) || (childrenTail_ == nullptr)) {
        return false;
    }
    Rect childRect = GetAllChildRelativeRect();
    if (direction_ == HORIZONTAL) {
        if ((childRect.GetWidth() - childrenHead_->GetWidth() >= GetWidth()) &&
            (childRect.GetWidth() - childrenTail_->GetWidth() >= GetWidth())) {
            return true;
        }
    } else {
        if ((childRect.GetHeight() - childrenHead_->GetHeight() >= GetHeight()) &&
            (childRect.GetHeight() - childrenTail_->GetHeight() >= GetHeight())) {
            return true;
        }
    }
    return false;
}

void UISwipeView::MoveFirstChildToLast()
{
    if ((childrenTail_ == nullptr) || (childrenHead_ == nullptr)) {
        return;
    }
    if (direction_ == HORIZONTAL) {
        childrenHead_->SetX(childrenTail_->GetX() + childrenTail_->GetWidth());
    } else {
        childrenHead_->SetY(childrenTail_->GetY() + childrenTail_->GetHeight());
    }
    UIView* head = childrenHead_;
    UIViewGroup::Remove(childrenHead_);
    UIViewGroup::Add(head);
}

void UISwipeView::MoveLastChildToFirst()
{
    if ((childrenTail_ == nullptr) || (childrenHead_ == nullptr)) {
        return;
    }
    if (direction_ == HORIZONTAL) {
        childrenTail_->SetX(childrenHead_->GetX() - childrenTail_->GetWidth());
    } else {
        childrenTail_->SetY(childrenHead_->GetY() - childrenTail_->GetHeight());
    }
    UIView* last = childrenTail_;
    UIViewGroup::Remove(childrenTail_);
    UIViewGroup::Insert(nullptr, last);
}

void UISwipeView::CalculateInvalidate()
{
    Rect swipeRect(0, 0, GetRelativeRect().GetWidth() - 1, GetRelativeRect().GetHeight() - 1);
    UIView* view = childrenHead_;
    bool isFound = false;
    while (view != nullptr) {
        Rect rect = view->GetRelativeRect();
        if (rect.IsIntersect(swipeRect)) {
            if (view->IsVisible() && (view->GetOpaScale() != OPA_TRANSPARENT)) {
                view->Invalidate();
            }
            isFound = true;
        } else if (isFound) {
            return;
        }

        view = view->GetNextSibling();
    }
}
552 553 554

void UISwipeView::CurrentIndexInc()
{
555 556
    curIndex_++;
    if (curIndex_ > childrenNum_ - 1) {
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
        if (IsNeedLoop()) {
            curIndex_ = curIndex_ % childrenNum_;
        } else {
            curIndex_ = childrenNum_ - 1;
        }
    }
}

void UISwipeView::CurrentIndexDec()
{
    if (curIndex_ == 0) {
        if (IsNeedLoop()) {
            curIndex_ = childrenNum_ - 1;
        }
    } else {
        curIndex_--;
    }
}

#if ENABLE_VIBRATOR
void UISwipeView::Vibrator()
{
    VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
    if (vibratorFunc != nullptr && isRotating_) {
        if (!loop_ && (curIndex_ == 0 || curIndex_ == childrenNum_ - 1)) {
            GRAPHIC_LOGI("UISwipeView::Vibrator calls TYPE_THREE vibrator");
G
guyuanzhang 已提交
583
            vibratorFunc(VibratorType::VIBRATOR_TYPE_THREE);
584 585
        } else {
            GRAPHIC_LOGI("UISwipeView::Vibrator calls TYPE_ONE vibrator");
G
guyuanzhang 已提交
586
            vibratorFunc(VibratorType::VIBRATOR_TYPE_ONE);
587 588 589 590
        }
    }
}
#endif
M
mamingshuai 已提交
591
} // namespace OHOS