提交 38d9c37f 编写于 作者: O openharmony_ci 提交者: Gitee

!307 修复调用SwipeView的SetCurrentPage接口在从最后一个元素切换至第一个元素时显示错误问题

Merge pull request !307 from JayLeeHW/OpenHarmony-2.3-Beta
...@@ -75,8 +75,32 @@ void UISwipeView::Remove(UIView* view) ...@@ -75,8 +75,32 @@ void UISwipeView::Remove(UIView* view)
Invalidate(); Invalidate();
} }
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();
}
}
}
}
void UISwipeView::SetCurrentPage(uint16_t index, bool needAnimator) void UISwipeView::SetCurrentPage(uint16_t index, bool needAnimator)
{ {
if (needAnimator) {
MoveHeadOrTailChild();
}
SwitchToPage(index, needAnimator); SwitchToPage(index, needAnimator);
Invalidate(); Invalidate();
} }
...@@ -415,21 +439,7 @@ void UISwipeView::RefreshCurrentView(int16_t distance) ...@@ -415,21 +439,7 @@ void UISwipeView::RefreshCurrentView(int16_t distance)
void UISwipeView::MoveChildByOffset(int16_t xOffset, int16_t yOffset) void UISwipeView::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
{ {
UIViewGroup::MoveChildByOffset(xOffset, yOffset); UIViewGroup::MoveChildByOffset(xOffset, yOffset);
if (direction_ == HORIZONTAL) { MoveHeadOrTailChild();
while (isNeedLoop() && (childrenHead_->GetX() > 0)) {
MoveLastChildToFirst();
}
while (isNeedLoop() && (childrenTail_->GetX() + childrenTail_->GetWidth() < GetWidth())) {
MoveFirstChildToLast();
}
} else {
while (isNeedLoop() && (childrenHead_->GetY() > 0)) {
MoveLastChildToFirst();
}
while (isNeedLoop() && (childrenTail_->GetY() + childrenTail_->GetHeight() < GetHeight())) {
MoveFirstChildToLast();
}
}
} }
bool UISwipeView::isNeedLoop() bool UISwipeView::isNeedLoop()
......
...@@ -329,6 +329,7 @@ protected: ...@@ -329,6 +329,7 @@ protected:
void StopAnimator() override; void StopAnimator() override;
virtual void SwitchToPage(int16_t dst, bool needAnimator = true); virtual void SwitchToPage(int16_t dst, bool needAnimator = true);
void MoveChildByOffset(int16_t xOffset, int16_t yOffset) override; void MoveChildByOffset(int16_t xOffset, int16_t yOffset) override;
void MoveHeadOrTailChild();
/** /**
* @brief Indicates that the animation duration is 12 ticks. * @brief Indicates that the animation duration is 12 ticks.
......
...@@ -31,6 +31,7 @@ static int16_t g_swipeW = 400; ...@@ -31,6 +31,7 @@ static int16_t g_swipeW = 400;
static int16_t g_swipeHorH = 110; static int16_t g_swipeHorH = 110;
static int16_t g_deltaCoordinateY = 19; static int16_t g_deltaCoordinateY = 19;
static int16_t g_deltaCoordinateY2 = 37; static int16_t g_deltaCoordinateY2 = 37;
static uint16_t g_MaxIndex = 3;
} // namespace } // namespace
void UITestUISwipeView::SetUp() void UITestUISwipeView::SetUp()
...@@ -53,6 +54,8 @@ void UITestUISwipeView::TearDown() ...@@ -53,6 +54,8 @@ void UITestUISwipeView::TearDown()
removeHeadBtn_ = nullptr; removeHeadBtn_ = nullptr;
removeMidBtn_ = nullptr; removeMidBtn_ = nullptr;
removeAllBtn_ = nullptr; removeAllBtn_ = nullptr;
loopBtn_ = nullptr;
changePageBtn_ = nullptr;
lastX_ = 0; lastX_ = 0;
lastY_ = 0; lastY_ = 0;
} }
...@@ -70,6 +73,8 @@ const UIView* UITestUISwipeView::GetTestView() ...@@ -70,6 +73,8 @@ const UIView* UITestUISwipeView::GetTestView()
UIKit_Swipe_View_Test_Ver_002(); UIKit_Swipe_View_Test_Ver_002();
UIKit_Swipe_View_Test_Remove_001(); UIKit_Swipe_View_Test_Remove_001();
UIKit_Swipe_View_Test_SetCurrentPage();
return container_; return container_;
} }
...@@ -344,6 +349,55 @@ void UITestUISwipeView::UIKit_Swipe_View_Test_Align_001(UISwipeView::AlignMode a ...@@ -344,6 +349,55 @@ void UITestUISwipeView::UIKit_Swipe_View_Test_Align_001(UISwipeView::AlignMode a
SetLastPos(swipe); SetLastPos(swipe);
} }
void UITestUISwipeView::UIKit_Swipe_View_Test_SetCurrentPage()
{
if (container_ == nullptr) {
return;
}
positionY_ += g_deltaCoordinateY;
UILabel* label = GetTitleLabel("UISwipeView切换页面");
container_->Add(label);
positionY_ += g_deltaCoordinateY;
label->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_);
positionY_ += g_deltaCoordinateY2;
UISwipeView* swipe = new UISwipeView(UISwipeView::HORIZONTAL);
swipe->SetIntercept(true);
swipe->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
swipe->SetPosition(TEXT_DISTANCE_TO_LEFT_SIDE, positionY_, g_swipeW, g_swipeH);
swipe->SetLoopState(loop_);
swipe->SetAnimatorTime(1000); // 100: mean animator drag time(ms)
currentSwipe_ = swipe;
container_->Add(swipe);
UIView* view1 = new UIView();
view1->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
view1->Resize(g_swipeW, g_swipeH);
swipe->Add(view1);
UIView* view2 = new UIView();
view2->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full);
view2->Resize(g_swipeW, g_swipeH);
swipe->Add(view2);
UIView* view3 = new UIView();
view3->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
view3->Resize(g_swipeW, g_swipeH);
swipe->Add(view3);
UIView* view4 = new UIView();
view4->SetStyle(STYLE_BACKGROUND_COLOR, Color::Yellow().full);
view4->Resize(g_swipeW, g_swipeH);
swipe->Add(view4);
if (loopBtn_ == nullptr) {
loopBtn_ = new UILabelButton();
}
if (changePageBtn_ == nullptr) {
changePageBtn_ = new UILabelButton();
}
positionX_ = TEXT_DISTANCE_TO_LEFT_SIDE + swipe->GetWidth() + 20; // 20: is interval between button and swipe
positionY_ += g_deltaCoordinateY2;
SetUpButton(loopBtn_, "设置循环 关 ");
SetUpButton(changePageBtn_, "切换页面 ");
}
bool UITestUISwipeView::OnClick(UIView& view, const ClickEvent& event) bool UITestUISwipeView::OnClick(UIView& view, const ClickEvent& event)
{ {
if (currentSwipe_ == nullptr) { if (currentSwipe_ == nullptr) {
...@@ -371,6 +425,21 @@ bool UITestUISwipeView::OnClick(UIView& view, const ClickEvent& event) ...@@ -371,6 +425,21 @@ bool UITestUISwipeView::OnClick(UIView& view, const ClickEvent& event)
currentSwipe_->Remove(view); currentSwipe_->Remove(view);
} else if (&view == removeAllBtn_) { } else if (&view == removeAllBtn_) {
currentSwipe_->RemoveAll(); currentSwipe_->RemoveAll();
} else if (&view == loopBtn_) {
loop_ = !loop_;
currentSwipe_->SetLoopState(loop_);
if (!loop_) {
loopBtn_->SetText("设置循环 关 ");
} else {
loopBtn_->SetText("设置循环 开 ");
}
} else if (&view == changePageBtn_) {
uint16_t currentIndex = currentSwipe_->GetCurrentPage();
if (currentIndex < g_MaxIndex) {
currentSwipe_->SetCurrentPage(++currentIndex, true);
} else {
currentSwipe_->SetCurrentPage(0, true);
}
} }
currentSwipe_->Invalidate(); currentSwipe_->Invalidate();
btnNum_++; btnNum_++;
......
...@@ -38,6 +38,7 @@ public: ...@@ -38,6 +38,7 @@ public:
void UIKit_Swipe_View_Test_Ver_002(); void UIKit_Swipe_View_Test_Ver_002();
void UIKit_Swipe_View_Test_Remove_001(); void UIKit_Swipe_View_Test_Remove_001();
void UIKit_Swipe_View_Test_Align_001(UISwipeView::AlignMode alignMode); void UIKit_Swipe_View_Test_Align_001(UISwipeView::AlignMode alignMode);
void UIKit_Swipe_View_Test_SetCurrentPage();
private: private:
void SetUpButton(UILabelButton* btn, const char* title); void SetUpButton(UILabelButton* btn, const char* title);
...@@ -50,7 +51,9 @@ private: ...@@ -50,7 +51,9 @@ private:
UILabelButton* removeHeadBtn_ = nullptr; UILabelButton* removeHeadBtn_ = nullptr;
UILabelButton* removeMidBtn_ = nullptr; UILabelButton* removeMidBtn_ = nullptr;
UILabelButton* removeAllBtn_ = nullptr; UILabelButton* removeAllBtn_ = nullptr;
UILabelButton* loopBtn_ = nullptr;
UILabelButton* changePageBtn_ = nullptr;
bool loop_ = false;
int16_t lastX_ = 0; int16_t lastX_ = 0;
int16_t lastY_ = 0; int16_t lastY_ = 0;
int16_t btnNum_ = 0; int16_t btnNum_ = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册