diff --git a/frameworks/src/core/components/component.h b/frameworks/src/core/components/component.h index d15dbb9..bdf2d87 100755 --- a/frameworks/src/core/components/component.h +++ b/frameworks/src/core/components/component.h @@ -200,6 +200,18 @@ public: */ const Dimension &GetDimension(uint16_t keyNameId) const; + void SetWidth(const int16_t width) + { + width_.type = DimensionType::TYPE_PIXEL; + width_.value.pixel = width; + } + + void SetHeight(const int16_t height) + { + height_.type = DimensionType::TYPE_PIXEL; + height_.value.pixel = height; + } + protected: void SetComponentName(uint16_t name) { diff --git a/frameworks/src/core/components/list_adapter.cpp b/frameworks/src/core/components/list_adapter.cpp index 57b04f5..f882e1b 100755 --- a/frameworks/src/core/components/list_adapter.cpp +++ b/frameworks/src/core/components/list_adapter.cpp @@ -286,6 +286,11 @@ void ListAdapter::BuildItemViewTree(const JSValue element) const return; } ConstrainedParameter parentParam = uiListContentParam_; + if (direction_ == UIList::VERTICAL) { + component->SetWidth(uiListContentParam_.maxWidth); + } else { + component->SetHeight(uiListContentParam_.maxHeight); + } Component::BuildViewTree(component, nullptr, parentParam); component->OnViewAttached(); } diff --git a/frameworks/src/core/components/list_adapter.h b/frameworks/src/core/components/list_adapter.h index b865e91..46303e3 100644 --- a/frameworks/src/core/components/list_adapter.h +++ b/frameworks/src/core/components/list_adapter.h @@ -66,6 +66,11 @@ public: void UpdateContentAlignParam(ConstrainedParameter param); + void SetDirection(uint8_t direction) + { + direction_ = direction; + } + private: bool GenerateListItems(const JSValue descriptors, int16_t size); int16_t CalculateItemIndex(int16_t itemIndex) const; @@ -81,6 +86,7 @@ private: int16_t listItemsCount_; // the content area ConstrainedParameter uiListContentParam_; + uint8_t direction_ = UIList::VERTICAL; }; } // namespace ACELite } // namespace OHOS diff --git a/frameworks/src/core/components/list_component.cpp b/frameworks/src/core/components/list_component.cpp index 0c14417..261148a 100755 --- a/frameworks/src/core/components/list_component.cpp +++ b/frameworks/src/core/components/list_component.cpp @@ -136,6 +136,7 @@ void ListComponent::OnViewAttached() ConstrainedParameter listParameter; GetConstrainedParam(listParameter); adapter_.UpdateContentAlignParam(listParameter); + adapter_.SetDirection(list_.GetDirection()); // Step4. add children to list dynamically. list_.SetAdapter(&adapter_); }