diff --git a/frameworks/bridge/declarative_frontend/jsview/js_scroller.cpp b/frameworks/bridge/declarative_frontend/jsview/js_scroller.cpp index 9c6297c879a59d20fedf1c93921b301fa74e4a21..8a2383eff9f536ef0b18f349d8fb1951e1f4ea92 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_scroller.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_scroller.cpp @@ -77,6 +77,7 @@ void JSScroller::JSBind(BindingTarget globalObj) JSClass::CustomMethod("isAtEnd", &JSScroller::IsAtEnd); JSClass::CustomMethod("getItemRect", &JSScroller::GetItemRect); JSClass::CustomMethod("getItemIndex", &JSScroller::GetItemIndex); + JSClass::CustomMethod("contentSize", &JSScroller::ContentSize); JSClass::Bind(globalObj, JSScroller::Constructor, JSScroller::Destructor); } @@ -434,4 +435,19 @@ void JSScroller::GetItemIndex(const JSCallbackInfo& args) return; } + +void JSScroller::ContentSize(const JSCallbackInfo& args) +{ + auto scrollController = controllerWeak_.Upgrade(); + if (!scrollController) { + JSException::Throw(ERROR_CODE_NAMED_ROUTE_ERROR, "%s", "Controller not bound to component."); + return; + } + auto retObj = JSRef::New(); + ContainerScope scope(instanceId_); + auto contentSize = scrollController->ContentSize(); + retObj->SetProperty("width", Dimension(contentSize.Width(), DimensionUnit::PX).ConvertToVp()); + retObj->SetProperty("height", Dimension(contentSize.Height(), DimensionUnit::PX).ConvertToVp()); + args.SetReturnValue(retObj); +} } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_scroller.h b/frameworks/bridge/declarative_frontend/jsview/js_scroller.h index 9511ba97ff4e5d4d27b9a342c2790f0b5a747ab2..a9412dd857fe500756ea9a560883717b2ae1fe32 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_scroller.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_scroller.h @@ -43,6 +43,7 @@ public: void IsAtEnd(const JSCallbackInfo& args); void GetItemRect(const JSCallbackInfo& args); void GetItemIndex(const JSCallbackInfo& args); + void ContentSize(const JSCallbackInfo& args); const WeakPtr& GetController() const { diff --git a/frameworks/core/components/scroll/scroll_controller_base.h b/frameworks/core/components/scroll/scroll_controller_base.h index 248d6c761d27007158c01c730e3ee98cbf37ea7d..dacbb4171143cf6f8412d358ed1a523e59cf9a7e 100644 --- a/frameworks/core/components/scroll/scroll_controller_base.h +++ b/frameworks/core/components/scroll/scroll_controller_base.h @@ -18,6 +18,7 @@ #include "base/geometry/axis.h" #include "base/geometry/dimension.h" +#include "base/geometry/ng/size_t.h" #include "base/geometry/offset.h" #include "base/geometry/rect.h" #include "base/memory/ace_type.h" @@ -130,6 +131,11 @@ public: { return -1; } + + virtual NG::SizeF ContentSize() const + { + return NG::SizeF(); + } virtual Rect GetItemRectInGroup(int32_t index, int32_t indexInGroup) const { diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable_controller.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable_controller.cpp index 2be674fb97b8bcad1ea7e8725e575fb2b0c0e03f..37f338dbd1e757e1b80257874a05a6c9f3d93c54 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_controller.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_controller.cpp @@ -220,6 +220,13 @@ int32_t ScrollableController::GetItemIndex(double x, double y) const return pattern->GetItemIndex(x, y); } +SizeF ScrollableController::ContentSize() const +{ + auto pattern = scroll_.Upgrade(); + CHECK_NULL_RETURN(pattern, SizeF()); + return pattern->GetChildrenExpandedSize(); +} + void ScrollableController::StopAnimate() { auto pattern = scroll_.Upgrade(); diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable_controller.h b/frameworks/core/components_ng/pattern/scrollable/scrollable_controller.h index d5c5ee652ed53c6949134b15f5662b71fd1ab2ac..89ad6bd92992ab6707af1a737f8cd37e896f37b7 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable_controller.h +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable_controller.h @@ -56,6 +56,7 @@ public: bool IsAtEnd() const override; Rect GetItemRect(int32_t index) const override; int32_t GetItemIndex(double x, double y) const override; + SizeF ContentSize() const override; void StopAnimate() override; void SetObserver(const ScrollerObserver& observer) override