From 6b25ee6f874ef95f2cc291ac7e6d576ff4f1713e Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Thu, 26 May 2022 21:13:34 +0800 Subject: [PATCH 1/3] add list scroll bar Signed-off-by: jiangdayuan Change-Id: Ib60b8f9a7871df9196c42317129e9f983f9aacc3 --- .../components/common/properties/scroll_bar.h | 2 +- .../grid_layout/grid_layout_component.cpp | 4 +- .../scroll_bar/scroll_bar_proxy.cpp | 10 +- .../components_v2/grid/render_grid_scroll.cpp | 20 ++-- frameworks/core/components_v2/list/BUILD.gn | 1 + .../list/flutter_render_list.cpp | 29 +++++ .../list/list_scroll_bar_controller.cpp | 68 +++++++++++ .../list/list_scroll_bar_controller.h | 38 ++++++ .../core/components_v2/list/render_list.cpp | 108 ++++++++++++++++-- .../core/components_v2/list/render_list.h | 22 +++- .../components_v2/list/rosen_render_list.cpp | 40 +++++-- 11 files changed, 302 insertions(+), 40 deletions(-) create mode 100644 frameworks/core/components_v2/list/list_scroll_bar_controller.cpp create mode 100644 frameworks/core/components_v2/list/list_scroll_bar_controller.h diff --git a/frameworks/core/components/common/properties/scroll_bar.h b/frameworks/core/components/common/properties/scroll_bar.h index 716ee01d72b..f7983d3d37d 100644 --- a/frameworks/core/components/common/properties/scroll_bar.h +++ b/frameworks/core/components/common/properties/scroll_bar.h @@ -297,7 +297,7 @@ public: void SetScrollBarController(RefPtr controller) { - barController_ = controller; + barController_ = std::move(controller); } bool IsPressed() const diff --git a/frameworks/core/components/grid_layout/grid_layout_component.cpp b/frameworks/core/components/grid_layout/grid_layout_component.cpp index f6ce660038d..cf4826da68b 100644 --- a/frameworks/core/components/grid_layout/grid_layout_component.cpp +++ b/frameworks/core/components/grid_layout/grid_layout_component.cpp @@ -27,7 +27,7 @@ RefPtr GridLayoutComponent::CreateElement() { // judge to create GridLayoutElement for dynamic grid if (((rowsArgs_.empty() && (!columnsArgs_.empty())) || ((!rowsArgs_.empty()) && columnsArgs_.empty())) && - (maxCount_ >= minCount_) && (minCount_ >= 1) && (cellLength_ > 0) && (editMode_ == true)) { + (maxCount_ >= minCount_) && (minCount_ >= 1) && (cellLength_ > 0) && editMode_) { return AceType::MakeRefPtr(); } if (isDeclarative_ && useScroll_ && (rowsArgs_.empty() || columnsArgs_.empty())) { @@ -40,7 +40,7 @@ RefPtr GridLayoutComponent::CreateRenderNode() { // judge to create RenderGridLayout for dynamic grid if (((rowsArgs_.empty() && (!columnsArgs_.empty())) || ((!rowsArgs_.empty()) && columnsArgs_.empty())) && - (maxCount_ >= minCount_) && (minCount_ >= 1) && (cellLength_ > 0) && (editMode_ == true)) { + (maxCount_ >= minCount_) && (minCount_ >= 1) && (cellLength_ > 0) && editMode_) { return RenderGridLayout::Create(); } if (isDeclarative_ && useScroll_ && (rowsArgs_.empty() || columnsArgs_.empty())) { diff --git a/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp b/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp index eec16884119..5cf8f685a6a 100644 --- a/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp +++ b/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp @@ -251,8 +251,8 @@ Size ScrollBarProxy::GetScrollableChildSize( } auto renderList = AceType::DynamicCast(scrollable); if (renderList) { - scrollBarAxis == Axis::VERTICAL ? result.SetHeight(renderList->GetEstimatedHeight()) - : result.SetWidth(renderList->GetEstimatedHeight()); + scrollBarAxis == Axis::VERTICAL ? result.SetHeight(renderList->GetRealMainSize()) + : result.SetWidth(renderList->GetRealMainSize()); return result; } auto renderWaterFlow = AceType::DynamicCast(scrollable); @@ -287,10 +287,10 @@ void ScrollBarProxy::AdjustParam(const RefPtr& scrollable, Axis scro auto renderList = AceType::DynamicCast(scrollable); if (renderList) { - scrollBarAxis == Axis::VERTICAL ? scrollableChildSize.SetHeight(renderList->GetEstimatedHeight()) - : scrollableChildSize.SetWidth(renderList->GetEstimatedHeight()); + scrollBarAxis == Axis::VERTICAL ? scrollableChildSize.SetHeight(renderList->GetRealMainSize()) + : scrollableChildSize.SetWidth(renderList->GetRealMainSize()); scrollableAxis = renderList->GetAxis(); - scrollableChildPosition = renderList->GetLastOffset(); + scrollableChildPosition = renderList->GetCurrentOffset(); } auto renderWaterFlow = AceType::DynamicCast(scrollable); diff --git a/frameworks/core/components_v2/grid/render_grid_scroll.cpp b/frameworks/core/components_v2/grid/render_grid_scroll.cpp index 6282ddad100..719b58087e1 100644 --- a/frameworks/core/components_v2/grid/render_grid_scroll.cpp +++ b/frameworks/core/components_v2/grid/render_grid_scroll.cpp @@ -203,7 +203,6 @@ void RenderGridScroll::OnTouchTestHit( } else { scrollable_->SetCoordinateOffset(coordinateOffset); scrollable_->SetDragTouchRestrict(touchRestrict); - result.emplace_back(scrollable_); } result.emplace_back(scrollable_); } @@ -1075,7 +1074,7 @@ void RenderGridScroll::CalculateWholeSize(double drawLength) double RenderGridScroll::GetEstimatedHeight() { if (reachTail_) { - // reach the end og grid, update the total scroll bar length + // reach the end of grid, update the total scroll bar length estimateHeight_ = scrollBarExtent_; } else { estimateHeight_ = std::max(estimateHeight_, scrollBarExtent_); @@ -1085,6 +1084,10 @@ double RenderGridScroll::GetEstimatedHeight() void RenderGridScroll::InitScrollBar(const RefPtr& component) { + if (scrollBar_) { + scrollBar_->Reset(); + return; + } const RefPtr grid = AceType::DynamicCast(component); if (!grid) { LOGE("RenderGridLayout update failed."); @@ -1095,13 +1098,10 @@ void RenderGridScroll::InitScrollBar(const RefPtr& component) if (!theme) { return; } - if (scrollBar_) { - scrollBar_->Reset(); - } else { - RefPtr controller = AceType::MakeRefPtr(); - scrollBar_ = AceType::MakeRefPtr(grid->GetScrollBar(), theme->GetShapeMode()); - scrollBar_->SetScrollBarController(controller); - } + RefPtr controller = AceType::MakeRefPtr(); + scrollBar_ = AceType::MakeRefPtr(grid->GetScrollBar(), theme->GetShapeMode()); + scrollBar_->SetScrollBarController(controller); + // set the scroll bar style scrollBar_->SetReservedHeight(theme->GetReservedHeight()); scrollBar_->SetMinHeight(theme->GetMinHeight()); @@ -1161,7 +1161,7 @@ void RenderGridScroll::SetScrollBarCallback() return; } grid->scrollBarOpacity_ = value; - grid->MarkNeedLayout(true); + grid->MarkNeedRender(); }; auto&& scrollEndCallback = [weakGrid = AceType::WeakClaim(this)]() { auto grid = weakGrid.Upgrade(); diff --git a/frameworks/core/components_v2/list/BUILD.gn b/frameworks/core/components_v2/list/BUILD.gn index ff1753e7948..ef9f9f8e668 100644 --- a/frameworks/core/components_v2/list/BUILD.gn +++ b/frameworks/core/components_v2/list/BUILD.gn @@ -22,6 +22,7 @@ build_component("list_v2") { "list_item_component.cpp", "list_item_element.cpp", "list_position_controller.cpp", + "list_scroll_bar_controller.cpp", "render_list.cpp", "render_list_creator.cpp", "render_list_item.cpp", diff --git a/frameworks/core/components_v2/list/flutter_render_list.cpp b/frameworks/core/components_v2/list/flutter_render_list.cpp index 91cb43fb3e2..0c68ad4eadf 100644 --- a/frameworks/core/components_v2/list/flutter_render_list.cpp +++ b/frameworks/core/components_v2/list/flutter_render_list.cpp @@ -16,6 +16,7 @@ #include "core/components_v2/list/flutter_render_list.h" #include "base/utils/utils.h" +#include "core/components/common/painter/flutter_scroll_bar_painter.h" #include "core/pipeline/base/scoped_canvas_state.h" namespace OHOS::Ace::V2 { @@ -114,6 +115,34 @@ void FlutterRenderList::Paint(RenderContext& context, const Offset& offset) if (scrollBarProxy_) { scrollBarProxy_->NotifyScrollBar(AceType::WeakClaim(this)); } + + // paint scrollBar + if (scrollBar_ && scrollBar_->NeedPaint()) { + bool needPaint = false; + if (scrollBar_->GetFirstLoad() || scrollBar_->IsActive() || scrollBar_->GetDisplayMode() == DisplayMode::ON) { + scrollBarOpacity_ = UINT8_MAX; + needPaint = true; + } else { + if (scrollBarOpacity_ != 0) { + needPaint = true; + } + } + if (needPaint) { + scrollBar_->UpdateScrollBarRegion(offset, GetLayoutSize(), GetLastOffset(), GetEstimatedHeight()); + RefPtr scrollBarPainter = AceType::MakeRefPtr(); + const auto renderContext = static_cast(&context); + flutter::Canvas* canvas = renderContext->GetCanvas(); + if (!canvas) { + return; + } + scrollBarPainter->PaintBar( + canvas, offset, GetPaintRect(), scrollBar_, GetGlobalOffset(), scrollBarOpacity_); + if (scrollBar_->GetFirstLoad()) { + scrollBar_->SetFirstLoad(false); + scrollBar_->HandleScrollBarEnd(); + } + } + } } } // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/list/list_scroll_bar_controller.cpp b/frameworks/core/components_v2/list/list_scroll_bar_controller.cpp new file mode 100644 index 00000000000..f6e689df156 --- /dev/null +++ b/frameworks/core/components_v2/list/list_scroll_bar_controller.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "core/components_v2/list/list_scroll_bar_controller.h" +#include "core/components_v2/list/render_list.h" + +namespace OHOS::Ace::V2 { +void ListScrollBarController::MarkScrollRender() +{ + auto list = AceType::DynamicCast(scroll_.Upgrade()); + if (list) { + list->MarkNeedLayout(); + } +} + +bool ListScrollBarController::CheckScroll() +{ + auto list = AceType::DynamicCast(scroll_.Upgrade()); + return list != nullptr; +} + +bool ListScrollBarController::UpdateScrollPosition(const double offset, int32_t source) +{ + bool ret = true; + if (!callback_) { + return true; + } + auto list = AceType::DynamicCast(scroll_.Upgrade()); + if (!list || NearZero(list->GetEstimatedHeight())) { + return true; + } + double height = list->GetLayoutSize().Height(); + double estimateHeight = list->GetEstimatedHeight(); + if (NearZero(estimateHeight) || NearZero(height)) { + return true; + } + double activeHeight = height * height / estimateHeight; + if (!NearEqual(height, activeHeight)) { + double value = offset * estimateHeight / height; + ret = callback_(value, source); + } + return ret; +} + +void ListScrollBarController::ProcessScrollMotion(double position) +{ + if (!NearEqual(currentPos_, position)) { + UpdateScrollPosition(0.0, SCROLL_FROM_ANIMATION); + } else { + if (!UpdateScrollPosition(currentPos_ - position, SCROLL_FROM_BAR)) { + dragEndAnimator_->Stop(); + } + } + currentPos_ = position; +} +} // namespace OHOS::Ace::V2 \ No newline at end of file diff --git a/frameworks/core/components_v2/list/list_scroll_bar_controller.h b/frameworks/core/components_v2/list/list_scroll_bar_controller.h new file mode 100644 index 00000000000..86660059a53 --- /dev/null +++ b/frameworks/core/components_v2/list/list_scroll_bar_controller.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_SCROLL_BAR_CONTROLLER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_SCROLL_BAR_CONTROLLER_H + +#include "core/components/scroll/scroll_bar_controller.h" + +namespace OHOS::Ace::V2 { +class ListScrollBarController : public ScrollBarController { + DECLARE_ACE_TYPE(ListScrollBarController, ScrollBarController); + +public: + ListScrollBarController() = default; + ~ListScrollBarController() override = default; + + void MarkScrollRender() override; + bool CheckScroll() override; + +protected: + bool UpdateScrollPosition(double offset, int32_t source) override; + + void ProcessScrollMotion(double position) override; +}; +} // namespace OHOS::Ace::V2 +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_SCROLL_BAR_CONTROLLER_H \ No newline at end of file diff --git a/frameworks/core/components_v2/list/render_list.cpp b/frameworks/core/components_v2/list/render_list.cpp index 5717b3f46b6..52fe9e84a4b 100644 --- a/frameworks/core/components_v2/list/render_list.cpp +++ b/frameworks/core/components_v2/list/render_list.cpp @@ -24,6 +24,7 @@ #include "core/components/scroll/scroll_spring_effect.h" #include "core/components/stack/stack_element.h" #include "core/components_v2/list/list_component.h" +#include "core/components_v2/list/list_scroll_bar_controller.h" #include "core/event/axis_event.h" #include "core/gestures/long_press_recognizer.h" #include "core/gestures/pan_recognizer.h" @@ -100,6 +101,7 @@ void RenderList::Update(const RefPtr& component) { component_ = AceType::DynamicCast(component); ACE_DCHECK(component_); + InitScrollBar(); RemoveAllItems(); @@ -266,6 +268,68 @@ bool RenderList::IsReachStart() return scrollUpToReachStart || scrollDownToReachStart; } +void RenderList::InitScrollBar() +{ + if (scrollBar_) { + scrollBar_->Reset(); + return; + } + if (!component_) { + return; + } + const RefPtr theme = GetTheme(); + if (!theme) { + return; + } + + scrollBar_ = AceType::MakeRefPtr(component_->GetScrollBar(), theme->GetShapeMode()); + RefPtr controller = AceType::MakeRefPtr(); + scrollBar_->SetScrollBarController(controller); + + // set the scroll bar style + scrollBar_->SetReservedHeight(theme->GetReservedHeight()); + scrollBar_->SetMinHeight(theme->GetMinHeight()); + scrollBar_->SetMinDynamicHeight(theme->GetMinDynamicHeight()); + scrollBar_->SetForegroundColor(theme->GetForegroundColor()); + scrollBar_->SetBackgroundColor(theme->GetBackgroundColor()); + scrollBar_->SetPadding(theme->GetPadding()); + scrollBar_->SetScrollable(true); + scrollBar_->SetInactiveWidth(theme->GetNormalWidth()); + scrollBar_->SetNormalWidth(theme->GetNormalWidth()); + scrollBar_->SetActiveWidth(theme->GetActiveWidth()); + scrollBar_->SetTouchWidth(theme->GetTouchWidth()); + scrollBar_->InitScrollBar(AceType::WeakClaim(this), GetContext()); + SetScrollBarCallback(); +} + +void RenderList::SetScrollBarCallback() +{ + if (!scrollBar_ || !scrollBar_->NeedScrollBar()) { + return; + } + auto&& scrollCallback = [weakList = AceType::WeakClaim(this)](double value, int32_t source) { + auto list = weakList.Upgrade(); + if (!list) { + LOGE("render list is released"); + return false; + } + return list->UpdateScrollPosition(value, source); + }; + auto&& barEndCallback = [weakList = AceType::WeakClaim(this)](int32_t value) { + auto list = weakList.Upgrade(); + if (!list) { + LOGE("render list is released."); + return; + } + list->scrollBarOpacity_ = value; + list->MarkNeedRender(); + }; + auto&& scrollEndCallback = []() { + // nothing to do + }; + scrollBar_->SetCallBack(scrollCallback, barEndCallback, scrollEndCallback); +} + void RenderList::PerformLayout() { UpdateAccessibilityAttr(); @@ -278,7 +342,6 @@ void RenderList::PerformLayout() const auto innerLayout = MakeInnerLayout(); double curMainPos = LayoutOrRecycleCurrentItems(innerLayout, mainSize); - // Try to request new items at end if needed for (size_t newIndex = startIndex_ + items_.size();; ++newIndex) { if (cachedCount_ != 0) { @@ -367,7 +430,6 @@ void RenderList::PerformLayout() auto layoutSize = SetItemsPosition(mainSize, innerLayout); // Set layout size of list component itself - if ((hasHeight_ && vertical_) || (hasWidth_ && !vertical_)) { SetLayoutSize(GetLayoutParam().GetMaxSize()); } else { @@ -565,7 +627,7 @@ LayoutParam RenderList::MakeInnerLayout() return LayoutParam(maxSize, minSize); } -bool RenderList::GetCurMainPosAndMainSize(double &curMainPos, double &mainSize) +bool RenderList::GetCurMainPosAndMainSize(double& curMainPos, double& mainSize) { // Check validation of layout size mainSize = ApplyLayoutParam(); @@ -614,6 +676,10 @@ bool RenderList::UpdateScrollPosition(double offset, int32_t source) return true; } + if (scrollBar_ && scrollBar_->NeedScrollBar()) { + scrollBar_->SetActive(SCROLL_FROM_CHILD != source); + } + if (reachStart_ && reachEnd_) { return false; } @@ -691,8 +757,12 @@ void RenderList::OnTouchTestHit( if (!scrollable_ || !scrollable_->Available()) { return; } - - scrollable_->SetCoordinateOffset(coordinateOffset); + if (scrollBar_ && scrollBar_->InBarRegion(globalPoint_ - coordinateOffset)) { + scrollBar_->AddScrollBarController(coordinateOffset, result); + } else { + scrollable_->SetCoordinateOffset(coordinateOffset); + } + result.emplace_back(scrollable_); } double RenderList::ApplyLayoutParam() @@ -777,8 +847,8 @@ double RenderList::LayoutOrRecycleCurrentItems(const LayoutParam& layoutParam, d for (auto it = items_.begin(); it != items_.end(); ++curIndex) { if (startCachedCount_ > cachedCount_) { const auto& child = *(it); - double mainSize = GetMainSize(child->GetLayoutSize()); - curMainPosForRecycle += mainSize + spaceWidth_; + double childSize = GetMainSize(child->GetLayoutSize()); + curMainPosForRecycle += childSize + spaceWidth_; currentOffset_ = curMainPosForRecycle; startIndex_ = curIndex + 1; @@ -797,8 +867,8 @@ double RenderList::LayoutOrRecycleCurrentItems(const LayoutParam& layoutParam, d const auto& child = *(it); if (LessOrEqual(curMainPos, endMainPos_)) { child->Layout(layoutParam); - double mainSize = GetMainSize(child->GetLayoutSize()); - curMainPos += mainSize + spaceWidth_; + double childSize = GetMainSize(child->GetLayoutSize()); + curMainPos += childSize + spaceWidth_; if (GreatOrEqual(curMainPos, startMainPos_)) { ++it; continue; @@ -1109,6 +1179,22 @@ void RenderList::CalculateMainScrollExtent(double curMainPos, double mainSize) isOutOfBoundary_ = LessNotEqual(curMainPos, mainSize) || GreatNotEqual(currentOffset_, 0.0); // content length mainScrollExtent_ = curMainPos - currentOffset_; + if (GetChildren().empty()) { + return; + } + Size itemSize; // Calculate all children layout size. + for (const auto& child : GetChildren()) { + itemSize += child->GetLayoutSize(); + } + auto averageItemHeight = GetMainSize(itemSize) / GetChildren().size() + spaceWidth_; + estimatedHeight_ = averageItemHeight * TotalCount(); + lastOffset_ = startIndex_ * averageItemHeight - currentOffset_; + if (estimatedHeight_ <= GetMainSize(GetLayoutSize()) && scrollBar_) { + LOGD("SetScrollable false, do not show scroll bar."); + scrollBar_->SetScrollable(false); + } else { + scrollBar_->SetScrollable(true); + } } void RenderList::ProcessDragStart(double startPosition) @@ -1777,9 +1863,7 @@ bool RenderList::IsAxisScrollable(AxisDirection direction) ((AxisEvent::IsDirectionDown(direction) || AxisEvent::IsDirectionRight(direction)) && !reachEnd_)); } -void RenderList::HandleAxisEvent(const AxisEvent& event) -{ -} +void RenderList::HandleAxisEvent(const AxisEvent& event) {} bool RenderList::HandleMouseEvent(const MouseEvent& event) { diff --git a/frameworks/core/components_v2/list/render_list.h b/frameworks/core/components_v2/list/render_list.h index 799e5d54a22..ed636a98669 100644 --- a/frameworks/core/components_v2/list/render_list.h +++ b/frameworks/core/components_v2/list/render_list.h @@ -163,16 +163,26 @@ public: return component_; } - Offset GetLastOffset() const + Offset GetCurrentOffset() const { return vertical_ ? Offset(0.0, -currentOffset_) : Offset(-currentOffset_, 0.0); } - double GetEstimatedHeight() const + double GetRealMainSize() const { return realMainSize_; } + double GetEstimatedHeight() const + { + return estimatedHeight_; + } + + Offset GetLastOffset() const + { + return vertical_ ? Offset(0.0, lastOffset_) : Offset(lastOffset_, 0.0); + } + Dimension GetListSpace() const { return listSpace_; @@ -317,6 +327,7 @@ protected: std::list> items_; double spaceWidth_ = 0.0; + double lastOffset_ = 0.0; double startMainPos_ = 0.0; double endMainPos_ = 0.0; double currentOffset_ = 0.0; @@ -350,7 +361,8 @@ protected: WeakPtr itemGenerator_; RefPtr scrollable_; RefPtr scrollEffect_; - RefPtr scrollBarProxy_; + RefPtr scrollBarProxy_; // user defined scroll bar + RefPtr scrollBar_; // system defined scroll bar size_t currentStickyIndex_ = INITIAL_CHILD_INDEX; RefPtr currentStickyItem_; @@ -374,8 +386,10 @@ protected: Offset mouseStartOffset_; Offset mouseEndOffset_; int32_t focusIndex_ = 0; + int32_t scrollBarOpacity_ = 0; double prevOffset_ = 0.0; double prevMainPos_ = 0.0; + double estimatedHeight_ = 0.0; private: bool IsReachStart(); @@ -383,6 +397,8 @@ private: bool ActionByScroll(bool forward, ScrollEventBack scrollEventBack); void ModifyActionScroll(); void InitScrollBarProxy(); + void InitScrollBar(); + void SetScrollBarCallback(); Dimension listSpace_; double realMainSize_ = 0.0; // Real size of main axis. size_t startCachedCount_ = 0; diff --git a/frameworks/core/components_v2/list/rosen_render_list.cpp b/frameworks/core/components_v2/list/rosen_render_list.cpp index 198252eef18..1d158025bd5 100644 --- a/frameworks/core/components_v2/list/rosen_render_list.cpp +++ b/frameworks/core/components_v2/list/rosen_render_list.cpp @@ -18,6 +18,7 @@ #include "render_service_client/core/ui/rs_node.h" #include "base/utils/utils.h" +#include "core/components/common/painter/rosen_scroll_bar_painter.h" #include "core/pipeline/base/rosen_render_context.h" namespace OHOS::Ace::V2 { @@ -49,14 +50,16 @@ void RosenRenderList::Paint(RenderContext& context, const Offset& offset) PaintChild(child, context, offset); } + const auto renderContext = static_cast(&context); + auto canvas = renderContext->GetCanvas(); + auto rsNode = renderContext->GetRSNode(); + if (!canvas || !rsNode) { + LOGE("canvas is null"); + return; + } + rsNode->SetPaintOrder(true); const auto& divider = component_->GetItemDivider(); if (divider && divider->color.GetAlpha() > 0x00 && GreatNotEqual(divider->strokeWidth.Value(), 0.0)) { - auto canvas = static_cast(&context)->GetCanvas(); - if (canvas == nullptr) { - LOGE("skia canvas is null"); - return; - } - const double mainSize = GetMainSize(layoutSize); const double strokeWidth = NormalizePercentToPx(divider->strokeWidth, vertical_); const double halfSpaceWidth = std::max(spaceWidth_, strokeWidth) / 2.0; @@ -110,6 +113,29 @@ void RosenRenderList::Paint(RenderContext& context, const Offset& offset) PaintChild(selectedItem_, context, offset); } + // paint scrollBar + if (scrollBar_ && scrollBar_->NeedPaint()) { + bool needPaint = false; + if (scrollBar_->GetFirstLoad() || scrollBar_->IsActive() || scrollBar_->GetDisplayMode() == DisplayMode::ON) { + scrollBarOpacity_ = UINT8_MAX; + needPaint = true; + } else { + if (scrollBarOpacity_ != 0) { + needPaint = true; + } + } + if (needPaint) { + scrollBar_->UpdateScrollBarRegion(offset, GetLayoutSize(), GetLastOffset(), GetEstimatedHeight()); + RefPtr scrollBarPainter = AceType::MakeRefPtr(); + scrollBarPainter->PaintBar( + canvas, offset, GetPaintRect(), scrollBar_, GetGlobalOffset(), scrollBarOpacity_); + if (scrollBar_->GetFirstLoad()) { + scrollBar_->SetFirstLoad(false); + scrollBar_->HandleScrollBarEnd(); + } + } + } + PaintSelectedZone(context); } @@ -122,7 +148,7 @@ void RosenRenderList::PaintSelectedZone(RenderContext& context) } SkRect skRect = SkRect::MakeXYWH(mouseStartOffset_.GetX(), mouseStartOffset_.GetY(), - mouseEndOffset_.GetX()-mouseStartOffset_.GetX(), mouseEndOffset_.GetY()-mouseStartOffset_.GetY()); + mouseEndOffset_.GetX() - mouseStartOffset_.GetX(), mouseEndOffset_.GetY() - mouseStartOffset_.GetY()); SkPaint fillGeometry; fillGeometry.setAntiAlias(true); -- Gitee From ed2e40575b39337326ab51fc944894dc15c0f361 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Fri, 27 May 2022 01:14:37 +0000 Subject: [PATCH 2/3] update frameworks/core/components_v2/list/list_scroll_bar_controller.cpp. Signed-off-by: jiangdayuan --- .../core/components_v2/list/list_scroll_bar_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/core/components_v2/list/list_scroll_bar_controller.cpp b/frameworks/core/components_v2/list/list_scroll_bar_controller.cpp index f6e689df156..92dac88c87c 100644 --- a/frameworks/core/components_v2/list/list_scroll_bar_controller.cpp +++ b/frameworks/core/components_v2/list/list_scroll_bar_controller.cpp @@ -38,7 +38,7 @@ bool ListScrollBarController::UpdateScrollPosition(const double offset, int32_t return true; } auto list = AceType::DynamicCast(scroll_.Upgrade()); - if (!list || NearZero(list->GetEstimatedHeight())) { + if (!list) { return true; } double height = list->GetLayoutSize().Height(); -- Gitee From ad1a81054538a9ba747eb793b9a48a2665c19713 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Fri, 27 May 2022 04:15:29 +0000 Subject: [PATCH 3/3] update frameworks/core/components_v2/list/list_scroll_bar_controller.h. Signed-off-by: jiangdayuan --- .../core/components_v2/list/list_scroll_bar_controller.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/core/components_v2/list/list_scroll_bar_controller.h b/frameworks/core/components_v2/list/list_scroll_bar_controller.h index 86660059a53..f0b3421bf3c 100644 --- a/frameworks/core/components_v2/list/list_scroll_bar_controller.h +++ b/frameworks/core/components_v2/list/list_scroll_bar_controller.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_SCROLL_BAR_CONTROLLER_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_SCROLL_BAR_CONTROLLER_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_LIST_LIST_SCROLL_BAR_CONTROLLER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_LIST_LIST_SCROLL_BAR_CONTROLLER_H #include "core/components/scroll/scroll_bar_controller.h" @@ -35,4 +35,4 @@ protected: void ProcessScrollMotion(double position) override; }; } // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_SCROLL_BAR_CONTROLLER_H \ No newline at end of file +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_LIST_LIST_SCROLL_BAR_CONTROLLER_H \ No newline at end of file -- Gitee