fix scrollable scrollpage

Signed-off-by: hongzexuan <hongzexuan@huawei.com>
Change-Id: Ie5aef299f71ad5ee216a03088ed2c7fe5ea5ea00
This commit is contained in:
hongzexuan 2024-08-27 19:37:49 +08:00
parent 15b2d61689
commit 74a3561a6c
6 changed files with 39 additions and 14 deletions

View File

@ -2908,9 +2908,13 @@ void ScrollablePattern::ScrollPage(bool reverse, bool smooth, AccessibilityScrol
if (scrollType == AccessibilityScrollType::SCROLL_HALF) {
distance = distance / 2.f;
}
float position = -GetTotalOffset() + distance;
AnimateTo(-position, -1, nullptr, true, false, false);
return;
if (smooth) {
float position = -GetTotalOffset() + distance;
AnimateTo(-position, -1, nullptr, true, false, false);
} else {
StopAnimate();
UpdateCurrentOffset(distance, SCROLL_FROM_JUMP);
}
}
void ScrollablePattern::InitScrollBarMouseEvent()
@ -3269,7 +3273,7 @@ void ScrollablePattern::SetAccessibilityAction()
pattern->IsScrollable(), scrollType, static_cast<int32_t>(host->GetAccessibilityId()),
host->GetTag().c_str());
CHECK_NULL_VOID(pattern->IsScrollable());
pattern->ScrollPage(false, false, scrollType);
pattern->ScrollPage(false, true, scrollType);
});
accessibilityProperty->SetActionScrollBackward([weakPtr = WeakClaim(this)](AccessibilityScrollType scrollType) {
@ -3281,7 +3285,7 @@ void ScrollablePattern::SetAccessibilityAction()
pattern->IsScrollable(), scrollType, static_cast<int32_t>(host->GetAccessibilityId()),
host->GetTag().c_str());
CHECK_NULL_VOID(pattern->IsScrollable());
pattern->ScrollPage(true, false, scrollType);
pattern->ScrollPage(true, true, scrollType);
});
}

View File

@ -4146,7 +4146,7 @@ typedef enum {
* @brief Scroll to the next or previous page.
*
* Format of the {@link ArkUI_AttributeItem} parameter for setting the attribute:\n
* .value[0].i32 Indicates whether to scroll to next page. Value 1 indicates scroll to next page and value 0
* .value[0].i32 Indicates whether to scroll to next page. Value 0 indicates scroll to next page and value 1
* indicates scroll to previous page. \n
* .value[1]?.i32 Indicates whether to enable animation. Value 1 indicates enable and 0 indicates disable. \n
*

View File

@ -15,6 +15,7 @@
#include "grid_test_ng.h"
#include "test/mock/core/render/mock_render_context.h"
#include "test/mock/core/animation/mock_animation_manager.h"
#include "core/components_ng/pattern/button/button_model_ng.h"
#include "core/components_ng/pattern/grid/grid_item_pattern.h"
@ -1282,9 +1283,13 @@ HWTEST_F(GridCommonTestNg, PerformActionTest002, TestSize.Level1)
CreateFixedItems(10);
CreateDone(frameNode_);
accessibilityProperty_->ActActionScrollForward();
EXPECT_EQ(pattern_->GetGridLayoutInfo().currentOffset_, 0.f);
MockAnimationManager::GetInstance().Tick();
FlushLayoutTask(frameNode_);
EXPECT_EQ(pattern_->GetGridLayoutInfo().currentHeight_, 0.f);
accessibilityProperty_->ActActionScrollBackward();
EXPECT_EQ(pattern_->GetGridLayoutInfo().currentOffset_, 0.f);
MockAnimationManager::GetInstance().Tick();
FlushLayoutTask(frameNode_);
EXPECT_EQ(pattern_->GetGridLayoutInfo().currentHeight_, 0.f);
/**
* @tc.steps: step2. When grid is Scrollable
@ -1293,12 +1298,16 @@ HWTEST_F(GridCommonTestNg, PerformActionTest002, TestSize.Level1)
ClearOldNodes();
model = CreateGrid();
model.SetColumnsTemplate("1fr 1fr 1fr 1fr");
CreateFixedItems(20);
CreateFixedItems(40);
CreateDone(frameNode_);
accessibilityProperty_->ActActionScrollForward();
EXPECT_EQ(pattern_->GetGridLayoutInfo().currentOffset_, -GRID_HEIGHT);
MockAnimationManager::GetInstance().Tick();
FlushLayoutTask(frameNode_);
EXPECT_EQ(-pattern_->GetGridLayoutInfo().currentHeight_, -GRID_HEIGHT);
accessibilityProperty_->ActActionScrollBackward();
EXPECT_EQ(pattern_->GetGridLayoutInfo().currentOffset_, 0.f);
MockAnimationManager::GetInstance().Tick();
FlushLayoutTask(frameNode_);
EXPECT_EQ(-pattern_->GetGridLayoutInfo().currentHeight_, 0.f);
}
/**

View File

@ -19,6 +19,7 @@
#include "test/mock/core/common/mock_container.h"
#include "test/mock/core/common/mock_theme_manager.h"
#include "test/mock/core/pipeline/mock_pipeline_context.h"
#include "test/mock/core/animation/mock_animation_manager.h"
#include "core/components/button/button_theme.h"
#include "core/components_ng/pattern/button/button_model_ng.h"
@ -46,7 +47,7 @@ void GridTestNg::SetUpTestSuite()
EXPECT_CALL(*MockPipelineContext::pipeline_, FlushUITasks).Times(AnyNumber());
auto container = Container::GetContainer(CONTAINER_ID_DIVIDE_SIZE);
EXPECT_CALL(*(AceType::DynamicCast<MockContainer>(container)), GetWindowId()).Times(AnyNumber());
MockAnimationManager::Enable(true);
#ifndef TEST_IRREGULAR_GRID
g_irregularGrid = false;
#endif
@ -67,7 +68,10 @@ void GridTestNg::TearDownTestSuite()
TestNG::TearDownTestSuite();
}
void GridTestNg::SetUp() {}
void GridTestNg::SetUp()
{
MockAnimationManager::GetInstance().Reset();
}
void GridTestNg::TearDown()
{

View File

@ -1104,7 +1104,7 @@ HWTEST_F(ScrollableCoverTestNg, ScrollPage001, TestSize.Level1)
* @tc.steps: step2. Test ScrollPage
* @tc.expected: Verify the scrollAbort_ status
*/
scrollPn->ScrollPage(false, false, AccessibilityScrollType::SCROLL_HALF);
scrollPn->ScrollPage(false, true, AccessibilityScrollType::SCROLL_HALF);
EXPECT_TRUE(scrollPn->scrollAbort_);
}

View File

@ -1193,8 +1193,12 @@ HWTEST_F(WaterFlowTestNg, PositionController008, TestSize.Level1)
* @tc.expected: Will trigger ScrollPage func
*/
accessibilityProperty_->ActActionScrollForward();
MockAnimationManager::GetInstance().Tick();
FlushLayoutTask(frameNode_);
EXPECT_TRUE(IsEqualTotalOffset(WATER_FLOW_HEIGHT));
accessibilityProperty_->ActActionScrollBackward();
MockAnimationManager::GetInstance().Tick();
FlushLayoutTask(frameNode_);
EXPECT_TRUE(IsEqualTotalOffset(0));
}
@ -1432,8 +1436,12 @@ HWTEST_F(WaterFlowTestNg, WaterFlowAccessibilityTest002, TestSize.Level1)
CreateWaterFlowItems(TOTAL_LINE_NUMBER * 2);
CreateDone();
accessibilityProperty_->ActActionScrollForward();
MockAnimationManager::GetInstance().Tick();
FlushLayoutTask(frameNode_);
EXPECT_TRUE(IsEqualTotalOffset(WATER_FLOW_HEIGHT));
accessibilityProperty_->ActActionScrollBackward();
MockAnimationManager::GetInstance().Tick();
FlushLayoutTask(frameNode_);
EXPECT_TRUE(IsEqualTotalOffset(0));
}