提交 6441b10a 编写于 作者: O openharmony_ci 提交者: Gitee

!122 增加 UIList 自动对齐动画时间设置功能

Merge pull request !122 from guyuanzhang/scroll
......@@ -105,6 +105,7 @@ void UIAbstractScroll::StartAnimator(int16_t dragDistanceX, int16_t dragDistance
if (dragTimes < MIN_DRAG_TIMES) {
dragTimes = MIN_DRAG_TIMES;
}
animatorCallback_.RsetCallback();
animatorCallback_.SetDragStartValue(0, 0);
animatorCallback_.SetDragEndValue(dragDistanceX, dragDistanceY);
animatorCallback_.SetDragTimes(dragTimes * DRAG_ACC_FACTOR / GetDragACCLevel());
......@@ -146,7 +147,6 @@ void UIAbstractScroll::ListAnimatorCallback::Callback(UIView* view)
if (view == nullptr) {
return;
}
curtTime_++;
UIAbstractScroll* scrollView = static_cast<UIAbstractScroll*>(view);
scrollView->isDragging_ = true;
......@@ -174,9 +174,11 @@ void UIAbstractScroll::ListAnimatorCallback::Callback(UIView* view)
}
if (needStopX && needStopY) {
scrollView->StopAnimator();
} else {
curtTime_++;
}
} else {
scrollView->StopAnimator();
}
}
} // namespace OHOS
\ No newline at end of file
} // namespace OHOS
......@@ -99,41 +99,14 @@ void UIList::Recycle::FillActiveView()
}
}
UIList::UIList()
: onSelectedView_(nullptr),
isLoopList_(false),
isReCalculateDragEnd_(true),
autoAlign_(false),
startIndex_(0),
topIndex_(0),
bottomIndex_(0),
selectPosition_(0),
onSelectedIndex_(0),
recycle_(this),
scrollListener_(nullptr)
{
#if ENABLE_ROTATE_INPUT
rotateFactor_ = DEFAULT_ROTATE_FACTOR;
isRotating_ = false;
lastRotateLen_ = 0;
#endif
#if ENABLE_VIBRATOR
vibratorType_ = VibratorType::VIBRATOR_TYPE_ONE;
#endif
#if ENABLE_FOCUS_MANAGER
focusable_ = true;
#endif
direction_ = VERTICAL;
touchable_ = true;
draggable_ = true;
dragParentInstead_ = false;
}
UIList::UIList() : UIList(VERTICAL) {}
UIList::UIList(uint8_t direction)
: onSelectedView_(nullptr),
isLoopList_(false),
isReCalculateDragEnd_(true),
autoAlign_(false),
alignTime_(DEFAULT_ALINE_TIMES),
startIndex_(0),
topIndex_(0),
bottomIndex_(0),
......@@ -386,9 +359,10 @@ bool UIList::ReCalculateDragEnd()
// 2: half
offsetX = selectPosition_ - (onSelectedView_->GetX() + (onSelectedView_->GetRelativeRect().GetWidth() / 2));
}
animatorCallback_.RsetCallback();
animatorCallback_.SetDragStartValue(0, 0);
animatorCallback_.SetDragEndValue(offsetX, offsetY);
animatorCallback_.SetDragTimes(RECALCULATE_DRAG_TIMES * DRAG_ACC_FACTOR / GetDragACCLevel());
animatorCallback_.SetDragTimes(GetAutoAlignTime() / DEFAULT_TASK_PERIOD);
scrollAnimator_.Start();
isReCalculateDragEnd_ = true;
return true;
......
......@@ -362,6 +362,30 @@ public:
autoAlign_ = state;
}
/**
* @brief 设置自动对齐动画时长,单位为毫秒,默认为100毫秒。该功能依赖EnableAutoAlign()方法,自动对齐设置为true情况下才生效。
*
* @param value 自动对齐动画时长,0表示无动画。
* @since 3.0
* @version 3.0
*/
void SetAutoAlignTime(uint16_t time)
{
alignTime_ = time;
}
/**
* @brief 获取自动对齐动画时长。
*
* @return 自动对齐动画时长。
* @since 3.0
* @version 3.0
*/
uint16_t GetAutoAlignTime() const
{
return alignTime_;
}
void RemoveAll() override;
static constexpr int8_t NULL_SELECT_INDEX = -1;
......@@ -371,6 +395,7 @@ public:
protected:
static constexpr int16_t RECALCULATE_DRAG_DISTANCE = 10;
static constexpr int16_t RECALCULATE_DRAG_TIMES = 10;
static constexpr int16_t DEFAULT_ALINE_TIMES = 100;
void StopAnimator() override;
bool DragXInner(int16_t distance) override;
bool DragYInner(int16_t distance) override;
......@@ -442,6 +467,7 @@ private:
bool isLoopList_;
bool isReCalculateDragEnd_;
bool autoAlign_;
uint16_t alignTime_;
uint16_t startIndex_;
uint16_t topIndex_;
uint16_t bottomIndex_;
......
......@@ -102,6 +102,8 @@ void UITestUIList::TearDown()
setSelectOffBtn_ = nullptr;
setAutoAlignBtn_ = nullptr;
setAutoAlignOffBtn_ = nullptr;
setAutoAlignACCIncBtn_ = nullptr;
setAutoAlignACCDncBtn_ = nullptr;
lastX_ = 0;
lastY_ = 0;
}
......@@ -200,6 +202,13 @@ void UITestUIList::SetControlButton()
setAutoAlignOffBtn_ = new UILabelButton();
}
if (setAutoAlignACCIncBtn_ == nullptr) {
setAutoAlignACCIncBtn_ = new UILabelButton();
}
if (setAutoAlignACCDncBtn_ == nullptr) {
setAutoAlignACCDncBtn_ = new UILabelButton();
}
positionX_ += 5; // 5: increase y-coordinate
SetUpButton(setBlankBtn_, "开启blank");
SetUpButton(setBlankOffBtn_, "关闭blank");
......@@ -214,6 +223,8 @@ void UITestUIList::SetControlButton()
SetUpButton(setSelectOffBtn_, "关闭select");
SetUpButton(setAutoAlignBtn_, "开启自动对齐 ");
SetUpButton(setAutoAlignOffBtn_, "关闭自动对齐 ");
SetUpButton(setAutoAlignACCIncBtn_, "增加自动对齐时间 ");
SetUpButton(setAutoAlignACCDncBtn_, "减少自动对齐时间 ");
}
void UITestUIList::UIKit_List_Scroll_Test_Blank_Set_001()
......@@ -305,6 +316,12 @@ bool UITestUIList::OnClick(UIView& view, const ClickEvent& event)
currentList_->EnableAutoAlign(true);
} else if (&view == setAutoAlignOffBtn_) {
currentList_->EnableAutoAlign(false);
} else if (&view == setAutoAlignACCIncBtn_) {
autoAlignTime_ += ALINE_TIME_CHANGE_VALUE;
currentList_->SetAutoAlignTime(autoAlignTime_);
} else if (&view == setAutoAlignACCDncBtn_) {
autoAlignTime_ -= ALINE_TIME_CHANGE_VALUE;
currentList_->SetAutoAlignTime(autoAlignTime_);
}
return true;
}
......
......@@ -41,6 +41,7 @@ public:
void UIKit_List_Scroll_Test_Blank_Set_001();
private:
static constexpr int16_t ALINE_TIME_CHANGE_VALUE = 100;
void SetLastPos(UIView* view);
void SetUpButton(UILabelButton* btn, const char* title);
void SetControlButton();
......@@ -55,6 +56,8 @@ private:
UILabelButton* setSelectOffBtn_ = nullptr;
UILabelButton* setAutoAlignBtn_ = nullptr;
UILabelButton* setAutoAlignOffBtn_ = nullptr;
UILabelButton* setAutoAlignACCIncBtn_ = nullptr;
UILabelButton* setAutoAlignACCDncBtn_ = nullptr;
UILabel* scrollStateLabel_ = nullptr;
UILabel* scrollSelectLabel_ = nullptr;
UIScrollView* container_ = nullptr;
......@@ -69,6 +72,7 @@ private:
UILabel* lastSelectLabel_ = nullptr;
int16_t lastX_ = 0;
int16_t lastY_ = 0;
uint16_t autoAlignTime_ = 100; // 100: default list auto aling ACC
};
} // namespace OHOS
#endif // UI_TEST_UI_LIST_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册