!47615 滚动类组件CAPI支持获取子组件全展开尺寸

Merge pull request !47615 from honzx/1102size
This commit is contained in:
openharmony_ci 2024-11-12 07:34:16 +00:00 committed by Gitee
commit 1be088946a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 152 additions and 3 deletions

View File

@ -2310,4 +2310,38 @@ void GridPattern::DumpAdvanceInfo(std::unique_ptr<JsonValue>& json)
BuildScrollAlignInfo(json);
BuildGridLayoutInfo(json);
}
SizeF GridPattern::GetChildrenExpandedSize()
{
auto host = GetHost();
CHECK_NULL_RETURN(host, SizeF());
auto layoutProperty = host->GetLayoutProperty<GridLayoutProperty>();
CHECK_NULL_RETURN(layoutProperty, SizeF());
auto padding = layoutProperty->CreatePaddingAndBorder();
auto geometryNode = host->GetGeometryNode();
CHECK_NULL_RETURN(geometryNode, SizeF());
auto viewSize = geometryNode->GetFrameSize();
MinusPaddingToSize(padding, viewSize);
auto axis = GetAxis();
float estimatedHeight = 0.f;
const auto& info = info_;
auto viewScopeSize = geometryNode->GetPaddingSize();
auto mainGap = GridUtils::GetMainGap(layoutProperty, viewScopeSize, info.axis_);
if (UseIrregularLayout()) {
estimatedHeight = info.GetIrregularHeight(mainGap);
} else if (!layoutProperty->GetLayoutOptions().has_value()) {
estimatedHeight = info.GetContentHeight(mainGap);
} else {
estimatedHeight =
info.GetContentHeight(layoutProperty->GetLayoutOptions().value(), info.childrenCount_, mainGap);
}
if (axis == Axis::VERTICAL) {
return SizeF(viewSize.Width(), estimatedHeight);
} else if (axis == Axis::HORIZONTAL) {
return SizeF(estimatedHeight, viewSize.Height());
}
return SizeF();
}
} // namespace OHOS::Ace::NG

View File

@ -268,6 +268,9 @@ public:
{
focusIndex_ = std::nullopt;
}
SizeF GetChildrenExpandedSize() override;
private:
/**
* @brief calculate where startMainLine_ should be after spring animation.

View File

@ -2715,4 +2715,25 @@ void ListPattern::DumpAdvanceInfo(std::unique_ptr<JsonValue>& json)
json->Put("IsAtTop", IsAtTop());
json->Put("IsAtBottom", IsAtBottom());
}
SizeF ListPattern::GetChildrenExpandedSize()
{
auto viewSize = GetViewSizeMinusPadding();
auto axis = GetAxis();
float estimatedHeight = 0.0f;
if (childrenSize_) {
estimatedHeight = listTotalHeight_;
} else if (!itemPosition_.empty()) {
auto calculate = ListHeightOffsetCalculator(itemPosition_, spaceWidth_, lanes_, axis);
calculate.GetEstimateHeightAndOffset(GetHost());
estimatedHeight = calculate.GetEstimateHeight();
}
if (axis == Axis::VERTICAL) {
return SizeF(viewSize.Width(), estimatedHeight);
} else if (axis == Axis::HORIZONTAL) {
return SizeF(estimatedHeight, viewSize.Height());
}
return SizeF();
}
} // namespace OHOS::Ace::NG

View File

@ -345,6 +345,8 @@ public:
return canOverScroll;
}
void UpdateChildPosInfo(int32_t index, float delta, float sizeChange);
SizeF GetChildrenExpandedSize() override;
private:
bool IsNeedInitClickEventRecorder() const override

View File

@ -1373,4 +1373,15 @@ void ScrollPattern::DumpAdvanceInfo(std::unique_ptr<JsonValue>& json)
}
json->Put("scrollMeasureInfos", infochildren);
}
SizeF ScrollPattern::GetChildrenExpandedSize()
{
auto axis = GetAxis();
if (axis == Axis::VERTICAL) {
return SizeF(viewPort_.Width(), viewPortExtent_.Height());
} else if (axis == Axis::HORIZONTAL) {
return SizeF(viewPortExtent_.Width(), viewPort_.Height());
}
return SizeF();
}
} // namespace OHOS::Ace::NG

View File

@ -353,6 +353,8 @@ public:
void StartScrollSnapAnimation(float scrollSnapDelta, float scrollSnapVelocity);
SizeF GetChildrenExpandedSize() override;
protected:
void DoJump(float position, int32_t source = SCROLL_FROM_JUMP);

View File

@ -3807,4 +3807,18 @@ void ScrollablePattern::OnColorConfigurationUpdate()
scrollBar_->SetForegroundColor(theme->GetForegroundColor());
scrollBar_->SetBackgroundColor(theme->GetBackgroundColor());
}
SizeF ScrollablePattern::GetViewSizeMinusPadding()
{
auto host = GetHost();
CHECK_NULL_RETURN(host, SizeF());
auto layoutProperty = host->GetLayoutProperty();
CHECK_NULL_RETURN(layoutProperty, SizeF());
auto padding = layoutProperty->CreatePaddingAndBorder();
auto geometryNode = host->GetGeometryNode();
CHECK_NULL_RETURN(geometryNode, SizeF());
auto viewSize = geometryNode->GetFrameSize();
MinusPaddingToSize(padding, viewSize);
return viewSize;
}
} // namespace OHOS::Ace::NG

View File

@ -692,6 +692,13 @@ public:
void OnColorConfigurationUpdate() override;
virtual SizeF GetChildrenExpandedSize()
{
return SizeF();
}
SizeF GetViewSizeMinusPadding();
protected:
void SuggestOpIncGroup(bool flag);
void OnDetachFromFrameNode(FrameNode* frameNode) override;

View File

@ -838,4 +838,22 @@ void WaterFlowPattern::DumpInfoAddSections()
}
DumpLog::GetInstance().AddDesc("-----------end print sections_------------");
}
SizeF WaterFlowPattern::GetChildrenExpandedSize()
{
auto viewSize = GetViewSizeMinusPadding();
auto axis = GetAxis();
float estimatedHeight = 0.0f;
if (layoutInfo_->Mode() != LayoutMode::SLIDING_WINDOW) {
auto info = DynamicCast<WaterFlowLayoutInfo>(layoutInfo_);
estimatedHeight = info->EstimateContentHeight();
}
if (axis == Axis::VERTICAL) {
return SizeF(viewSize.Width(), estimatedHeight);
} else if (axis == Axis::HORIZONTAL) {
return SizeF(estimatedHeight, viewSize.Height());
}
return SizeF();
}
} // namespace OHOS::Ace::NG

View File

@ -202,6 +202,8 @@ public:
return layoutInfo_->defCachedCount_;
}
SizeF GetChildrenExpandedSize() override;
private:
DisplayMode GetDefaultScrollBarDisplayMode() const override
{

View File

@ -2815,6 +2815,7 @@ struct ArkUIScrollModifier {
void (*resetScrollFadingEdge)(ArkUINodeHandle node);
void (*getScrollFadingEdge)(ArkUINodeHandle node, ArkUIInt32orFloat32 (*values)[2]);
void (*setScrollFling)(ArkUINodeHandle node, ArkUI_Float64 value);
void (*getScrollContentSize)(ArkUINodeHandle node, ArkUI_Float32 (*values)[2]);
};
struct ArkUIListItemModifier {

View File

@ -550,6 +550,17 @@ void GetScrollFadingEdge(ArkUINodeHandle node, ArkUIInt32orFloat32 (*values)[2])
(*values)[0].i32 = static_cast<int32_t>(NG::ScrollableModelNG::GetFadingEdge(frameNode));
(*values)[1].f32 = NG::ScrollableModelNG::GetFadingEdgeLength(frameNode);
}
void GetScrollContentSize(ArkUINodeHandle node, ArkUI_Float32 (*values)[2])
{
auto* frameNode = reinterpret_cast<FrameNode*>(node);
CHECK_NULL_VOID(frameNode);
auto pattern = frameNode->GetPattern<OHOS::Ace::NG::ScrollablePattern>();
CHECK_NULL_VOID(pattern);
SizeF size = pattern->GetChildrenExpandedSize();
(*values)[0] = size.Width();
(*values)[1] = size.Height();
}
} // namespace
namespace NodeModifier {
@ -593,6 +604,7 @@ const ArkUIScrollModifier* GetScrollModifier()
SetOnScrollFrameBeginCallBack, ResetOnScrollFrameBeginCallBack,
SetScrollFadingEdge, ResetScrollFadingEdge, GetScrollFadingEdge,
SetScrollFling,
GetScrollContentSize,
};
/* clang-format on */
return &modifier;

View File

@ -4211,6 +4211,19 @@ typedef enum {
*/
NODE_SCROLL_FADING_EDGE,
/**
* @brief Obtains the total size of all child components when fully expanded in the scrollable component.
*
* Format of the return value {@link ArkUI_AttributeItem}:\n
* .value[0].f32: total width of all child components when fully expanded in the scrollable component.
* The default unit is vp. \n
* .value[1].f32: total height of all child components when fully expanded in the scrollable component.
* The default unit is vp. \n
*
* @since 14
*/
NODE_SCROLL_SIZE,
/**
* @brief Defines the direction in which the list items are arranged. This attribute can be set, reset, and
* obtained as required through APIs.

View File

@ -5609,6 +5609,15 @@ void ResetScrollFadingEdge(ArkUI_NodeHandle node)
fullImpl->getNodeModifiers()->getScrollModifier()->resetScrollFadingEdge(node->uiNodeHandle);
}
const ArkUI_AttributeItem* GetScrollContentSize(ArkUI_NodeHandle node)
{
ArkUI_Float32 values[NUM_2];
GetFullImpl()->getNodeModifiers()->getScrollModifier()->getScrollContentSize(node->uiNodeHandle, &values);
g_numberValues[NUM_0].f32 = values[NUM_0];
g_numberValues[NUM_1].f32 = values[NUM_1];
return &g_attributeItem;
}
const ArkUI_AttributeItem* GetListDirection(ArkUI_NodeHandle node)
{
auto value = GetFullImpl()->getNodeModifiers()->getListModifier()->getListDirection(node->uiNodeHandle);
@ -13783,7 +13792,7 @@ int32_t SetScrollAttribute(ArkUI_NodeHandle node, int32_t subTypeId, const ArkUI
static Setter* setters[] = { SetScrollScrollBar, SetScrollScrollBarWidth, SetScrollScrollBarColor,
SetScrollScrollable, SetScrollEdgeEffect, SetScrollEnableScrollInteraction, SetScrollFriction,
SetScrollScrollSnap, SetScrollNestedScroll, SetScrollTo, SetScrollEdge, SetScrollEnablePaging,
SetScrollPage, SetScrollBy, SetScrollFling, SetScrollFadingEdge };
SetScrollPage, SetScrollBy, SetScrollFling, SetScrollFadingEdge, nullptr };
if (static_cast<uint32_t>(subTypeId) >= sizeof(setters) / sizeof(Setter*)) {
TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "scroll node attribute: %{public}d NOT IMPLEMENT", subTypeId);
return ERROR_CODE_NATIVE_IMPL_TYPE_NOT_SUPPORTED;
@ -13796,7 +13805,7 @@ const ArkUI_AttributeItem* GetScrollAttribute(ArkUI_NodeHandle node, int32_t sub
static Getter* getters[] = { GetScrollScrollBar, GetScrollScrollBarWidth, GetScrollScrollBarColor,
GetScrollScrollable, GetScrollEdgeEffect, GetScrollEnableScrollInteraction, GetScrollFriction,
GetScrollScrollSnap, GetScrollNestedScroll, GetScrollOffset, GetScrollEdge, GetScrollEnablePaging,
nullptr, nullptr, nullptr, GetScrollFadingEdge };
nullptr, nullptr, nullptr, GetScrollFadingEdge, GetScrollContentSize };
if (static_cast<uint32_t>(subTypeId) >= sizeof(getters) / sizeof(Getter*)) {
TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "slider node attribute: %{public}d NOT IMPLEMENT", subTypeId);
return nullptr;
@ -13810,7 +13819,7 @@ void ResetScrollAttribute(ArkUI_NodeHandle node, int32_t subTypeId)
static Resetter* resetters[] = { ResetScrollScrollBar, ResetScrollScrollBarWidth, ResetScrollScrollBarColor,
ResetScrollScrollable, ResetScrollEdgeEffect, ResetScrollEnableScrollInteraction, ResetScrollFriction,
ResetScrollScrollSnap, ResetScrollNestedScroll, ResetScrollTo, ResetScrollEdge, ResetScrollEnablePaging,
nullptr, nullptr, nullptr, ResetScrollFadingEdge };
nullptr, nullptr, nullptr, ResetScrollFadingEdge, nullptr };
if (static_cast<uint32_t>(subTypeId) >= sizeof(resetters) / sizeof(Resetter*)) {
TAG_LOGE(AceLogTag::ACE_NATIVE_NODE, "list node attribute: %{public}d NOT IMPLEMENT", subTypeId);
return;