From a84e09d82555c36a077cfb28d7fb0da6415149d2 Mon Sep 17 00:00:00 2001 From: yanshuifeng Date: Thu, 28 Apr 2022 13:36:28 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!2056=20?= =?UTF-8?q?:=20wateflow=E7=BB=84=E4=BB=B6=E9=9C=80=E6=B1=82'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bridge/declarative_frontend/BUILD.gn | 2 - .../engine/jsi/jsi_view_register.cpp | 6 +- .../engine/quickjs/qjs_view_register.cpp | 5 - .../engine/v8/v8_view_register.cpp | 6 +- .../jsview/js_water_flow.cpp | 150 -- .../jsview/js_water_flow.h | 33 - .../jsview/js_water_flow_item.cpp | 60 - .../jsview/js_water_flow_item.h | 32 - .../view_stack_processor.cpp | 7 +- frameworks/core/BUILD.gn | 1 - .../scroll_bar/scroll_bar_proxy.cpp | 22 +- .../core/components/test/unittest/BUILD.gn | 3 +- .../test/unittest/water_flow/BUILD.gn | 45 - .../water_flow/render_water_flow_test.cpp | 846 -------- .../water_flow/water_flow_test_utils.cpp | 92 - .../water_flow/water_flow_test_utils.h | 71 - .../core/components_v2/water_flow/BUILD.gn | 31 - .../water_flow/flutter_render_water_flow.cpp | 71 - .../water_flow/flutter_render_water_flow.h | 37 - .../water_flow/render_water_flow.cpp | 1808 ----------------- .../water_flow/render_water_flow.h | 327 --- .../water_flow/render_water_flow_creator.cpp | 32 - .../water_flow/render_water_flow_item.cpp | 84 - .../water_flow/render_water_flow_item.h | 122 -- .../water_flow/rosen_render_water_flow.cpp | 77 - .../water_flow/rosen_render_water_flow.h | 35 - .../water_flow/water_flow_component.cpp | 114 -- .../water_flow/water_flow_component.h | 136 -- .../water_flow/water_flow_element.cpp | 214 -- .../water_flow/water_flow_element.h | 49 - .../water_flow/water_flow_item_component.cpp | 49 - .../water_flow/water_flow_item_component.h | 100 - .../water_flow/water_flow_item_element.cpp | 39 - .../water_flow/water_flow_item_element.h | 38 - .../water_flow_position_controller.cpp | 66 - .../water_flow_position_controller.h | 38 - .../water_flow_scroll_controller.cpp | 71 - .../water_flow/water_flow_scroll_controller.h | 38 - 38 files changed, 7 insertions(+), 4950 deletions(-) delete mode 100644 frameworks/bridge/declarative_frontend/jsview/js_water_flow.cpp delete mode 100644 frameworks/bridge/declarative_frontend/jsview/js_water_flow.h delete mode 100644 frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.cpp delete mode 100644 frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h delete mode 100644 frameworks/core/components/test/unittest/water_flow/BUILD.gn delete mode 100644 frameworks/core/components/test/unittest/water_flow/render_water_flow_test.cpp delete mode 100644 frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.cpp delete mode 100644 frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.h delete mode 100644 frameworks/core/components_v2/water_flow/BUILD.gn delete mode 100644 frameworks/core/components_v2/water_flow/flutter_render_water_flow.cpp delete mode 100644 frameworks/core/components_v2/water_flow/flutter_render_water_flow.h delete mode 100644 frameworks/core/components_v2/water_flow/render_water_flow.cpp delete mode 100644 frameworks/core/components_v2/water_flow/render_water_flow.h delete mode 100644 frameworks/core/components_v2/water_flow/render_water_flow_creator.cpp delete mode 100644 frameworks/core/components_v2/water_flow/render_water_flow_item.cpp delete mode 100644 frameworks/core/components_v2/water_flow/render_water_flow_item.h delete mode 100644 frameworks/core/components_v2/water_flow/rosen_render_water_flow.cpp delete mode 100644 frameworks/core/components_v2/water_flow/rosen_render_water_flow.h delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_component.cpp delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_component.h delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_element.cpp delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_element.h delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_item_component.cpp delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_item_component.h delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_item_element.cpp delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_item_element.h delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_position_controller.cpp delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_position_controller.h delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_scroll_controller.cpp delete mode 100644 frameworks/core/components_v2/water_flow/water_flow_scroll_controller.h diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index 10d92720..c5038371 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -224,8 +224,6 @@ template("declarative_js_engine") { "jsview/js_view_context.cpp", "jsview/js_view_functions.cpp", "jsview/js_view_stack_processor.cpp", - "jsview/js_water_flow.cpp", - "jsview/js_water_flow_item.cpp", "jsview/menu/js_context_menu.cpp", "jsview/scroll_bar/js_scroll_bar.cpp", "sharedata/js_share_data.cpp", diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp index 9a02c59a..fa3bb5a1 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp @@ -140,8 +140,6 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_view.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_context.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h" #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h" #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h" @@ -928,9 +926,7 @@ static const std::unordered_map> { "TextTimerController", JSTextTimerController::JSBind }, { "Checkbox", JSCheckbox::JSBind }, { "CheckboxGroup", JSCheckboxGroup::JSBind }, - { "Refresh", JSRefresh::JSBind }, - { "WaterFlow", JSWaterFlow::JSBind }, - { "FlowItem", JSWaterFlowItem::JSBind } + { "Refresh", JSRefresh::JSBind } }; void RegisterAllModule(BindingTarget globalObj) diff --git a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp index 01d7abdc..314ecec7 100644 --- a/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/quickjs/qjs_view_register.cpp @@ -140,8 +140,6 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_view_register.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.h" #include "frameworks/bridge/declarative_frontend/jsview/js_local_storage.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h" #ifdef XCOMPONENT_SUPPORTED #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h" #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h" @@ -954,9 +952,6 @@ void JsRegisterViews(BindingTarget globalObj) JSTextPickerDialog::JSBind(globalObj); JSCheckbox::JSBind(globalObj); JSCheckboxGroup::JSBind(globalObj); - JSWaterFlow::JSBind(globalObj); - JSWaterFlowItem::JSBind(globalObj); - JSObjectTemplate toggleType; toggleType.Constant("Checkbox", 0); diff --git a/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp index c04c39cd..98f120cd 100644 --- a/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/v8/v8_view_register.cpp @@ -136,8 +136,6 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_view.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_context.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h" #if !defined(WINDOWS_PLATFORM) and !defined(MAC_PLATFORM) #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h" #include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h" @@ -698,9 +696,7 @@ static const std::unordered_map> {"TextTimerController", JSTextTimerController::JSBind}, {"TextClockController", JSTextClockController::JSBind}, {"Checkbox", JSCheckbox::JSBind}, - {"CheckboxGroup", JSCheckboxGroup::JSBind}, - {"WaterFlow", JSWaterFLow::JSBind}, - {"FlowItem", JSFLowItem::JSBind} + {"CheckboxGroup", JSCheckboxGroup::JSBind} }; void RegisterAllModule(BindingTarget globalObj) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_water_flow.cpp b/frameworks/bridge/declarative_frontend/jsview/js_water_flow.cpp deleted file mode 100644 index 69bee2c4..00000000 --- a/frameworks/bridge/declarative_frontend/jsview/js_water_flow.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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 "frameworks/bridge/declarative_frontend/jsview/js_water_flow.h" - -#include "bridge/declarative_frontend/jsview/js_view_common_def.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_scroller.h" -#include "frameworks/bridge/declarative_frontend/view_stack_processor.h" -#include "frameworks/core/components_v2/water_flow/water_flow_component.h" - -namespace OHOS::Ace::Framework { -namespace { -const std::vector LAYOUT_DIRECTION = { FlexDirection::ROW, FlexDirection::COLUMN, - FlexDirection::ROW_REVERSE, FlexDirection::COLUMN_REVERSE }; -} // namespace - -void JSWaterFlow::Create(const JSCallbackInfo& args) -{ - LOGI("Create component: WaterFLow"); - if (args.Length() < 1) { - LOGE("Arg is wrong, it is supposed to have at least 1 arguments"); - return; - } - - if (!args[0]->IsObject()) { - LOGE("Arg is not object"); - return; - } - - JSRef obj = JSRef::Cast(args[0]); - JSRef crossSplice = obj->GetProperty("crossSplice"); - if (!crossSplice->IsNumber()) { - LOGW("Args is invalid"); - return; - } - - // create waterflow component - std::list> componentChildren; - auto waterflowComponent = - AceType::MakeRefPtr(componentChildren, crossSplice->ToNumber()); - - // mainLength - JSRef jsMainLength = obj->GetProperty("mainLength"); - Dimension mainLength; - if (ParseJsDimensionVp(jsMainLength, mainLength)) { - waterflowComponent->SetMainLength(mainLength); - } else { - LOGW("The parameter of mainLength not exists."); - } - - // scroller - if (args.Length() > 1 && args[1]->IsObject()) { - JSScroller* jsScroller = JSRef::Cast(args[1])->Unwrap(); - if (jsScroller) { - auto positionController = AceType::MakeRefPtr(); - jsScroller->SetController(positionController); - waterflowComponent->SetController(positionController); - - // Init scroll bar proxy. - auto proxy = jsScroller->GetScrollBarProxy(); - if (!proxy) { - proxy = AceType::MakeRefPtr(); - jsScroller->SetScrollBarProxy(proxy); - } - waterflowComponent->SetScrollBarProxy(proxy); - } - } else { - LOGW("The parameter of scroller not exists."); - } - - ViewStackProcessor::GetInstance()->Push(waterflowComponent); -} - -void JSWaterFlow::JSBind(BindingTarget globalObj) -{ - LOGD("JSWaterFlow:JSBind"); - JSClass::Declare("WaterFlow"); - - MethodOptions opt = MethodOptions::NONE; - JSClass::StaticMethod("create", &JSWaterFlow::Create, opt); - JSClass::StaticMethod("columnsGap", &JSWaterFlow::SetColumnsGap, opt); - JSClass::StaticMethod("rowsGap", &JSWaterFlow::SetRowsGap, opt); - JSClass::StaticMethod("layoutDirection", &JSWaterFlow::SetLayoutDirection, opt); - JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); - JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); - - JSClass::Inherit(); - JSClass::Inherit(); - JSClass::Bind<>(globalObj); -} - -void JSWaterFlow::SetColumnsGap(const JSCallbackInfo& info) -{ - if (info.Length() < 1) { - LOGE("Arg is wrong, it is supposed to have at least 1 argument"); - return; - } - Dimension colGap; - if (!ParseJsDimensionVp(info[0], colGap)) { - return; - } - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto waterflow = AceType::DynamicCast(component); - if (waterflow) { - waterflow->SetColumnsGap(colGap); - } -} - -void JSWaterFlow::SetRowsGap(const JSCallbackInfo& info) -{ - if (info.Length() < 1) { - LOGE("Arg is wrong, it is supposed to have at least 1 argument"); - return; - } - Dimension rowGap; - if (!ParseJsDimensionVp(info[0], rowGap)) { - return; - } - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto waterflow = AceType::DynamicCast(component); - if (waterflow) { - waterflow->SetRowsGap(rowGap); - } -} - -void JSWaterFlow::SetLayoutDirection(int32_t value) -{ - if (value >= 0 && value < static_cast(LAYOUT_DIRECTION.size())) { - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto waterflow = AceType::DynamicCast(component); - if (waterflow) { - // not support the other layoutDirection except default for now. - waterflow->SetLayoutDirection(FlexDirection::COLUMN); - } - } -} -} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_water_flow.h b/frameworks/bridge/declarative_frontend/jsview/js_water_flow.h deleted file mode 100644 index 6889efed..00000000 --- a/frameworks/bridge/declarative_frontend/jsview/js_water_flow.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_H -#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_H - -#include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" - -namespace OHOS::Ace::Framework { -class JSWaterFlow : public JSContainerBase { -public: - static void Create(const JSCallbackInfo& args); - static void JSBind(BindingTarget globalObj); - -protected: - static void SetColumnsGap(const JSCallbackInfo& info); - static void SetRowsGap(const JSCallbackInfo& info); - static void SetLayoutDirection(int32_t value); -}; -} // namespace OHOS::Ace::Framework -#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_H diff --git a/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.cpp b/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.cpp deleted file mode 100644 index 3f40d9c9..00000000 --- a/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 "frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h" - -#include "frameworks/bridge/declarative_frontend/view_stack_processor.h" -#include "frameworks/core/components_v2/water_flow/water_flow_item_component.h" - -namespace OHOS::Ace::Framework { -void JSWaterFlowItem::Create() -{ - auto itemComponent = AceType::MakeRefPtr(); - ViewStackProcessor::GetInstance()->Push(itemComponent); -} - -void JSWaterFlowItem::JSBind(BindingTarget globalObj) -{ - LOGD("JSWaterFlowItem:JSBind"); - JSClass::Declare("FlowItem"); - - MethodOptions opt = MethodOptions::NONE; - JSClass::StaticMethod("create", &JSWaterFlowItem::Create, opt); - JSClass::StaticMethod("rowSpan", &JSWaterFlowItem::SetRowSpan, opt); - JSClass::StaticMethod("columnSpan", &JSWaterFlowItem::SetColumnSpan, opt); - - JSClass::Inherit(); - JSClass::Inherit(); - JSClass::Bind<>(globalObj); -} - -void JSWaterFlowItem::SetRowSpan(int32_t rowSpan) -{ - auto flowItem = - AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); - if (flowItem) { - flowItem->SetRowSpan(rowSpan); - } -} - -void JSWaterFlowItem::SetColumnSpan(int32_t columnSpan) -{ - auto flowItem = - AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); - if (flowItem) { - flowItem->SetColumnSpan(columnSpan); - } -} -} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h b/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h deleted file mode 100644 index cfce3720..00000000 --- a/frameworks/bridge/declarative_frontend/jsview/js_water_flow_item.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_ITEM_H -#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_ITEM_H - -#include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h" - -namespace OHOS::Ace::Framework { -class JSWaterFlowItem : public JSContainerBase { -public: - static void JSBind(BindingTarget globalObj); - static void Create(); - -protected: - static void SetRowSpan(int32_t rowSpan); - static void SetColumnSpan(int32_t columnSpan); -}; -} // namespace OHOS::Ace::Framework -#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_WATER_FLOW_ITEM_H diff --git a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp index a3c3cd81..262af9d7 100644 --- a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp +++ b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp @@ -35,7 +35,6 @@ #include "core/components/web/web_component.h" #include "core/components/xcomponent/xcomponent_component.h" #include "core/components_v2/list/list_item_component.h" -#include "core/components_v2/water_flow/water_flow_item_component.h" #include "core/pipeline/base/component.h" #include "core/pipeline/base/multi_composed_component.h" #include "core/pipeline/base/sole_child_component.h" @@ -559,8 +558,7 @@ RefPtr ViewStackProcessor::WrapComponents() std::unordered_map> videoMap; bool isItemComponent = AceType::InstanceOf(mainComponent) || - AceType::InstanceOf(mainComponent) || - AceType::InstanceOf(mainComponent); + AceType::InstanceOf(mainComponent); RefPtr itemChildComponent; @@ -818,7 +816,8 @@ RefPtr ViewStackProcessor::GetScoringComponent() const void ViewStackProcessor::CreateInspectorComposedComponent(const std::string& inspectorTag) { if (V2::InspectorComposedComponent::HasInspectorFinished(inspectorTag)) { - auto composedComponent = AceType::MakeRefPtr(GenerateId(), inspectorTag); + auto composedComponent = + AceType::MakeRefPtr(GenerateId(), inspectorTag); auto& wrappingComponentsMap = componentsStack_.top(); wrappingComponentsMap.emplace("inspector", composedComponent); } diff --git a/frameworks/core/BUILD.gn b/frameworks/core/BUILD.gn index f50fb61a..2c6f865e 100644 --- a/frameworks/core/BUILD.gn +++ b/frameworks/core/BUILD.gn @@ -327,7 +327,6 @@ template("ace_core_source_set") { "$ace_root/frameworks/core/components_v2/pattern_lock:ace_core_components_pattern_lock_$platform", "$ace_root/frameworks/core/components_v2/swiper:ace_core_components_swiper_v2_$platform", "$ace_root/frameworks/core/components_v2/tabs:ace_core_components_tabs_v2_$platform", - "$ace_root/frameworks/core/components_v2/water_flow:ace_core_components_water_flow_v2_$platform", ] if (defined(config.enable_rosen_backend) && config.enable_rosen_backend) { diff --git a/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp b/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp index eec16884..f4a4b6c0 100644 --- a/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp +++ b/frameworks/core/components/scroll_bar/scroll_bar_proxy.cpp @@ -19,7 +19,6 @@ #include "core/components/scroll_bar/render_scroll_bar.h" #include "core/components_v2/grid/render_grid_scroll.h" #include "core/components_v2/list/render_list.h" -#include "core/components_v2/water_flow/render_water_flow.h" namespace OHOS::Ace { @@ -209,7 +208,7 @@ void ScrollBarProxy::StopScrollBarAnimator() const bool ScrollBarProxy::CheckScrollable(const RefPtr& node) const { return AceType::InstanceOf(node) || AceType::InstanceOf(node) || - AceType::InstanceOf(node) || AceType::InstanceOf(node); + AceType::InstanceOf(node); } Axis ScrollBarProxy::GetScrollableAxis(const RefPtr& node) const @@ -226,10 +225,6 @@ Axis ScrollBarProxy::GetScrollableAxis(const RefPtr& node) const if (renderList) { return renderList->GetAxis(); } - auto renderWaterFlow = AceType::DynamicCast(node); - if (renderWaterFlow) { - return renderWaterFlow->GetAxis(); - } return Axis::NONE; } @@ -255,12 +250,6 @@ Size ScrollBarProxy::GetScrollableChildSize( : result.SetWidth(renderList->GetEstimatedHeight()); return result; } - auto renderWaterFlow = AceType::DynamicCast(scrollable); - if (renderWaterFlow) { - scrollBarAxis == Axis::VERTICAL ? result.SetHeight(renderWaterFlow->GetEstimatedHeight()) - : result.SetWidth(renderWaterFlow->GetEstimatedHeight()); - return result; - } return result; } @@ -292,15 +281,6 @@ void ScrollBarProxy::AdjustParam(const RefPtr& scrollable, Axis scro scrollableAxis = renderList->GetAxis(); scrollableChildPosition = renderList->GetLastOffset(); } - - auto renderWaterFlow = AceType::DynamicCast(scrollable); - if (renderWaterFlow) { - scrollBarAxis == Axis::VERTICAL ? scrollableChildSize.SetHeight(renderWaterFlow->GetEstimatedHeight()) - : scrollableChildSize.SetWidth(renderWaterFlow->GetEstimatedHeight()); - scrollableAxis = renderWaterFlow->GetAxis(); - scrollableChildPosition = renderWaterFlow->GetLastOffset(); - return; - } } } // namespace OHOS::Ace \ No newline at end of file diff --git a/frameworks/core/components/test/unittest/BUILD.gn b/frameworks/core/components/test/unittest/BUILD.gn index a5979e26..8c7c7879 100644 --- a/frameworks/core/components/test/unittest/BUILD.gn +++ b/frameworks/core/components/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2021 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 @@ -65,7 +65,6 @@ group("unittest") { "tween:unittest", #"view_update:unittest", - "water_flow:unittest", "wrap:unittest", ] if (!is_wearable_product) { diff --git a/frameworks/core/components/test/unittest/water_flow/BUILD.gn b/frameworks/core/components/test/unittest/water_flow/BUILD.gn deleted file mode 100644 index ec248b08..00000000 --- a/frameworks/core/components/test/unittest/water_flow/BUILD.gn +++ /dev/null @@ -1,45 +0,0 @@ -# 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. - -import("//build/test.gni") -import("//foundation/arkui/ace_engine/ace_config.gni") - -if (is_standard_system) { - module_output_path = "ace_engine_standard/backenduicomponent/water_flow" -} else { - module_output_path = "ace_engine_full/backenduicomponent/water_flow" -} - -ohos_unittest("RenderWaterFlowTest") { - module_out_path = module_output_path - - sources = [ - "$ace_root/frameworks/core/components/test/json/json_frontend.cpp", - "$ace_root/frameworks/core/components/test/unittest/mock/mock_render_common.cpp", - "render_water_flow_test.cpp", - "water_flow_test_utils.cpp", - ] - - configs = [ "$ace_root:ace_test_config" ] - - deps = [ "$ace_root/build:ace_ohos_unittest_base" ] - - part_name = ace_engine_part -} - -group("unittest") { - testonly = true - deps = [] - - deps = [ ":RenderWaterFlowTest" ] -} diff --git a/frameworks/core/components/test/unittest/water_flow/render_water_flow_test.cpp b/frameworks/core/components/test/unittest/water_flow/render_water_flow_test.cpp deleted file mode 100644 index 432c6efd..00000000 --- a/frameworks/core/components/test/unittest/water_flow/render_water_flow_test.cpp +++ /dev/null @@ -1,846 +0,0 @@ -/* - * 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 "gtest/gtest.h" - -#include "core/components/test/unittest/mock/mock_render_common.h" - -#define private public -#define protected public -#include "core/components/test/unittest/water_flow/water_flow_test_utils.h" -#include "core/components_v2/water_flow/render_water_flow.h" -#undef private -#undef protected - -using namespace testing; -using namespace testing::ext; -using RenderWaterFlow = OHOS::Ace::V2::RenderWaterFlow; -using RenderWaterFlowItem = OHOS::Ace::V2::RenderWaterFlowItem; -using WaterFlowComponent = OHOS::Ace::V2::WaterFlowComponent; -using WaterFlowItemComponent = OHOS::Ace::V2::WaterFlowItemComponent; -using WaterFlowPositionController = OHOS::Ace::V2::WaterFlowPositionController; - -namespace OHOS::Ace { -constexpr int32_t WATER_FLOW_COLUMNS_NUMBERS = 5; -constexpr Dimension height = 160.0_px; -constexpr double view_width = 1000.0; -constexpr double view_height = 1000.0; -constexpr double rowGap = 50.0; -constexpr double colGap = 50.0; -constexpr int32_t rowCount = 5; -constexpr int32_t colCount = 5; - -class RenderWaterFlowTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - - void CreateWaterFlow(int32_t itemMainSpan, int32_t itemCrossSpan); - void CreateWaterFlowDefaultHeight(); - void FillItems( - int32_t index, int32_t MainSpan, int32_t CrossSpan, int32_t callbackMainSpan, int32_t callbackCrossSpan); - void SetCallback(int32_t itemMainSpan, int32_t itemCrossSpan); - - RefPtr mockContext_; - RefPtr renderNode_; - const int32_t render_component_count = 5; -}; - -void RenderWaterFlowTest::SetUpTestCase() {} -void RenderWaterFlowTest::TearDownTestCase() {} - -void RenderWaterFlowTest::SetUp() -{ - mockContext_ = MockRenderCommon::GetMockContext(); - renderNode_ = AceType::MakeRefPtr(); - renderNode_->Attach(mockContext_); -} - -void RenderWaterFlowTest::TearDown() -{ - mockContext_ = nullptr; - renderNode_ = nullptr; -} - -void RenderWaterFlowTest::CreateWaterFlow(int32_t itemMainSpan, int32_t itemCrossSpan) -{ - auto Component = WaterFlowTestUtils::CreateComponent(FlexDirection::COLUMN, WATER_FLOW_COLUMNS_NUMBERS); - auto waterflowComponent = AceType::DynamicCast(Component); - if (!waterflowComponent) { - GTEST_LOG_(INFO) << "create WaterFlow component failed!"; - return; - } - RefPtr controller = AceType::MakeRefPtr(); - RefPtr scrollBarProxy = AceType::MakeRefPtr(); - waterflowComponent->SetController(controller); - waterflowComponent->SetScrollBarProxy(scrollBarProxy); - waterflowComponent->SetMainLength(height); - if (renderNode_ == nullptr) { - GTEST_LOG_(INFO) << "renderNode_ == nullptr!"; - } - renderNode_->mainSize_ = view_height; - renderNode_->crossSize_ = view_width; - renderNode_->mainCount_ = rowCount; - renderNode_->crossCount_ = colCount; - renderNode_->mainGap_ = rowGap; - renderNode_->crossGap_ = colGap; - renderNode_->useScrollable_ = V2::RenderWaterFlow::SCROLLABLE::VERTICAL; - DisplayMode displayMode = DisplayMode::AUTO; - renderNode_->scrollBar_ = AceType::MakeRefPtr(displayMode); - renderNode_->totalCountFlag_ = true; - renderNode_->GetChildViewPort().SetWidth(view_width); - renderNode_->GetChildViewPort().SetHeight(view_height); - SetCallback(itemMainSpan, itemCrossSpan); - renderNode_->Update(waterflowComponent); -} - -void RenderWaterFlowTest::CreateWaterFlowDefaultHeight() -{ - auto Component = WaterFlowTestUtils::CreateComponent(FlexDirection::ROW, WATER_FLOW_COLUMNS_NUMBERS); - auto waterflowComponent = AceType::DynamicCast(Component); - if (!waterflowComponent) { - GTEST_LOG_(INFO) << "create WaterFlow component failed!"; - return; - } - RefPtr controller = AceType::MakeRefPtr(); - RefPtr scrollBarProxy = AceType::MakeRefPtr(); - waterflowComponent->SetController(controller); - waterflowComponent->SetScrollBarProxy(scrollBarProxy); - renderNode_->Update(waterflowComponent); -} - -void RenderWaterFlowTest::FillItems( - int32_t index, int32_t itemMainSpan, int32_t itemCrossSpan, int32_t callbackMainSpan, int32_t callbackCrossSpan) -{ - CreateWaterFlow(callbackMainSpan, callbackCrossSpan); - auto item = WaterFlowTestUtils::CreateRenderItem(itemMainSpan, itemCrossSpan, index, mockContext_); - auto flowitem = AceType::DynamicCast(item); - if (flowitem == nullptr) { - GTEST_LOG_(INFO) << "flowitem == nullptr!"; - return; - } - renderNode_->AddChildByIndex(index, flowitem); -} - -void RenderWaterFlowTest::SetCallback(int32_t callMainSpan, int32_t callCrossSpan) -{ - renderNode_->SetBuildChildByIndex([this, callMainSpan, callCrossSpan](int32_t index) { - GTEST_LOG_(INFO) << "SetBuildChildByIndex called!"; - auto item = WaterFlowTestUtils::CreateRenderItem(callMainSpan, callCrossSpan, index, mockContext_); - if (item) { - item->GetChildren().front()->Attach(mockContext_); - item->Attach(mockContext_); - renderNode_->AddChildByIndex(index, item); - return true; - } else { - GTEST_LOG_(INFO) << "create RenderWaterFlowItem component failed!"; - return false; - } - }); - renderNode_->SetDeleteChildByIndex([this](int32_t index) { - for (auto outIt = renderNode_->flowMatrix_.begin(); outIt != renderNode_->flowMatrix_.end(); outIt++) { - for (auto inIt = outIt->second.begin(); inIt != outIt->second.end(); inIt++) { - if (inIt->second == index) { - GTEST_LOG_(INFO) << "delete: rowIndex:" << outIt->first << "columnIndex:" << inIt->first - << "index:" << inIt->second; - return; - } - } - } - }); - renderNode_->SetGetChildSpanByIndex( - [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { - GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called !"; - - if (index >= 0) { - if (isHorizontal) { - itemMainSpan = 1; - itemCrossSpan = 1; - } else { - itemMainSpan = 1; - itemCrossSpan = 1; - } - return true; - } - return false; - }); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetItemCalSizeNeeded_001, TestSize.Level1) -{ - RefPtr renderitem = nullptr; - auto result = renderNode_->GetItemCalSizeNeeded(renderitem); - EXPECT_EQ(result, false); - auto item = WaterFlowTestUtils::CreateRenderItem(1, 1, 1, mockContext_); - if (item) { - item->GetChildren().front()->Attach(mockContext_); - item->Attach(mockContext_); - } - auto expect = renderNode_->GetItemCalSizeNeeded(item); - EXPECT_EQ(expect, true); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_SetItemCalSizeNeeded_001, TestSize.Level1) -{ - auto item = WaterFlowTestUtils::CreateRenderItem(1, 1, 1, mockContext_); - if (item) { - item->GetChildren().front()->Attach(mockContext_); - item->Attach(mockContext_); - } - renderNode_->SetItemCalSizeNeeded(item, true); - EXPECT_TRUE(item->GetCalSizeNeeded()); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_UpdateAccessibilityAttr_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - NodeId nodeId = 1; - std::string nodeName = "string"; - auto sAbilityNode = AceType::MakeRefPtr(nodeId, nodeName); - WeakPtr wAbilityNode(sAbilityNode); - auto wref = wAbilityNode.Upgrade(); - if (wref == nullptr) { - GTEST_LOG_(INFO) << "wref == nullptr!"; - return; - } - - renderNode_->SetAccessibilityNode(wAbilityNode); - renderNode_->UpdateAccessibilityAttr(); - auto refPtr = renderNode_->GetAccessibilityNode().Upgrade(); - if (refPtr) { - EXPECT_EQ(refPtr->GetCollectionInfo().rows, 5); - EXPECT_EQ(refPtr->GetCollectionInfo().columns, 5); - } else { - GTEST_LOG_(INFO) << "the refptr is nullptr"; - } -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetIndexByFlow_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - int32_t row = 1; - int32_t col = 2; - int32_t index = 1; - for (int32_t i = 1; i < 3; i++) { - for (int32_t j = 1; j < 3; j++) { - renderNode_->flowMatrix_[i][j] = index; - index++; - } - } - int32_t result = renderNode_->GetIndexByFlow(row, col); - EXPECT_EQ(result, 2); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_focusMove_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - int32_t index = 0; - KeyDirection direction = KeyDirection::DOWN; - for (int32_t i = 0; i < 4; i++) { - for (int32_t j = 0; j < 4; j++) { - renderNode_->flowMatrix_[i][j] = index; - index++; - } - } - renderNode_->focusRow_ = 0; - renderNode_->focusCol_ = 1; - renderNode_->focusIndex_ = 1; - int32_t result = renderNode_->focusMove(direction); - EXPECT_EQ(result, 5); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetItemSpan_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - auto item = WaterFlowTestUtils::CreateRenderItem(1, 2, 1, mockContext_); - auto flowItem = AceType::DynamicCast(item); - EXPECT_NE(flowItem, nullptr); - int32_t rowresult = renderNode_->GetItemSpan(flowItem, true); - EXPECT_EQ(rowresult, 1); - int32_t colresult = renderNode_->GetItemSpan(flowItem, false); - EXPECT_EQ(colresult, 2); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_updatefocusinfo_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - int32_t index = 0; - int32_t focusIndex = 1; - for (int32_t i = 0; i < 4; i++) { - for (int32_t j = 0; j < 4; j++) { - renderNode_->flowMatrixByIndex_[i][j] = index; - index++; - } - } - - renderNode_->UpdateFocusInfo(focusIndex); - EXPECT_EQ(renderNode_->focusRow_, 0); - EXPECT_EQ(renderNode_->focusCol_, 4); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_RequestNextFocus_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - int32_t index = 0; - bool vertical = true; - bool reverse = false; - for (int32_t i = 0; i < 4; i++) { - for (int32_t j = 0; j < 4; j++) { - renderNode_->flowMatrix_[j][i] = index; - index++; - } - } - renderNode_->focusRow_ = 0; - renderNode_->focusCol_ = 1; - renderNode_->focusIndex_ = 1; - int32_t result = renderNode_->RequestNextFocus(vertical, reverse); - EXPECT_EQ(result, 5); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_ParseCrossLength_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - std::vector rowlens; - std::vector collens; - rowlens = renderNode_->ParseCrossLength(renderNode_->mainSize_, renderNode_->mainGap_); - for (auto& len : rowlens) { - EXPECT_EQ(len, 160); - } - collens = renderNode_->ParseCrossLength(renderNode_->crossSize_, renderNode_->crossGap_); - for (auto len : collens) { - EXPECT_EQ(len, 160); - } -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_UpdateScrollPosition_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - renderNode_->currentOffset_ = 1.0; - double offset1 = 3.1; - int32_t source = 10; - bool result = renderNode_->UpdateScrollPosition(offset1, source); - EXPECT_TRUE(result); - EXPECT_EQ(renderNode_->currentOffset_, 1.0); - - double offset = 2.1; - int32_t source2 = 2; - renderNode_->reachHead_ = false; - renderNode_->reachTail_ = true; - renderNode_->currentOffset_ = 1.0; - auto expect = renderNode_->UpdateScrollPosition(offset, source2); - EXPECT_EQ(renderNode_->reachTail_, false); - EXPECT_TRUE(expect); - EXPECT_EQ(renderNode_->currentOffset_, 3.0); - - double offset2 = -2.1; - int32_t source3 = 2; - renderNode_->reachHead_ = true; - renderNode_->reachTail_ = false; - renderNode_->currentOffset_ = 1.0; - auto expect2 = renderNode_->UpdateScrollPosition(offset2, source3); - EXPECT_EQ(renderNode_->reachHead_, false); - EXPECT_TRUE(expect2); - EXPECT_EQ(renderNode_->currentOffset_, -1.0); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_HandleAxisEvent_001, TestSize.Level1) -{ - AxisEvent event; - event.horizontalAxis = 1.5; - event.verticalAxis = 1.5; - renderNode_->reachHead_ = true; - renderNode_->reachTail_ = false; - renderNode_->currentOffset_ = 1.0; - renderNode_->HandleAxisEvent(event); - EXPECT_EQ(renderNode_->reachHead_, false); - EXPECT_EQ(renderNode_->currentOffset_, -11.0); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_isScrollable_001, TestSize.Level1) -{ - AxisDirection direction1 = AxisDirection::UP; - renderNode_->isVertical_ = true; - renderNode_->reachHead_ = false; - renderNode_->reachTail_ = true; - EXPECT_TRUE(renderNode_->IsAxisScrollable(direction1)); - - AxisDirection direction2 = AxisDirection::DOWN; - renderNode_->reachHead_ = true; - renderNode_->reachTail_ = false; - EXPECT_TRUE(renderNode_->IsAxisScrollable(direction2)); - - renderNode_->isVertical_ = false; - AxisDirection direction3 = AxisDirection::LEFT; - renderNode_->reachHead_ = false; - renderNode_->reachTail_ = true; - EXPECT_TRUE(renderNode_->IsAxisScrollable(direction3)); - - AxisDirection direction4 = AxisDirection::RIGHT; - renderNode_->reachHead_ = true; - renderNode_->reachTail_ = false; - EXPECT_TRUE(renderNode_->IsAxisScrollable(direction4)); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_OnPaintFinish_001, TestSize.Level1) -{ - renderNode_->showItem_ = {1.0, 2.0}; - renderNode_->OnPaintFinish(); - EXPECT_EQ(renderNode_->startShowItemIndex_, 1.0); - EXPECT_EQ(renderNode_->endShowItemIndex_, 2.0); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_ClearItems_001, TestSize.Level1) -{ - FillItems(0, 1, 1, 1, 1); - renderNode_->ClearItems(); - EXPECT_EQ(renderNode_->items_.size(), 0); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetItemSpanFromCache_001, TestSize.Level1) -{ - int32_t itemMainSpan = 0; - int32_t itemCrossSpan = 0; - int32_t index = 2; - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - bool result = renderNode_->GetItemSpanFromCache(index, itemMainSpan, itemCrossSpan); - auto it = renderNode_->itemSpanCache_.find(2); - if (it != renderNode_->itemSpanCache_.end()) { - EXPECT_EQ(it->second.rowSpan, 1); - EXPECT_EQ(it->second.colSpan, 1); - } - EXPECT_TRUE(result); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_OnDataSourceUpdated_001, TestSize.Level1) -{ - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - int32_t index = -1; - for (int32_t i = 0; i < 4; i++) { - for (int32_t j = 0; j < 4; j++) { - renderNode_->flowMatrix_[i][j] = index; - } - } - renderNode_->OnDataSourceUpdated(index); - EXPECT_EQ(renderNode_->items_.size(), 0); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetItemMainIndex_001, TestSize.Level1) -{ - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - int32_t index = 0; - int32_t findindex = 2; - int32_t mainIndex = 0; - int32_t crossIndex = 0; - for (int32_t i = 0; i < 4; i++) { - for (int32_t j = 0; j < 4; j++) { - renderNode_->flowMatrixByIndex_[i][j] = index; - index++; - } - } - bool result = renderNode_->GetItemMainCrossIndex(1, mainIndex, crossIndex); - EXPECT_TRUE(result); - EXPECT_EQ(mainIndex, 0); - EXPECT_EQ(crossIndex, 4); - EXPECT_EQ(renderNode_->GetItemMainIndex(findindex), 0); - findindex = 6; - EXPECT_EQ(renderNode_->GetItemMainIndex(findindex), -1); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_DeleteItems_001, TestSize.Level1) -{ - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - int32_t index = 0; - for (int32_t i = 0; i < 3; i++) { - for (int32_t j = 0; j < 3; j++) { - renderNode_->flowMatrix_[i][j] = index; - index++; - } - } - EXPECT_EQ(renderNode_->items_.size(), 5); - renderNode_->DeleteItems(0, false); - EXPECT_EQ(renderNode_->items_.size(), 2); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_BuildFlow_001, TestSize.Level1) -{ - std::vector cross; - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - renderNode_->BuildFlow(cross); - if (cross.empty()) { - GTEST_LOG_(INFO) << "buildflow failed!"; - return; - } - EXPECT_EQ(renderNode_->flowCells_.Width(), 160.0); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_NeedUpdate_001, TestSize.Level1) -{ - FlexDirection directionExpect = FlexDirection::COLUMN; - int32_t cols = 3; - auto component = WaterFlowTestUtils::CreateComponent(directionExpect, cols); - bool update = renderNode_->NeedUpdate(component); - EXPECT_TRUE(update); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_AddChildByIndex_001, TestSize.Level1) -{ - for (int32_t index = 0; index < render_component_count; index++) { - auto item = WaterFlowTestUtils::CreateRenderItem(1, 1, index, mockContext_); - auto flowitem = AceType::DynamicCast(item); - renderNode_->AddChildByIndex(index, flowitem); - } - EXPECT_EQ(renderNode_->items_.size(), render_component_count); - EXPECT_EQ(renderNode_->RenderNode::GetChildren().size(), render_component_count); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_SetChildPosition_001, TestSize.Level1) -{ - int32_t index = 0; - Size size(160, 160); - for (int32_t i = 0; i < 6; i++) { - FillItems(i, 1, 1, 1, 1); - } - for (int32_t i = 0; i < 3; i++) { - for (int32_t j = 0; j < 3; j++) { - renderNode_->flowMatrixByIndex_[i][j] = index; - index++; - } - } - renderNode_->flowCells_ = size; - auto item = renderNode_->items_.find(3); - int32_t itemMainSpan = renderNode_->GetItemSpan(item->second, false); - int32_t itemCrosspan = renderNode_->GetItemSpan(item->second, true); - int32_t itemMain = renderNode_->GetItemMainIndex(1); - item->second->SetLayoutSize(Size(160, 160)); - renderNode_->SetChildPosition(item->second, itemMain, 1, itemMainSpan, itemCrosspan); - EXPECT_TRUE(item->second->GetPosition() == Offset(210.0, 0.0)); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_CheckFlowPlaced_001, TestSize.Level1) -{ - int32_t itemMain = 0; - int32_t itemCross = 2; - int32_t itemMainSpan = 0; - int32_t itemCrossSpan = 0; - int32_t index = 2; - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - EXPECT_TRUE(renderNode_->GetItemSpanFromCache(index, itemMainSpan, itemCrossSpan)); - bool result = renderNode_->CheckFlowPlaced(index, itemMain, itemCross, itemMainSpan, itemCrossSpan); - EXPECT_TRUE(result); - EXPECT_TRUE(renderNode_->flowMatrix_.count(0)); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_MakeInnerLayoutParam_001, TestSize.Level1) -{ - int32_t itemMain = 0; - int32_t itemCross = 2; - int32_t itemMainSpan = 0; - int32_t itemCrossSpan = 0; - int32_t index = 2; - Size size(160, 160); - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - renderNode_->flowCells_ = size; - EXPECT_TRUE(renderNode_->GetItemSpanFromCache(index, itemMainSpan, itemCrossSpan)); - const auto& it = renderNode_->MakeInnerLayoutParam(itemMain, itemCross, itemMainSpan, itemCrossSpan); - EXPECT_EQ(it.GetMaxSize(), size); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_LayoutChild_001, TestSize.Level1) -{ - int32_t itemMain = 0; - int32_t itemCross = 1; - int32_t itemMainSpan = 1; - int32_t itemCrossSpan = 1; - - Size size(160, 160); - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - renderNode_->flowCells_ = size; - renderNode_->mainSize_ = 160; - auto item = renderNode_->items_.find(1); - renderNode_->LayoutChild(item->second, itemMain, itemCross, itemMainSpan, itemCrossSpan); - EXPECT_EQ(item->second->GetPosition(), Offset(0, 210)); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_GetFlowSize_001, TestSize.Level1) -{ - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - renderNode_->mainSize_ = 0; - renderNode_->crossSize_ = 0; - Size sizemax(1000, 1000); - Size sizemin(160, 160); - LayoutParam layoutParam(sizemax, sizemin); - renderNode_->SetLayoutParam(layoutParam); - EXPECT_TRUE(renderNode_->GetFlowSize()); - EXPECT_EQ(renderNode_->mainSize_, 1000); - EXPECT_EQ(renderNode_->crossSize_, 1000); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_Rank_001, TestSize.Level1) -{ - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - int32_t index = 0; - for (int32_t i = 0; i < 4; i++) { - for (int32_t j = 0; j < 4; j++) { - renderNode_->flowMatrix_[i][j] = index; - index++; - } - } - bool result = renderNode_->Rank(3); - EXPECT_TRUE(result); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_CreateScrollable_001, TestSize.Level1) -{ - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - renderNode_->scrollable_ = nullptr; - renderNode_->CreateScrollable(); - EXPECT_TRUE(renderNode_->scrollable_ != nullptr); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_SupplyItems_001, TestSize.Level1) -{ - std::vector main; - - int32_t mainIndex = 0; - bool vailSupplyItem = false; - for (int32_t i = 0; i < 5; i++) { - FillItems(i, 1, 1, 1, 1); - } - int32_t index = 0; - for (int32_t i = 0; i < 4; i++) { - for (int32_t j = 0; j < 4; j++) { - renderNode_->flowMatrix_[i][j] = -1; - index++; - } - } - renderNode_->BuildFlow(main); - renderNode_->SupplyItems(vailSupplyItem, mainIndex); - - EXPECT_TRUE(renderNode_->inCache_.count(mainIndex)); -} - -HWTEST_F(RenderWaterFlowTest, RenderWaterFlowTest_PerformLayout_001, TestSize.Level1) -{ - CreateWaterFlow(1, 1); - renderNode_->mainSize_ = 0; - renderNode_->crossSize_ = 0; - Size sizemax(1000, 1000); - Size sizemin(160, 160); - LayoutParam layoutParam(sizemax, sizemin); - renderNode_->SetLayoutParam(layoutParam); - renderNode_->PerformLayout(); - const std::list>& items = renderNode_->RenderNode::GetChildren(); - EXPECT_TRUE(!items.empty()); - int32_t index = 0; - for (const auto& item : items) { - EXPECT_TRUE(item->GetPosition() == Offset(index % 5 * 210, index / 5 * 210)); - EXPECT_TRUE(item->GetLayoutSize() == Size(160.0, 160.0)); - index++; - } -} - -HWTEST_F(RenderWaterFlowTest, PerformLayout_002, TestSize.Level1) -{ - CreateWaterFlow(2, 2); - renderNode_->SetGetChildSpanByIndex( - [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { - GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; - if (index >= 0) { - itemMainSpan = 2; - itemCrossSpan = 2; - return true; - } - return false; - }); - renderNode_->SetDeleteChildByIndex([](int32_t index) {}); - - LayoutParam layoutParam; - layoutParam.SetMinSize(Size(0.0, 0.0)); - layoutParam.SetMaxSize(Size(1000.0, 1000.0)); - renderNode_->SetLayoutParam(layoutParam); - - renderNode_->PerformLayout(); - - auto& items = renderNode_->RenderNode::GetChildren(); - EXPECT_TRUE(!items.empty()); - int32_t index = 0; - for (const auto& item : items) { - if ((index + 1) % 3 == 0) { - EXPECT_TRUE(item->GetPosition() == Offset(index % 3 * 420, index / 3 * 420)); - EXPECT_TRUE(item->GetLayoutSize() == Size(160.0, 2 * 160 + 50)); - } else { - EXPECT_TRUE(item->GetPosition() == Offset(index % 3 * 420, index / 3 * 420)); - EXPECT_TRUE(item->GetLayoutSize() == Size(2 * 160 + 50, 2 * 160 + 50)); - } - index++; - } -} - -HWTEST_F(RenderWaterFlowTest, PerformLayout_003, TestSize.Level1) -{ - CreateWaterFlow(3, 3); - renderNode_->SetGetChildSpanByIndex( - [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { - GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; - if (index >= 0) { - itemMainSpan = 3; - itemCrossSpan = 3; - return true; - } - return false; - }); - renderNode_->SetDeleteChildByIndex([](int32_t index) {}); - - LayoutParam layoutParam; - layoutParam.SetMinSize(Size(0.0, 0.0)); - layoutParam.SetMaxSize(Size(1000.0, 1000.0)); - renderNode_->SetLayoutParam(layoutParam); - - renderNode_->PerformLayout(); - - auto& items = renderNode_->RenderNode::GetChildren(); - EXPECT_TRUE(!items.empty()); - int32_t index = 0; - for (const auto& item : items) { - if ((index + 1) % 2 == 0) { - EXPECT_TRUE(item->GetPosition() == Offset(index % 2 * 630, index / 2 * 630)); - EXPECT_TRUE(item->GetLayoutSize() == Size(2 * 160 + 50, 3 * 160 + 50 * 2)); - } else { - EXPECT_TRUE(item->GetPosition() == Offset(index % 2 * 630, index / 2 * 630)); - EXPECT_TRUE(item->GetLayoutSize() == Size(3 * 160 + 50 * 2, 3 * 160 + 50 * 2)); - } - index++; - } -} - -HWTEST_F(RenderWaterFlowTest, PerformLayout_004, TestSize.Level1) -{ - CreateWaterFlow(4, 4); - renderNode_->SetGetChildSpanByIndex( - [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { - GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; - if (index >= 0) { - itemMainSpan = 4; - itemCrossSpan = 4; - return true; - } - return false; - }); - renderNode_->SetDeleteChildByIndex([](int32_t index) {}); - - LayoutParam layoutParam; - layoutParam.SetMinSize(Size(0.0, 0.0)); - layoutParam.SetMaxSize(Size(1000.0, 1000.0)); - renderNode_->SetLayoutParam(layoutParam); - - renderNode_->PerformLayout(); - - auto& items = renderNode_->RenderNode::GetChildren(); - EXPECT_TRUE(!items.empty()); - int32_t index = 0; - for (const auto& item : items) { - if ((index + 1) % 2 == 0) { - EXPECT_TRUE(item->GetPosition() == Offset(index % 2 * 840, index / 2 * 840)); - EXPECT_TRUE(item->GetLayoutSize() == Size(160, 4 * 160 + 50 * 3)); - } else { - EXPECT_TRUE(item->GetPosition() == Offset(index % 2 * 840, index / 2 * 840)); - EXPECT_TRUE(item->GetLayoutSize() == Size(4 * 160 + 50 * 3, 4 * 160 + 50 * 3)); - } - index++; - } -} - -HWTEST_F(RenderWaterFlowTest, PerformLayout_005, TestSize.Level1) -{ - CreateWaterFlow(5, 5); - renderNode_->SetGetChildSpanByIndex( - [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { - GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; - if (index >= 0) { - itemMainSpan = 5; - itemCrossSpan = 5; - return true; - } - return false; - }); - renderNode_->SetDeleteChildByIndex([](int32_t index) {}); - - LayoutParam layoutParam; - layoutParam.SetMinSize(Size(0.0, 0.0)); - layoutParam.SetMaxSize(Size(1000.0, 1000.0)); - renderNode_->SetLayoutParam(layoutParam); - - renderNode_->PerformLayout(); - - auto& items = renderNode_->RenderNode::GetChildren(); - EXPECT_TRUE(items.size() == 1); - auto it = items.begin(); - EXPECT_TRUE((*it)->GetPosition() == Offset(0, 0)); - EXPECT_TRUE((*it)->GetLayoutSize() == Size(1000, 1000)); -} - -HWTEST_F(RenderWaterFlowTest, PerformLayout_006, TestSize.Level1) -{ - CreateWaterFlow(6, 6); - renderNode_->SetGetChildSpanByIndex( - [](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { - GTEST_LOG_(INFO) << "SetGetChildSpanByIndex called start!"; - if (index >= 0) { - itemMainSpan = 6; - itemCrossSpan = 6; - return true; - } - return false; - }); - renderNode_->SetDeleteChildByIndex([](int32_t index) {}); - - LayoutParam layoutParam; - layoutParam.SetMinSize(Size(0.0, 0.0)); - layoutParam.SetMaxSize(Size(1000.0, 1000.0)); - renderNode_->SetLayoutParam(layoutParam); - - renderNode_->PerformLayout(); - - auto& items = renderNode_->RenderNode::GetChildren(); - EXPECT_TRUE(items.size() == 1); - auto it = items.begin(); - EXPECT_TRUE((*it)->GetPosition() == Offset(0, 0)); - EXPECT_TRUE((*it)->GetLayoutSize() == Size(1000, 1210)); -} -} // namespace OHOS::Ace diff --git a/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.cpp b/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.cpp deleted file mode 100644 index 8e5a8ce2..00000000 --- a/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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/test/unittest/water_flow/water_flow_test_utils.h" -#include "core/components_v2/water_flow/render_water_flow_item.h" -#include "core/components/box/box_component.h" - -namespace OHOS::Ace { -RefPtr WaterFlowTestUtils::CreateComponent(FlexDirection direction, int32_t cols) -{ - std::list> children; - Dimension RowGap = 50.0_px; - Dimension ColumnsGap = 50.0_px; - RefPtr component = AceType::MakeRefPtr(children, cols); - component->SetRowsGap(RowGap); - component->SetColumnsGap(ColumnsGap); - component->SetLayoutDirection(direction); - return component; -} - -RefPtr WaterFlowTestUtils::CreateComponentItem(const int32_t& itemMainSpan, const int32_t& itemCrossSpan) -{ - RefPtr box = AceType::MakeRefPtr(); - RefPtr ComponentItem = AceType::MakeRefPtr(box); - auto flowItem = AceType::DynamicCast(ComponentItem); - if (flowItem) { - flowItem->SetRowSpan(itemMainSpan); - flowItem->SetColumnSpan(itemCrossSpan); - return flowItem; - } - return nullptr; -} - - -RefPtr WaterFlowTestUtils::CreateRenderItem( - int32_t rowSpan, int32_t colSpan, int32_t index, const RefPtr& context) -{ - constexpr double DIM_SIZE_VALUE_TEST = 150.0; - RefPtr boxComponent = AceType::MakeRefPtr(); - RefPtr renderBox = AceType::MakeRefPtr(); - boxComponent->SetWidth(DIM_SIZE_VALUE_TEST); - boxComponent->SetHeight(DIM_SIZE_VALUE_TEST); - renderBox->Update(boxComponent); - renderBox->Attach(context); - RefPtr Renderitem = AceType::MakeRefPtr(); - if (Renderitem) { - auto itemComponent = CreateComponentItem(rowSpan, colSpan); - if (itemComponent) { - Renderitem->Update(itemComponent); - Renderitem->SetBoundary(); - Renderitem->SetIndex(index); - Renderitem->Attach(context); - Renderitem->SetHidden(false); - Renderitem->AddChild(renderBox); - return Renderitem; - } - } - return nullptr; -} - -RefPtr WaterFlowTestUtils::CreateRenderItem( - double width, double height, int32_t rowspan, int32_t colspan, const RefPtr& context) -{ - RefPtr parent = AceType::MakeRefPtr(); - RefPtr child = AceType::MakeRefPtr(); - RefPtr renderBox = AceType::MakeRefPtr(); - parent->Attach(context); - child->Attach(context); - renderBox->Attach(context); - RefPtr boxComponent = AceType::MakeRefPtr(); - boxComponent->SetWidth(width); - boxComponent->SetHeight(height); - renderBox->Update(boxComponent); - child->SetRowSpan(rowspan); - child->SetColumnSpan(colspan); - parent->AddChild(child); - child->AddChild(renderBox); - return parent; -} -} // namespace OHOS::Ace diff --git a/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.h b/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.h deleted file mode 100644 index 6642c8f1..00000000 --- a/frameworks/core/components/test/unittest/water_flow/water_flow_test_utils.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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_TEST_UNITTEST_WATER_FLOW_WARER_FLOW_TEST_UTILS_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEST_UNITTEST_WATER_FLOW_WARER_FLOW_TEST_UTILS_H - -#include "core/components_v2/water_flow/water_flow_component.h" -#include "core/components_v2/water_flow/render_water_flow.h" -#include "core/components_v2/water_flow/water_flow_item_component.h" -#include "core/components/box/render_box.h" -#include "core/components/image/render_image.h" -#include "core/components/image/image_component.h" - -namespace OHOS::Ace { -namespace { -using WaterFlowCallback = std::function; -class MockEventHandler : public AceEventHandler { - void HandleAsyncEvent(const EventMarker& eventMarker) override {}; - void HandleAsyncEvent(const EventMarker& eventMarker, int32_t param) override {}; - void HandleAsyncEvent(const EventMarker& eventMarker, const BaseEventInfo& info) override {}; - void HandleAsyncEvent(const EventMarker& eventMarker, const std::string& param) override {}; - void HandleAsyncEvent(const EventMarker& eventMarker, const KeyEvent& keyEvent) override {}; - void HandleSyncEvent(const EventMarker& eventMarker, bool& result) override {}; - void HandleSyncEvent(const EventMarker& eventMarker, const BaseEventInfo& info, bool& result) override {}; - void HandleSyncEvent(const EventMarker& eventMarker, const std::string& param, std::string& result) override {}; - void HandleSyncEvent(const EventMarker& eventMarker, const KeyEvent& keyEvent, bool& result) override {}; - void HandleSyncEvent( - const EventMarker& eventMarker, const std::string& componentId, const int32_t nodeId) override {}; -}; - -class TestGridEventHander : public MockEventHandler { -public: - explicit TestGridEventHander(WaterFlowCallback eventCallback) : eventCallback_(eventCallback) {}; - ~TestGridEventHander() = default; - - void HandleAsyncEvent(const EventMarker& eventMarker, const std::string& param) - { - if (eventCallback_) { - eventCallback_(eventMarker.GetData().eventId, param); - } - }; - -private: - WaterFlowCallback eventCallback_; -}; -} // namespace - -class WaterFlowTestUtils { -public: - static RefPtr CreateRenderItem( - double width, double height, int32_t rowspan, int32_t colspan, const RefPtr& context); - static RefPtr CreateRenderItem( - int32_t rowspan, int32_t colspan, int32_t index, const RefPtr& contex); - static RefPtr CreateComponent(FlexDirection direction, int32_t cols); - static RefPtr CreateComponentItem(const int32_t& itemMainSpan, const int32_t& itemCrossSpan); -}; -} // namespace OHOS::Ace - -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TEST_UNITTEST_WATER_FLOW_WARER_FLOW_TEST_UTILS_H diff --git a/frameworks/core/components_v2/water_flow/BUILD.gn b/frameworks/core/components_v2/water_flow/BUILD.gn deleted file mode 100644 index 73a19909..00000000 --- a/frameworks/core/components_v2/water_flow/BUILD.gn +++ /dev/null @@ -1,31 +0,0 @@ -# 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. - -import( - "//foundation/arkui/ace_engine/frameworks/core/components/components.gni") - -build_component("water_flow_v2") { - sources = [ - "flutter_render_water_flow.cpp", - "render_water_flow.cpp", - "render_water_flow_creator.cpp", - "render_water_flow_item.cpp", - "water_flow_component.cpp", - "water_flow_element.cpp", - "water_flow_item_component.cpp", - "water_flow_item_element.cpp", - "water_flow_position_controller.cpp", - "water_flow_scroll_controller.cpp", - ] - rosen_sources = [ "rosen_render_water_flow.cpp" ] -} diff --git a/frameworks/core/components_v2/water_flow/flutter_render_water_flow.cpp b/frameworks/core/components_v2/water_flow/flutter_render_water_flow.cpp deleted file mode 100644 index b9b8e4ee..00000000 --- a/frameworks/core/components_v2/water_flow/flutter_render_water_flow.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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/water_flow/flutter_render_water_flow.h" - -#include "core/components/common/painter/flutter_scroll_bar_painter.h" -#include "core/pipeline/base/flutter_render_context.h" - -namespace OHOS::Ace::V2 { -using namespace Flutter; -RenderLayer FlutterRenderWaterFlow::GetRenderLayer() -{ - if (!layer_) { - layer_ = AceType::MakeRefPtr( - 0.0, GetLayoutSize().Width(), 0.0, GetLayoutSize().Height(), Clip::HARD_EDGE); - TakeBoundary(); - } - return AceType::RawPtr(layer_); -} - -void FlutterRenderWaterFlow::Paint(RenderContext& context, const Offset& offset) -{ - LOGD("Paint %{public}lf %{public}lf", GetLayoutSize().Width(), GetLayoutSize().Height()); - layer_->SetClip(0.0, GetLayoutSize().Width(), 0.0, GetLayoutSize().Height(), Clip::HARD_EDGE); - RenderNode::Paint(context, offset); - - // Notify scroll bar to update. - if (scrollBarProxy_) { - scrollBarProxy_->NotifyScrollBar(AceType::WeakClaim(this)); - } - - // render scroll bar - if (!scrollBar_ || !scrollBar_->NeedPaint()) { - GetEstimatedHeight(); - return; - } - 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) { - return; - } - const auto renderContext = static_cast(&context); - flutter::Canvas* canvas = renderContext->GetCanvas(); - Offset lastOffset = isVertical_ ? Offset(0, lastOffset_) : Offset(lastOffset_, 0); - scrollBar_->UpdateScrollBarRegion(offset, GetLayoutSize(), lastOffset, GetEstimatedHeight()); - RefPtr scrollPainter = AceType::MakeRefPtr(); - scrollPainter->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/water_flow/flutter_render_water_flow.h b/frameworks/core/components_v2/water_flow/flutter_render_water_flow.h deleted file mode 100644 index 60d4fa93..00000000 --- a/frameworks/core/components_v2/water_flow/flutter_render_water_flow.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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_V2_WATER_FLOW_FLUTTER_RENDER_WATER_FLOW_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_FLUTTER_RENDER_WATER_FLOW_H - -#include "core/components_v2/water_flow/render_water_flow.h" -#include "core/pipeline/layers/clip_layer.h" - -namespace OHOS::Ace::V2 { -class FlutterRenderWaterFlow : public RenderWaterFlow { - DECLARE_ACE_TYPE(FlutterRenderWaterFlow, RenderWaterFlow); - -public: - FlutterRenderWaterFlow() = default; - ~FlutterRenderWaterFlow() override = default; - - RenderLayer GetRenderLayer() override; - void Paint(RenderContext& context, const Offset& offset) override; - -private: - RefPtr layer_; -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_FLUTTER_RENDER_WATER_FLOW_H diff --git a/frameworks/core/components_v2/water_flow/render_water_flow.cpp b/frameworks/core/components_v2/water_flow/render_water_flow.cpp deleted file mode 100644 index 329e3653..00000000 --- a/frameworks/core/components_v2/water_flow/render_water_flow.cpp +++ /dev/null @@ -1,1808 +0,0 @@ -/* - * 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/water_flow/render_water_flow.h" - -#include "base/log/ace_trace.h" -#include "base/log/event_report.h" -#include "base/log/log.h" -#include "base/utils/string_utils.h" -#include "base/utils/time_util.h" -#include "base/utils/utils.h" -#include "core/animation/curve_animation.h" -#include "core/components_v2/water_flow/render_water_flow_item.h" -#include "core/components_v2/water_flow/water_flow_component.h" -#include "core/components_v2/water_flow/water_flow_scroll_controller.h" -#include "core/event/ace_event_helper.h" - -namespace OHOS::Ace::V2 { -namespace { -constexpr int32_t TIMETHRESHOLD = 3 * 1000000; // milliseconds -constexpr int32_t MICROSEC_TO_NANOSEC = 1000; -constexpr int32_t DEFAULT_DEPTH = 10; -constexpr bool HORIZONTAL = false; -constexpr bool VERTICAL = true; -constexpr bool FORWARD = false; -constexpr bool REVERSE = true; - -// first bool mean if vertical, second bool mean if reverse -// false, false --> RIGHT -// false, true --> LEFT -// true, false --> DOWN -// true, true ---> UP -// This map will adapter the WaterFlow FlexDirection with Key Direction. -const std::map>> DIRECTION_MAP = { - { false, // RTL is false - { { HORIZONTAL, { { FORWARD, KeyDirection::RIGHT }, { REVERSE, KeyDirection::LEFT } } }, - { VERTICAL, { { FORWARD, KeyDirection::DOWN }, { REVERSE, KeyDirection::UP } } } } }, - { true, // RTL is true - { { HORIZONTAL, { { FORWARD, KeyDirection::LEFT }, { REVERSE, KeyDirection::RIGHT } } }, - { VERTICAL, { { FORWARD, KeyDirection::DOWN }, { REVERSE, KeyDirection::UP } } } } } -}; -} // namespace - -std::string WaterFlowEventInfo::ToJSONString() const -{ - return std::string("\"waterflow\",{\"first\":").append(std::to_string(scrollIndex_)).append("},null"); -} - -RenderWaterFlow::~RenderWaterFlow() -{ - if (scrollBarProxy_) { - scrollBarProxy_->UnRegisterScrollableNode(AceType::WeakClaim(this)); - } -} - -void RenderWaterFlow::Update(const RefPtr& component) -{ - InitScrollBar(component); - if (!NeedUpdate(component)) { - return; - } - - startRankItemIndex_ = 0; - currentItemIndex_ = 0; - const RefPtr flow = AceType::DynamicCast(component); - if (!flow) { - LOGE("RenderWaterFlow update failed."); - EventReport::SendRenderException(RenderExcepType::RENDER_COMPONENT_ERR); - return; - } - - isVertical_ = true; - updateFlag_ = true; - direction_ = flow->GetDirection(); - userColGap_ = flow->GetColumnsGap(); - userRowGap_ = flow->GetRowsGap(); - userMainLength_ = flow->GetMainLength(); - scrollBarProxy_ = flow->GetScrollBarProxy(); - crossCount_ = flow->GetCrossSplice(); - if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { - mainGap_ = NormalizePercentToPx(userRowGap_, true); - crossGap_ = NormalizePercentToPx(userColGap_, false); - useScrollable_ = SCROLLABLE::VERTICAL; - } else { - crossGap_ = NormalizePercentToPx(userRowGap_, true); - mainGap_ = NormalizePercentToPx(userColGap_, false); - useScrollable_ = SCROLLABLE::HORIZONTAL; - } - - InitScrollBarProxy(); - CreateScrollable(); - MarkNeedLayout(); - LOGD("%{public}s mainCount_:%{public}d crossCount_:%{public}d mainGap_:%{public}f " - "crossGap_:%{public}f", - __PRETTY_FUNCTION__, mainCount_, crossCount_, mainGap_, crossGap_); -} - -void RenderWaterFlow::CalAndPosItems(double& drawLength, int32_t& main) -{ - for (; main < mainCount_; main++) { - for (int32_t cross = 0; cross < crossCount_; cross++) { - auto mainIter = flowMatrix_.find(main); - if (mainIter == flowMatrix_.end()) { - LOGD("PerformLayout. main: %{public}d. skip flowMatrix_", main); - continue; - } - auto crossIter = mainIter->second.find(cross); - if (crossIter == mainIter->second.end()) { - LOGD("PerformLayout. main: %{public}d, cross: %{public}d. skip flowMatrix_", main, cross); - continue; - } - if (buildChildByIndex_ && (inCache_.count(main) == 0 || !CheckMainFull(main))) { - bool vail = false; - SupplyItems(vail, main); - } - if (showItem_.count(crossIter->second) != 0) { - continue; - } - - showItem_.insert(crossIter->second); - CheckAndInsertItems(main, crossIter->second); - auto item = items_.find(crossIter->second); - if (item != items_.end()) { - childrenInRect_.push_back(item->second); - int32_t itemMainSpan = GetItemSpan(item->second, useScrollable_ != SCROLLABLE::HORIZONTAL); - int32_t itemCrosspan = GetItemSpan(item->second, useScrollable_ == SCROLLABLE::HORIZONTAL); - int32_t itemMain = GetItemMainIndex(crossIter->second); - LOGD("PerformLayout. marix_ss itemInfo. itemindex:%{public}d, row:%{public}d, col:%{public}d, " - "rowSpan:%{public}d," - "colSpan:%{public}d.", - crossIter->second, itemMain, cross, itemMainSpan, itemCrosspan); - SetChildPosition(item->second, itemMain, cross, itemMainSpan, itemCrosspan); - } - } - if (main >= startIndex_) { - drawLength += GetSize(flowCells_) + mainGap_; - } - if (GreatOrEqual(drawLength, mainSize_)) { - break; - } - } -} - -void RenderWaterFlow::PerformLayout() -{ - if (RenderNode::GetChildren().empty() && !buildChildByIndex_) { - return; - } - - // calulate rowSize colSize mainLength - if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { - mainSize_ = GetLayoutParam().GetMaxSize().Height(); - crossSize_ = GetLayoutParam().GetMaxSize().Width(); - if (NearEqual(mainSize_, Size::INFINITE_SIZE)) { - mainSize_ = viewPort_.Height(); - } - if (NearEqual(crossSize_, Size::INFINITE_SIZE)) { - crossSize_ = viewPort_.Width(); - } - } else { - crossSize_ = GetLayoutParam().GetMaxSize().Height(); - mainSize_ = GetLayoutParam().GetMaxSize().Width(); - if (NearEqual(crossSize_, Size::INFINITE_SIZE)) { - crossSize_ = viewPort_.Height(); - } - if (NearEqual(mainSize_, Size::INFINITE_SIZE)) { - mainSize_ = viewPort_.Width(); - } - } - mainLength_ = NormalizePercentToPx(userMainLength_, true); - if (NearZero(mainLength_)) { - mainLength_ = ParseCrossLength(crossSize_, crossGap_).at(0); - } - - InitialFlowProp(); - CaculateViewPort(); - showItem_.clear(); - childrenInRect_.clear(); - double drawLength = 0.0 - firstItemOffset_; - int32_t main = startIndex_ > 0 ? startIndex_ - 1 : startIndex_; - LOGD("PerformLayout. main: %{public}d. start", main); - CalAndPosItems(drawLength, main); - SetLayoutSize(GetLayoutParam().Constrain(Size(crossSize_, mainSize_))); - endIndex_ = main; - MarkNeedPredictLayout(); - CalculateWholeSize(drawLength); - lastOffset_ = startMainPos_ + firstItemOffset_ - currentOffset_; - LOGD("PerformLayout. offset_ss lastOffset_:%{public}lf, startMainPos_:%{public}lf, firstItemOffset_:%{public}lf," - "currentOffset_:%{public}lf", - lastOffset_, startMainPos_, firstItemOffset_, currentOffset_); - LOGD("PerformLayout. offset_ss mainCount_:%{public}d", mainCount_); -} - -bool RenderWaterFlow::NeedUpdate(const RefPtr& component) -{ - const RefPtr flow = AceType::DynamicCast(component); - if (!flow) { - LOGE("RenderWaterFlow update failed."); - EventReport::SendRenderException(RenderExcepType::RENDER_COMPONENT_ERR); - return false; - } - auto controller = flow->GetController(); - if (controller) { - controller->SetScrollNode(WeakClaim(this)); - } - if (!animator_) { - animator_ = AceType::MakeRefPtr(GetContext()); - } - - if (direction_ != flow->GetDirection() || crossAxisAlign_ != flow->GetFlexAlign() || - userColGap_ != flow->GetColumnsGap() || userRowGap_ != flow->GetRowsGap() || - rightToLeft_ != flow->GetRightToLeft()) { - return true; - }; - return false; -} - -void RenderWaterFlow::AddChildByIndex(int32_t index, const RefPtr& renderNode) -{ - auto iter = items_.find(index); - if (iter != items_.end() && iter->second == nullptr) { - items_.erase(index); - itemSpanCache_.erase(index); - } - auto itor = items_.try_emplace(index, renderNode); - if (itor.second) { - AddChild(renderNode); - SetItemCalSizeNeeded(renderNode, true); - RefPtr node = AceType::DynamicCast(renderNode); - if (node) { - node->SetBoundary(); - node->SetIndex(index); - node->SetHidden(false); - } - Span span; - span.rowSpan = node->GetRowSpan(); - span.colSpan = node->GetColumnSpan(); - itemSpanCache_.emplace(std::make_pair(index, span)); - } -} - -void RenderWaterFlow::CreateScrollable() -{ - scrollable_ = nullptr; - if (useScrollable_ == SCROLLABLE::NO_SCROLL) { - return; - } - - auto callback = [weak = AceType::WeakClaim(this)](double offset, int32_t source) { - auto flow = weak.Upgrade(); - if (!flow) { - return false; - } - // Stop animator of scroll bar. - auto scrollBarProxy = flow->scrollBarProxy_; - if (scrollBarProxy) { - scrollBarProxy->StopScrollBarAnimator(); - } - return flow->UpdateScrollPosition(offset, source); - }; - scrollable_ = AceType::MakeRefPtr( - callback, useScrollable_ == SCROLLABLE::HORIZONTAL ? Axis::HORIZONTAL : Axis::VERTICAL); - scrollable_->SetScrollEndCallback([weak = AceType::WeakClaim(this)]() { - auto flow = weak.Upgrade(); - if (flow) { - auto proxy = flow->scrollBarProxy_; - if (proxy) { - proxy->StartScrollBarAnimator(); - } - } - }); - scrollable_->Initialize(context_); -} - -bool RenderWaterFlow::UpdateScrollPosition(double offset, int32_t source) -{ - if (source == SCROLL_FROM_START) { - return true; - } - - if (NearZero(offset)) { - return true; - } - if (scrollBar_ && scrollBar_->NeedScrollBar()) { - scrollBar_->SetActive(SCROLL_FROM_CHILD != source); - } - - if (reachHead_ && reachTail_) { - return false; - } - - if (offset > 0.0) { - if (reachHead_) { - return false; - } - reachTail_ = false; - } else { - if (reachTail_) { - return false; - } - reachHead_ = false; - } - - currentOffset_ += Round(offset); - MarkNeedLayout(true); - return true; -} - -void RenderWaterFlow::OnTouchTestHit( - const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) -{ - if (!GetVisible()) { - return; - } - if (!scrollable_ || !scrollable_->Available()) { - return; - } - if (scrollBar_ && scrollBar_->InBarRegion(globalPoint_ - coordinateOffset)) { - scrollBar_->AddScrollBarController(coordinateOffset, result); - } else { - scrollable_->SetCoordinateOffset(coordinateOffset); - scrollable_->SetDragTouchRestrict(touchRestrict); - result.emplace_back(scrollable_); - } - result.emplace_back(scrollable_); -} - -bool RenderWaterFlow::IsChildrenTouchEnable() -{ - bool ret = scrollable_->IsMotionStop(); - return ret; -} - -void RenderWaterFlow::SetChildPosition( - const RefPtr& child, int32_t main, int32_t cross, int32_t mainSpan, int32_t crossSpan) -{ - // Calculate the position for current child. - double positionMain = 0.0; - double positionCross = 0.0; - if (main < startIndex_) { - positionMain -= GetSize(flowCells_) * (startIndex_ - main); - positionMain += (main - startIndex_) * mainGap_; - } else { - positionMain += GetSize(flowCells_) * (main - startIndex_); - positionMain += (main - startIndex_) * mainGap_; - } - - positionCross += GetSize(flowCells_, false) * cross; - positionCross += cross * crossGap_; - - // Calculate the size for current child. - double mainLen = 0.0; - double crossLen = 0.0; - mainLen += GetSize(flowCells_) * mainSpan; - mainLen += (mainSpan - 1) * mainGap_; - crossLen += GetSize(flowCells_, false) * crossSpan; - crossLen += (crossSpan - 1) * crossGap_; - - // If RTL, place the item from right. - if (rightToLeft_) { - if (useScrollable_ != SCROLLABLE::HORIZONTAL) { - positionCross = crossSize_ - positionCross - crossLen; - } - } - - double mainOffset = (mainLen - GetSize(child->GetLayoutSize())) / 2.0; - double crosstOffset = (crossLen - GetSize(child->GetLayoutSize(), false)) / 2.0; - - Offset offset; - if (useScrollable_ != SCROLLABLE::HORIZONTAL) { - offset = Offset(positionCross + crosstOffset, positionMain + mainOffset - firstItemOffset_); - } else { - offset = Offset(positionMain + mainOffset - firstItemOffset_, positionCross + crosstOffset); - } - - child->SetPosition(offset); -} - -double RenderWaterFlow::GetSize(const Size& src, bool isMain) const -{ - if (useScrollable_ == SCROLLABLE::HORIZONTAL) { - return isMain ? src.Width() : src.Height(); - } - - return isMain ? src.Height() : src.Width(); -} - -bool RenderWaterFlow::GetFlowSize() -{ - double rowSize = ((flowHeight_ > 0.0) && (flowHeight_ < GetLayoutParam().GetMaxSize().Height())) - ? flowHeight_ - : GetLayoutParam().GetMaxSize().Height(); - double colSize = ((flowWidth_ > 0.0) && (flowWidth_ < GetLayoutParam().GetMaxSize().Width())) - ? flowWidth_ - : GetLayoutParam().GetMaxSize().Width(); - if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { - useScrollable_ = SCROLLABLE::VERTICAL; - if (NearEqual(mainSize_, Size::INFINITE_SIZE)) { - mainSize_ = viewPort_.Height(); - } - if (NearEqual(crossSize_, Size::INFINITE_SIZE)) { - crossSize_ = viewPort_.Width(); - } - LOGD("GetFlowSize %lf, %lf [%lf- %lf]", rowSize, colSize, mainSize_, crossSize_); - if (rowSize != mainSize_ || colSize != crossSize_) { - mainSize_ = rowSize; - crossSize_ = colSize; - CreateScrollable(); - return true; - } - } else { - useScrollable_ = SCROLLABLE::HORIZONTAL; - if (NearEqual(mainSize_, Size::INFINITE_SIZE)) { - mainSize_ = viewPort_.Width(); - } - if (NearEqual(crossSize_, Size::INFINITE_SIZE)) { - crossSize_ = viewPort_.Height(); - } - LOGD("GetFlowSize %lf, %lf [%lf- %lf]", rowSize, colSize, mainSize_, crossSize_); - if (rowSize != crossSize_ || colSize != mainSize_) { - crossSize_ = rowSize; - mainSize_ = colSize; - CreateScrollable(); - return true; - } - } - return false; -} - -void RenderWaterFlow::BuildFlow(std::vector& cross) -{ - cross = ParseCrossLength(crossSize_, crossGap_); - if (useScrollable_ == SCROLLABLE::VERTICAL) { - flowCells_ = Size(cross.at(0), mainLength_); - } else if (useScrollable_ == SCROLLABLE::HORIZONTAL) { - flowCells_ = Size(mainLength_, cross.at(0)); - } -} - -void RenderWaterFlow::CallGap() -{ - if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { - mainGap_ = NormalizePercentToPx(userRowGap_, true); - crossGap_ = NormalizePercentToPx(userColGap_, false); - } else { - crossGap_ = NormalizePercentToPx(userRowGap_, true); - mainGap_ = NormalizePercentToPx(userColGap_, false); - } -} - -void RenderWaterFlow::InitialFlowProp() -{ - // Not first time layout after update, no need to initial. - if (!GetFlowSize() && !updateFlag_) { - return; - } - ACE_SCOPED_TRACE("InitialFlowProp"); - OnDataSourceUpdated(-1); - CallGap(); - std::vector cross; - BuildFlow(cross); - // Initialize the columnCount and rowCount, default is 1 - crossCount_ = cross.size(); - mainCount_ = 0; - UpdateAccessibilityAttr(); - - if (!buildChildByIndex_) { - LOGE("%{public}s. buildChildByIndex_ is null.", __PRETTY_FUNCTION__); - return; - } - - int32_t endIndex = -1; - mainCount_ = GetItemMainIndex(startRankItemIndex_); - if (mainCount_ < 0) { - mainCount_ = 0; - } - while (endIndex < currentItemIndex_) { - Rank(mainCount_, startRankItemIndex_); - mainCount_++; - auto mainItor = flowMatrix_.find(mainCount_ - 1); - if (mainItor == flowMatrix_.end()) { - break; - } - for (int32_t crossIndex = crossCount_ - 1; crossIndex >= 0; crossIndex--) { - auto iter = mainItor->second.find(crossIndex); - if (iter != mainItor->second.end()) { - endIndex = iter->second; - break; - } - } - } - startRankItemIndex_ = 0; - currentItemIndex_ = 0; - bool vail = false; - SupplyItems(vail, mainCount_ > 0 ? mainCount_ - 1 : 0); - startIndex_ = mainCount_ > 0 ? mainCount_ - 1 : 0; - if (NearZero(currentOffset_)) { - needCalculateViewPort_ = true; - } - - updateFlag_ = false; - if (firstLineToBottom_ && firstLineToBottom_.value()) { - // calculate the distance from the first line to the last line - currentOffset_ = mainSize_ - GetSize(flowCells_); - needCalculateViewPort_ = false; - } - firstLineToBottom_ = std::nullopt; -} - -double RenderWaterFlow::BuildLazyFlowLayout(int32_t index, double sizeNeed) -{ - if (!buildChildByIndex_ || index < 0 || NearZero(sizeNeed)) { - return 0.0; - } - double size = 0.0; - int32_t startIndex = index; - while (size < sizeNeed) { - bool vail = false; - auto suppleSize = SupplyItems(vail, startIndex); - if (NearZero(suppleSize)) { - break; - } - mainCount_ = ++startIndex; - size += suppleSize + mainGap_; - } - return size; -} - -void RenderWaterFlow::CalculateCrossSpan( - int32_t mainIndex, int32_t cross, int32_t crossSpan, int32_t& calculateCrossSpan) -{ - auto mainIter = flowMatrix_.find(mainIndex); - if (mainIter != flowMatrix_.end()) { - int32_t tempCrossSpan = 0; - for (int32_t j = 0; j < crossSpan; j++) { - if ((mainIter->second.find(j + cross) == mainIter->second.end()) && (crossCount_ > (j + cross))) { - tempCrossSpan = j + 1; - } else if (tempCrossSpan > 0) { - break; - } - } - if ((calculateCrossSpan == 0) || (calculateCrossSpan >= tempCrossSpan)) { - calculateCrossSpan = tempCrossSpan; - } - } else { - // check if the first flowitem's crossSpan of the row is large then crossCount_ - if (crossCount_ < crossSpan && calculateCrossSpan == 0) { - calculateCrossSpan = crossCount_; - } - } -} - -bool RenderWaterFlow::CheckFlowPlaced(int32_t index, int32_t main, int32_t cross, int32_t& mainSpan, int32_t& crossSpan) -{ - auto mainIter = flowMatrix_.find(main); - if (mainIter != flowMatrix_.end()) { - auto crossIter = mainIter->second.find(cross); - if (crossIter != mainIter->second.end()) { - return false; - } - } - int32_t calculateCrossSpan = 0; - for (int32_t i = 0; i < mainSpan; i++) { - CalculateCrossSpan(i + main, cross, crossSpan, calculateCrossSpan); - } - if ((calculateCrossSpan != 0) && (calculateCrossSpan != crossSpan)) { - auto iter = itemSpanCache_.find(index); - if (iter != itemSpanCache_.end()) { - itemSpanCache_.erase(index); - } - Span span; - span.rowSpan = mainSpan; - span.colSpan = calculateCrossSpan; - itemSpanCache_.emplace(std::make_pair(index, span)); - crossSpan = calculateCrossSpan; - } - - for (int32_t i = main; i < main + mainSpan; ++i) { - std::map mainMap; - auto iter = flowMatrix_.find(i); - if (iter != flowMatrix_.end()) { - mainMap = iter->second; - } - for (int32_t j = cross; j < cross + crossSpan; ++j) { - mainMap.emplace(std::make_pair(j, index)); - } - flowMatrix_[i] = mainMap; - } - - std::map flowMap; - auto iterFlow = flowMatrixByIndex_.find(index); - if (iterFlow != flowMatrixByIndex_.end()) { - flowMap = iterFlow->second; - } - for (int32_t i = main; i < main + mainSpan; ++i) { - for (int32_t j = cross; j < cross + crossSpan; ++j) { - flowMap.emplace(std::make_pair(i, j)); - } - } - flowMatrixByIndex_[index] = flowMap; - - LOGD("CheckFlowPlaced done %{public}d %{public}d %{public}d %{public}d %{public}d", index, main, cross, mainSpan, - crossSpan); - return true; -} - -void RenderWaterFlow::LayoutChild(const RefPtr& child, int32_t main, int32_t cross, int32_t mainSpan, - int32_t crossSpan, bool needPosition) -{ - child->Layout(MakeInnerLayoutParam(main, cross, mainSpan, crossSpan)); - SetItemCalSizeNeeded(child, false); - - if (!needPosition) { - return; - } - if (useScrollable_ != SCROLLABLE::HORIZONTAL) { - child->SetPosition(Offset(0, mainSize_ + mainGap_)); - } else { - child->SetPosition(Offset(mainSize_ + mainGap_, 0)); - } -} - -void RenderWaterFlow::GetNextFlow(int32_t& curMain, int32_t& curCross) const -{ - ++curCross; - if (curCross >= crossCount_) { - curCross = 0; - ++curMain; - } -} - -void RenderWaterFlow::GetPreviousFlow(int32_t& curMain, int32_t& curCross) -{ - --curCross; - if (curCross < 0) { - curCross = crossCount_; - --curMain; - } -} - -LayoutParam RenderWaterFlow::MakeInnerLayoutParam( - int32_t main, int32_t cross, int32_t mainSpan, int32_t crossSpan) const -{ - LayoutParam innerLayout; - double mainLen = 0.0; - double crossLen = 0.0; - mainLen += GetSize(flowCells_) * mainSpan; - mainLen += (mainSpan - 1) * mainGap_; - - crossLen += GetSize(flowCells_, false) * crossSpan; - crossLen += (crossSpan - 1) * crossGap_; - - Size size; - LOGD("mainLen: %{public}lf", mainLen); - if (useScrollable_ == SCROLLABLE::HORIZONTAL) { - size = Size(mainLen, crossLen); - } else { - size = Size(crossLen, mainLen); - } - if (crossAxisAlign_ == FlexAlign::STRETCH) { - innerLayout.SetMinSize(size); - innerLayout.SetMaxSize(size); - } else { - innerLayout.SetMaxSize(size); - innerLayout.SetMinSize(size); - } - return innerLayout; -} - -void RenderWaterFlow::LoadForward() -{ - auto firstItem = 0; - decltype(flowMatrix_) flowMatrix(std::move(flowMatrix_)); - - int32_t count = 0; - int32_t endIndex = -1; - while (endIndex < startRankItemIndex_ - 1) { - if (!Rank(count, count == 0 ? firstItem : -1)) { - break; - } - count++; - auto mainItor = flowMatrix_.find(count - 1); - if (mainItor == flowMatrix_.end()) { - break; - } - for (int32_t cross = crossCount_ - 1; cross >= 0; cross--) { - auto iter = mainItor->second.find(cross); - if (iter != mainItor->second.end()) { - endIndex = iter->second; - break; - } - } - } - startRankItemIndex_ = firstItem; - if (count == 0) { - return; - } - for (const auto& item : flowMatrix) { - flowMatrix_[item.first + count] = item.second; - } - - decltype(inCache_) inCache(std::move(inCache_)); - for (const auto& item : inCache) { - LOGD("LoadForward inCache_.insert mainIndex: %{public}d.", item + count); - inCache_.insert(item + count); - } - - mainCount_ += count; - startIndex_ += count; -} - -void RenderWaterFlow::CaculateViewPortSceneOne() -{ - // move to top/left of first row/column - if (!NearZero(firstItemOffset_)) { - if (inCache_.find(startIndex_ + 1) != inCache_.end()) { - currentOffset_ += GetSize(flowCells_) + mainGap_ - firstItemOffset_; - startIndex_++; - } - firstItemOffset_ = 0.0; - } - // Move up - while (currentOffset_ > 0) { - if (startIndex_ > 0) { - if (inCache_.find(startIndex_ + 1) != inCache_.end()) { - bool vail = false; - SupplyItems(vail, startIndex_ - 1); - } - currentOffset_ -= GetSize(flowCells_) + mainGap_; - startIndex_--; - } - if (startIndex_ == 0 && startRankItemIndex_ > 0 && currentOffset_ > 0) { - LoadForward(); - } - if (startIndex_ == 0) { - break; - } - } - if (currentOffset_ < 0) { - firstItemOffset_ -= currentOffset_; - } else { - if (startIndex_ == 0) { - reachHead_ = true; - } - } - currentOffset_ = 0.0; -} - -bool RenderWaterFlow::CaculateViewPortSceneTwo(bool& NeedContinue) -{ - NeedContinue = false; - if (!NearZero(firstItemOffset_)) { - currentOffset_ -= firstItemOffset_; - firstItemOffset_ = 0.0; - } - // Move down - while (startIndex_ < mainCount_ && (currentOffset_ < 0 || needCalculateViewPort_)) { - currentOffset_ += GetSize(flowCells_) + mainGap_; - startIndex_++; - } - needCalculateViewPort_ = false; - if (currentOffset_ > 0) { - firstItemOffset_ = GetSize(flowCells_) + mainGap_ - currentOffset_; - currentOffset_ = 0.0; - startIndex_--; - } else if (!GreatOrEqual(0.0, BuildLazyFlowLayout(mainCount_, -currentOffset_))) { - NeedContinue = true; - return true; - } - currentOffset_ = 0.0; - auto blank = CalculateBlankOfEnd(); - if (GreatOrEqual(0.0, blank)) { - return false; - } - // request new item. - blank -= BuildLazyFlowLayout(mainCount_, blank); - if (blank <= 0) { - return false; - } - blank = blank - firstItemOffset_; - firstItemOffset_ = 0; - // Move up - while (blank > 0) { - if (startIndex_ == 0 && startRankItemIndex_ > 0) { - LoadForward(); - } - if (startIndex_ == 0) { - break; - } - if (inCache_.find(startIndex_ - 1) == inCache_.end()) { - bool vail = false; - SupplyItems(vail, startIndex_ - 1); - } - blank -= GetSize(flowCells_) + mainGap_; - startIndex_--; - } - firstItemOffset_ -= blank; - if (firstItemOffset_ < 0) { - firstItemOffset_ = 0; - } - reachTail_ = true; - return true; -} - -void RenderWaterFlow::CaculateViewPort() -{ - while (!NearZero(currentOffset_) || needCalculateViewPort_) { - if (currentOffset_ > 0) { - CaculateViewPortSceneOne(); - } else { - bool needSkip = false; - if (!CaculateViewPortSceneTwo(needSkip)) { - return; - } - if (needSkip) { - continue; - } - } - } -} - -double RenderWaterFlow::CalculateBlankOfEnd() -{ - double drawLength = 0.0 - firstItemOffset_; - for (int32_t main = startIndex_; main < mainCount_; main++) { - drawLength += GetSize(flowCells_) + mainGap_; - if (GreatOrEqual(drawLength, mainSize_)) { - break; - } - } - return mainSize_ - drawLength; -} - -bool RenderWaterFlow::CheckMainFull(int32_t mainIndex) -{ - auto mainItor = flowMatrix_.find(mainIndex); - if (mainItor == flowMatrix_.end()) { - return false; - } - - if (mainItor->second.size() < crossCount_) { - return false; - } - - return true; -} - -double RenderWaterFlow::SupplyItems( - bool& vailSupplyItem, int32_t mainIndex, int32_t itemIndex, bool needPosition, bool needRank) -{ - LOGD("%{public}s called mainIndex: %{public}d.", __PRETTY_FUNCTION__, mainIndex); - loadingIndex_ = -1; - ACE_SCOPED_TRACE("SupplyItems %d", mainIndex); - auto mainItor = flowMatrix_.find(mainIndex); - if (mainItor != flowMatrix_.end()) { - if (mainItor->second.size() == crossCount_) { - needRank = false; - } - } - - if ((inCache_.find(mainIndex) == inCache_.end() || !CheckMainFull(mainIndex)) && (mainIndex != 0) && needRank) { - Rank(mainIndex, itemIndex); - } - - vailSupplyItem = false; - - auto iter = flowMatrix_.find(mainIndex); - if (iter != flowMatrix_.end()) { - int32_t frontIndex = -1; - for (const auto& item : iter->second) { - if (item.second == frontIndex) { - continue; - } - if (((items_.find(item.second) != items_.end() && items_[item.second] != nullptr) || - buildChildByIndex_(item.second)) && - GetItemCalSizeNeeded(items_[item.second])) { - LOGD("SupplyItems resize() itemIndex: %{public}d", item.second); - int32_t itemRowSpan = GetItemSpan(items_[item.second], true); - int32_t itemColSpan = GetItemSpan(items_[item.second], false); - int32_t itemMain = -1; - int32_t itemCross = -1; - if (!GetItemMainCrossIndex(item.second, itemMain, itemCross)) { - itemMain = mainIndex; - itemCross = item.first; - } - if (useScrollable_ == SCROLLABLE::VERTICAL) { - LayoutChild(items_[item.second], itemMain, itemCross, itemRowSpan, itemColSpan, needPosition); - } else { - LayoutChild(items_[item.second], itemMain, itemCross, itemColSpan, itemRowSpan, needPosition); - } - vailSupplyItem = true; - } - frontIndex = item.second; - } - LOGD("SupplyItems inCache_.insert mainIndex: %{public}d.", mainIndex); - inCache_.insert(mainIndex); - return NearEqual(GetSize(flowCells_), Size::INFINITE_SIZE) ? 0.0 : GetSize(flowCells_); - } - return 0.0; -} - -int32_t RenderWaterFlow::CalItemIndexInRank(int32_t mainIndex) -{ - int32_t itemIndex = -1; - for (int32_t i = 1; (mainIndex - i) >= 0; i++) { - auto mainItor = flowMatrix_.find(mainIndex - i); - if (mainItor == flowMatrix_.end()) { - continue; - } - for (int32_t cross = crossCount_ - 1; cross >= 0; cross--) { - auto iter = mainItor->second.find(cross); - if (iter == mainItor->second.end()) { - continue; - } - if (itemIndex == -1) { - // fine the first itemIndex - itemIndex = iter->second + 1; - } else if (itemIndex <= iter->second + 1) { - // fine the max ID of itemIndex in the last line - itemIndex = iter->second + 1; - } - } - if (static_cast(mainItor->second.size()) == (crossCount_ - 1)) { - // search to the end, then the row of flowMatrix_ is all layouted - break; - } - } - return itemIndex; -} - -bool RenderWaterFlow::Rank(int32_t mainIndex, int32_t itemIndex) -{ - LOGD("%{public}s called. mainIndex:%{public}d itemIndex:%{public}d", __PRETTY_FUNCTION__, mainIndex, itemIndex); - - if (inCache_.find(mainIndex) != inCache_.end() && CheckMainFull(mainIndex)) { - return true; - } - ACE_SCOPED_TRACE("Rank [%d]", mainIndex); - - if (itemIndex == -1) { - itemIndex = CalItemIndexInRank(mainIndex); - } - - if (itemIndex == -1) { - LOGE("failed, itemIndex = -1, mainIndex = %d", mainIndex); - return false; - } - bool isFilled = false; - int32_t index = mainIndex; - int32_t crossIndex = 0; - bool placed = false; - while (!isFilled) { - int32_t itemMainSpan = -1; - int32_t itemCrossSpan = -1; - if (flowMatrixByIndex_.find(itemIndex) != flowMatrixByIndex_.end()) { - itemIndex++; - continue; - } - - if (!GetItemSpanFromCache(itemIndex, itemMainSpan, itemCrossSpan)) { - return false; - } - while (!CheckFlowPlaced(itemIndex, mainIndex, crossIndex, itemMainSpan, itemCrossSpan)) { - GetNextFlow(mainIndex, crossIndex); // crossIndex++ - if (mainIndex > index) { - isFilled = true; - break; - } - } - if (!isFilled) { - placed = true; - } - itemIndex++; - } - return true; -} - -void RenderWaterFlow::DealCache(int32_t start, int32_t end) -{ - if (loadingIndex_ != -1) { - return; - } - - std::set deleteItem; - for (const auto& item : inCache_) { - if (!(item < start - cacheCount_ || item > end + cacheCount_)) { - continue; - } - // check all item of inCache_ is in viewprot, if in viewprot the cacheCount_ cann't be delete - bool deleteEnable = true; - auto iter = flowMatrix_.find(item); - if (iter != flowMatrix_.end()) { - for (const auto& eachItem : iter->second) { - auto eachItemStartMain = GetItemMainIndex(eachItem.second); - if (items_[eachItem.second] == nullptr) { - continue; - } - auto eachItemEndMain = - eachItemStartMain + GetItemSpan(items_[eachItem.second], useScrollable_ != SCROLLABLE::HORIZONTAL); - if (!(eachItemEndMain < (start - cacheCount_) || eachItemStartMain > (end + cacheCount_))) { - deleteEnable = false; - break; - } - } - } - - if (deleteEnable) { - deleteItem.insert(item); - } - } - - for (const auto& item : deleteItem) { - DeleteItems(item, false); - } - LOGD("DealCache end: %{public}d, start: %{public}d", end, start); - for (int32_t i = 1; i <= cacheCount_; i++) { - if (inCache_.count(i + end) == 0 || !CheckMainFull(i + end)) { - loadingIndex_ = i + end; - LOGD("DealCache loadingIndex_: %{public}d.", loadingIndex_); - break; - } - if (start >= i && ((inCache_.count(start - i) == 0) || !CheckMainFull(start - i))) { - loadingIndex_ = start - i; - break; - } - } -} - -void RenderWaterFlow::DeleteItems(int32_t index, bool isTail) -{ - LOGD("%{public}s called. index: %{public}d", __PRETTY_FUNCTION__, index); - if (!deleteChildByIndex_) { - return; - } - - auto iter = flowMatrix_.find(index); - if (iter == flowMatrix_.end()) { - return; - } - for (const auto& item : iter->second) { - deleteChildByIndex_(item.second); - RemoveChildByIndex(item.second); - } - - inCache_.erase(index); -} - -void RenderWaterFlow::ClearLayout(int32_t index) -{ - currentOffset_ = 0.0; - showItem_.clear(); - childrenInRect_.clear(); - updateFlag_ = true; - reachHead_ = false; - reachTail_ = false; - startMainPos_ = 0.0; - endMainPos_ = 0.0; - firstItemOffset_ = 0.0; - endIndex_ = -1; - mainScrollExtent_ = 0.0; - lastOffset_ = 0.0; - estimateHeight_ = 0.0; - if (index > -1) { - int32_t main = GetItemMainIndex(index); - int32_t rows = flowMatrix_.size(); - DeleteItemsInMarix(rows, index); - for (auto it = inCache_.begin(); it != inCache_.end();) { - if (*it >= main) { - inCache_.erase(it++); - } else { - it++; - } - } - auto itFirst1 = itemSpanCache_.find(index); - if (itFirst1 != itemSpanCache_.end()) { - itemSpanCache_.erase(itFirst1, itemSpanCache_.end()); - } - auto itFirst3 = flowMatrixByIndex_.find(index); - if (itFirst3 != flowMatrixByIndex_.end()) { - flowMatrixByIndex_.erase(itFirst3, flowMatrixByIndex_.end()); - } - if (main <= startIndex_) { - startIndex_ = main; - } - } else { - startIndex_ = 0; - inCache_.clear(); - flowMatrix_.clear(); - flowMatrixByIndex_.clear(); - itemSpanCache_.clear(); - } -} - -void RenderWaterFlow::ClearItems(int32_t index) -{ - decltype(items_) items(std::move(items_)); - for (const auto& item : items) { - if (index <= item.first) { - deleteChildByIndex_(item.first); - RemoveChildByIndex(item.first); - } - } - loadingIndex_ = -1; -} - -int32_t RenderWaterFlow::GetItemMainIndex(int32_t index) const -{ - auto iter = flowMatrixByIndex_.find(index); - if (iter != flowMatrixByIndex_.end()) { - return iter->second.begin()->first; - } - return -1; -} - -bool RenderWaterFlow::GetItemMainCrossIndex(int32_t index, int32_t& mainIndex, int32_t& crossIndex) -{ - auto iter = flowMatrixByIndex_.find(index); - if (iter != flowMatrixByIndex_.end()) { - mainIndex = iter->second.begin()->first; - crossIndex = iter->second.begin()->second; - return true; - } - return false; -} - -void RenderWaterFlow::OnDataSourceUpdated(int32_t index) -{ - LOGD("OnDataSourceUpdated called. index:%{public}d", index); - if (items_.empty() && updateFlag_) { - return; - } - - ACE_SCOPED_TRACE("OnDataSourceUpdated %d", index); - auto items = flowMatrix_.find(startIndex_); - if (items != flowMatrix_.end() && items->second.size() > 0) { - currentItemIndex_ = items->second.begin()->second; - } - if (index >= 0) { - startRankItemIndex_ = index; - } else { - startRankItemIndex_ = 0; - } - auto offset = firstItemOffset_; - ClearItems(index); - ClearLayout(index); - currentOffset_ = -offset; - MarkNeedLayout(); -} - -bool RenderWaterFlow::CheckEndShowItemPlace(int32_t index) -{ - int32_t main = 0; - int32_t cross = 0; - if (!GetItemMainCrossIndex(index, main, cross)) { - return false; - } - int32_t itemMainSpan = GetItemSpan(items_[index], useScrollable_ != SCROLLABLE::HORIZONTAL); - int32_t mainIndex = main; - for (; mainIndex < (main + itemMainSpan); mainIndex++) { - auto items = flowMatrix_.find(mainIndex); - if (items == flowMatrix_.end()) { - return false; - } - if (items->second.size() < crossCount_) { - return true; - } - } - auto itemsNext = flowMatrix_.find(mainIndex); - if (itemsNext == flowMatrix_.end()) { - return true; - } - auto item = itemsNext->second.find(cross); - if (item == itemsNext->second.end()) { - return true; - } - return false; -} - -void RenderWaterFlow::CalculateWholeSize(double drawLength) -{ - if (flowMatrix_.empty()) { - return; - } - if (totalCountFlag_) { - int32_t lastRow = flowMatrix_.rbegin()->first; - int32_t totalRows = mainCount_; - lastRow++; - totalRows++; - if (lastRow > totalRows) { - totalRows = lastRow; - } - double drawLength2 = totalRows * mainLength_ + (totalRows - 1) * mainGap_; - if (lastRow <= totalRows && lastRow > 0) { - mainScrollExtent_ = (lastRow * drawLength2) / totalRows; - } - estimateHeight_ = mainScrollExtent_; - totalCountFlag_ = false; - } - bool isScrollable = false; - if (estimateHeight_ > mainSize_) { - isScrollable = true; - } - if (scrollBar_) { - scrollBar_->SetScrollable(isScrollable); - } - // get the start position in flow - LOGD("offset_ss startIndex_: %{public}d.", startIndex_); - startMainPos_ = GetSize(flowCells_) * (startIndex_) + mainGap_ * (startIndex_ - 1); - scrollBarExtent_ = GetSize(flowCells_) * (mainCount_) + mainGap_ * (mainCount_ - 1); - if (!isScrollable) { - currentOffset_ = 0.0; - } -} - -double RenderWaterFlow::GetEstimatedHeight() -{ - if (reachTail_) { - // reach the end og flow, update the total scroll bar length - estimateHeight_ = scrollBarExtent_; - } else { - estimateHeight_ = std::max(estimateHeight_, scrollBarExtent_); - } - return estimateHeight_; -} - -void RenderWaterFlow::InitScrollBar(const RefPtr& component) -{ - const RefPtr flow = AceType::DynamicCast(component); - if (!flow) { - LOGE("RenderWaterFlow update failed."); - EventReport::SendRenderException(RenderExcepType::RENDER_COMPONENT_ERR); - return; - } - - if (!flow->GetController()) { - flow->SetScrollBarDisplayMode(DisplayMode::OFF); - } - - const RefPtr theme = GetTheme(); - if (!theme) { - return; - } - if (scrollBar_) { - scrollBar_->Reset(); - } else { - RefPtr controller = AceType::MakeRefPtr(); - scrollBar_ = AceType::MakeRefPtr(flow->GetScrollBarDisplayMode(), theme->GetShapeMode()); - scrollBar_->SetScrollBarController(controller); - } - // set the scroll bar style - scrollBar_->SetReservedHeight(theme->GetReservedHeight()); - scrollBar_->SetMinHeight(theme->GetMinHeight()); - scrollBar_->SetMinDynamicHeight(theme->GetMinDynamicHeight()); - auto& scrollBarColor = flow->GetScrollBarColor(); - if (!scrollBarColor.empty()) { - scrollBarColor_ = Color::FromString(scrollBarColor); - } else { - scrollBarColor_ = theme->GetForegroundColor(); - } - scrollBar_->SetForegroundColor(scrollBarColor_); - scrollBar_->SetBackgroundColor(theme->GetBackgroundColor()); - scrollBar_->SetPadding(theme->GetPadding()); - scrollBar_->SetScrollable(true); - if (!flow->GetScrollBarWidth().empty()) { - const auto& width = StringUtils::StringToDimension(flow->GetScrollBarWidth()); - scrollBar_->SetInactiveWidth(width); - scrollBar_->SetNormalWidth(width); - scrollBar_->SetActiveWidth(width); - scrollBar_->SetTouchWidth(width); - } else { - scrollBar_->SetInactiveWidth(theme->GetNormalWidth()); - scrollBar_->SetNormalWidth(theme->GetNormalWidth()); - scrollBar_->SetActiveWidth(theme->GetActiveWidth()); - scrollBar_->SetTouchWidth(theme->GetTouchWidth()); - } - scrollBar_->InitScrollBar(AceType::WeakClaim(this), GetContext()); - SetScrollBarCallback(); -} - -void RenderWaterFlow::InitScrollBarProxy() -{ - if (!scrollBarProxy_) { - return; - } - auto&& scrollCallback = [weakScroll = AceType::WeakClaim(this)](double value, int32_t source) { - auto flow = weakScroll.Upgrade(); - if (!flow) { - LOGE("render flow is released"); - return false; - } - return flow->UpdateScrollPosition(value, source); - }; - scrollBarProxy_->UnRegisterScrollableNode(AceType::WeakClaim(this)); - scrollBarProxy_->RegisterScrollableNode({ AceType::WeakClaim(this), scrollCallback }); -} - -void RenderWaterFlow::SetScrollBarCallback() -{ - if (!scrollBar_ || !scrollBar_->NeedScrollBar()) { - return; - } - auto&& barEndCallback = [weakFlow = AceType::WeakClaim(this)](int32_t value) { - auto flow = weakFlow.Upgrade(); - if (!flow) { - LOGE("render flow is released"); - return; - } - flow->scrollBarOpacity_ = value; - flow->MarkNeedLayout(true); - }; - auto&& scrollEndCallback = [weakFlow = AceType::WeakClaim(this)]() { - auto flow = weakFlow.Upgrade(); - if (!flow) { - LOGE("render flow is released"); - return; - } - LOGD("trigger scroll end callback"); - }; - auto&& scrollCallback = [weakScroll = AceType::WeakClaim(this)](double value, int32_t source) { - auto flow = weakScroll.Upgrade(); - if (!flow) { - LOGE("render flow is released"); - return false; - } - return flow->UpdateScrollPosition(value, source); - }; - scrollBar_->SetCallBack(scrollCallback, barEndCallback, scrollEndCallback); -} - -bool RenderWaterFlow::AnimateTo(const Dimension& position, float duration, const RefPtr& curve) -{ - if (!animator_->IsStopped()) { - animator_->Stop(); - } - animator_->ClearInterpolators(); - animateDelta_ = 0.0; - auto animation = AceType::MakeRefPtr>(GetCurrentOffset(), NormalizeToPx(position), curve); - animation->AddListener([weakScroll = AceType::WeakClaim(this)](double value) { - auto scroll = weakScroll.Upgrade(); - if (scroll) { - scroll->DoJump(value, SCROLL_FROM_JUMP); - } - }); - animator_->AddInterpolator(animation); - animator_->SetDuration(duration); - animator_->ClearStopListeners(); - animator_->AddStopListener([weakScroll = AceType::WeakClaim(this)]() { - auto scroll = weakScroll.Upgrade(); - if (scroll) { - scroll->animateDelta_ = 0.0; - } - }); - animator_->Play(); - return true; -} - -Offset RenderWaterFlow::CurrentOffset() -{ - auto ctx = GetContext().Upgrade(); - if (!ctx) { - return useScrollable_ == SCROLLABLE::HORIZONTAL ? Offset(GetCurrentOffset(), 0.0) - : Offset(0.0, GetCurrentOffset()); - } - auto mainOffset = ctx->ConvertPxToVp(Dimension(GetCurrentOffset(), DimensionUnit::PX)); - Offset currentOffset = useScrollable_ == SCROLLABLE::HORIZONTAL ? Offset(mainOffset, 0.0) : Offset(0.0, mainOffset); - return currentOffset; -} - -void RenderWaterFlow::ScrollToEdge(OHOS::Ace::ScrollEdgeType edgeType, bool smooth) -{ - if (edgeType != ScrollEdgeType::SCROLL_TOP) { - LOGW("Not supported yet"); - return; - } - if (items_.empty() && updateFlag_) { - return; - } - if (scrollable_ && !scrollable_->IsStopped()) { - scrollable_->StopScrollable(); - } - currentItemIndex_ = 0; - startRankItemIndex_ = 0; - ClearItems(); - ClearLayout(); - MarkNeedLayout(); -} - -void RenderWaterFlow::DoJump(double position, int32_t source) -{ - double delta = position - animateDelta_; - UpdateScrollPosition(delta, source); - animateDelta_ = position; -} - -void RenderWaterFlow::OnPaintFinish() -{ - RenderNode::OnPaintFinish(); - if (showItem_.empty()) { - return; - } - auto currentStartItemCount = *showItem_.begin(); - auto currentEndItemCount = *showItem_.rbegin(); - if ((startShowItemIndex_ != currentStartItemCount) || (endShowItemIndex_ != currentEndItemCount)) { - startShowItemIndex_ = currentStartItemCount; - endShowItemIndex_ = currentEndItemCount; - } -} - -void RenderWaterFlow::OnPredictLayout(int64_t deadline) -{ - if (updateFlag_) { - return; - } - auto startTime = GetSysTimestamp(); // unit: ns - auto context = context_.Upgrade(); - if (!context) { - return; - } - if (!context->IsTransitionStop()) { - LOGD("In page transition, skip predict."); - return; - } - if (loadingIndex_ == -1) { - DealCache(startIndex_, endIndex_); - if (loadingIndex_ == -1) { - if (startIndex_ == 0 && startRankItemIndex_ > 0) { - LoadForward(); - MarkNeedPredictLayout(); - } - return; - } - } - LOGD("OnPredictLayout loadingIndex_: %{public}d.", loadingIndex_); - ACE_SCOPED_TRACE("OnPredictLayout %d", loadingIndex_); - if (GetSysTimestamp() - startTime + TIMETHRESHOLD > deadline * MICROSEC_TO_NANOSEC) { - MarkNeedPredictLayout(); - return; - } - bool vail = false; - SupplyItems(vail, loadingIndex_, -1); - if (vail) { - MarkNeedPredictLayout(); - } else { - loadingIndex_ = -1; - } -} - -bool RenderWaterFlow::IsAxisScrollable(AxisDirection direction) -{ - if (isVertical_) { - if (direction == AxisDirection::UP && reachHead_) { - return false; - } else if (direction == AxisDirection::DOWN && reachTail_) { - return false; - } else if (direction == AxisDirection::NONE) { - return false; - } - } else { - if (direction == AxisDirection::LEFT && reachHead_) { - return false; - } else if (direction == AxisDirection::RIGHT && reachTail_) { - return false; - } else if (direction == AxisDirection::NONE) { - return false; - } - } - return true; -} - -void RenderWaterFlow::HandleAxisEvent(const AxisEvent& event) -{ - double degree = 0.0f; - if (!NearZero(event.horizontalAxis)) { - degree = event.horizontalAxis; - } else if (!NearZero(event.verticalAxis)) { - degree = event.verticalAxis; - } - double offset = SystemProperties::Vp2Px(DP_PER_LINE_DESKTOP * LINE_NUMBER_DESKTOP * degree / MOUSE_WHEEL_DEGREES); - UpdateScrollPosition(-offset, SCROLL_FROM_ROTATE); -} - -WeakPtr RenderWaterFlow::CheckAxisNode() -{ - return AceType::WeakClaim(this); -} - -std::vector RenderWaterFlow::ParseCrossLength(double size, double gap) -{ - std::vector lens; - double crossLength = (size - (crossCount_ - 1) * gap) / crossCount_; - for (int32_t i = 0; i < crossCount_; i++) { - lens.push_back(crossLength); - } - - return lens; -} - -void RenderWaterFlow::OnChildAdded(const RefPtr& renderNode) -{ - RenderNode::OnChildAdded(renderNode); -} - -bool RenderWaterFlow::IsUseOnly() -{ - return true; -} - -int32_t RenderWaterFlow::RequestNextFocus(bool vertical, bool reverse) -{ - KeyDirection key = DIRECTION_MAP.at(rightToLeft_).at(vertical).at(reverse); - int32_t index = focusMove(key); - if (index < 0) { - return index; - } - return focusIndex_; -} - -void RenderWaterFlow::UpdateFocusInfo(int32_t focusIndex) -{ - if (focusIndex < 0) { - LOGW("Invalid focus index, update focus info failed."); - return; - } - if (focusIndex != focusIndex_) { - LOGD("Update focus index from %{public}d to %{public}d", focusIndex_, focusIndex); - focusIndex_ = focusIndex; - auto iter = flowMatrixByIndex_.find(focusIndex); - if (iter != flowMatrixByIndex_.end()) { - focusRow_ = iter->second.begin()->first; - focusCol_ = iter->second.begin()->second; - } - } -} - -int32_t RenderWaterFlow::GetItemSpan(const RefPtr& child, bool isRow) const -{ - int32_t depth = DEFAULT_DEPTH; - int32_t span = -1; - auto item = child; - auto flowItem = AceType::DynamicCast(item); - while (!flowItem && depth > 0) { - if (!item || item->GetChildren().empty()) { - return span; - } - item = item->GetChildren().front(); - flowItem = AceType::DynamicCast(item); - --depth; - } - if (flowItem) { - if (isRow) { - span = flowItem->GetRowSpan(); - } else { - auto crossItor = itemSpanCache_.find(GetIndexByNode(child)); - if (crossItor != itemSpanCache_.end()) { - span = crossItor->second.colSpan; - } else { - span = flowItem->GetColumnSpan(); - } - } - } - return span < 1 ? 1 : span; -} - -bool RenderWaterFlow::GetItemSpanFromCache(int32_t index, int32_t& rowSpan, int32_t& colSpan) -{ - auto itor = itemSpanCache_.find(index); - if (itor != itemSpanCache_.end()) { - rowSpan = itor->second.rowSpan; - colSpan = itor->second.colSpan; - } else { - auto item = items_.find(index); - if (item != items_.end()) { - rowSpan = GetItemSpan(item->second, useScrollable_ != SCROLLABLE::HORIZONTAL); - colSpan = GetItemSpan(item->second, useScrollable_ == SCROLLABLE::HORIZONTAL); - } else { - if (!getChildSpanByIndex_(index, useScrollable_ == SCROLLABLE::HORIZONTAL, rowSpan, colSpan)) { - return false; - } - } - Span span; - span.rowSpan = rowSpan; - span.colSpan = colSpan; - itemSpanCache_.emplace(std::make_pair(index, span)); - } - - return true; -} - -int32_t RenderWaterFlow::GetIndexByNode(const RefPtr& child) const -{ - for (const auto& item : items_) { - if (item.second == child) { - return item.first; - } - } - return -1; -} - -int32_t RenderWaterFlow::GetIndexByFlow(int32_t row, int32_t column) const -{ - LOGD("%{public}s begin. row: %{public}d, column: %{public}d", __PRETTY_FUNCTION__, row, column); - auto rowIter = flowMatrix_.find(row); - if (rowIter != flowMatrix_.end()) { - auto colIter = rowIter->second.find(column); - if (colIter != rowIter->second.end()) { - return colIter->second; - } - } - return -1; -} - -// Handle direction key move -int32_t RenderWaterFlow::focusMove(KeyDirection direction) -{ - int32_t nextRow = focusRow_ < 0 ? 0 : focusRow_; - int32_t nextCol = focusCol_ < 0 ? 0 : focusCol_; - int32_t next = focusIndex_; - while (focusIndex_ == next || next < 0) { - switch (direction) { - case KeyDirection::UP: - --nextRow; - break; - case KeyDirection::DOWN: - ++nextRow; - break; - case KeyDirection::LEFT: - --nextCol; - break; - case KeyDirection::RIGHT: - ++nextCol; - break; - default: - return -1; - } - if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { - if (nextRow < 0 || nextCol < 0 || nextRow >= mainCount_ || nextCol >= crossCount_) { - return -1; - } - } else { - if (nextRow < 0 || nextCol < 0 || nextRow >= crossCount_ || nextCol >= mainCount_) { - return -1; - } - } - - next = GetIndexByFlow(nextRow, nextCol); - } - LOGD("PreFocus:%{public}d CurrentFocus:%{public}d", focusIndex_, next); - focusRow_ = nextRow; - focusCol_ = nextCol; - focusIndex_ = next; - return next; -} - -void RenderWaterFlow::UpdateAccessibilityAttr() -{ - auto refPtr = accessibilityNode_.Upgrade(); - if (!refPtr) { - LOGD("accessibility node is not enabled."); - return; - } - auto collectionInfo = refPtr->GetCollectionInfo(); - if (direction_ == FlexDirection::COLUMN || direction_ == FlexDirection::COLUMN_REVERSE) { - collectionInfo.rows = mainCount_; - collectionInfo.columns = crossCount_; - } else { - collectionInfo.rows = crossCount_; - collectionInfo.columns = mainCount_; - } - - refPtr->SetCollectionInfo(collectionInfo); -} - -void RenderWaterFlow::SetItemCalSizeNeeded(const RefPtr& child, bool need) -{ - int32_t depth = DEFAULT_DEPTH; - auto item = child; - auto flowItem = AceType::DynamicCast(item); - while (!flowItem && depth > 0) { - if (!item || item->GetChildren().empty()) { - flowItem->SetCalSizeNeeded(need); - return; - } - item = item->GetChildren().front(); - flowItem = AceType::DynamicCast(item); - --depth; - } - if (flowItem) { - flowItem->SetCalSizeNeeded(need); - } -} - -bool RenderWaterFlow::GetItemCalSizeNeeded(const RefPtr& child) const -{ - int32_t depth = DEFAULT_DEPTH; - bool need = false; - auto item = child; - auto flowItem = AceType::DynamicCast(item); - while (!flowItem && depth > 0) { - if (!item || item->GetChildren().empty()) { - return need; - } - item = item->GetChildren().front(); - flowItem = AceType::DynamicCast(item); - --depth; - } - if (flowItem) { - need = flowItem->GetCalSizeNeeded(); - } - return need; -} - -void RenderWaterFlow::CheckAndInsertItems(int32_t mainIndex, int32_t itemIndex) -{ - auto item = items_.find(itemIndex); - if (((item != items_.end()) && (item->second == nullptr)) || (item == items_.end())) { - bool vail = false; - SupplyItems(vail, mainIndex, itemIndex); - } -} - -void RenderWaterFlow::OutPutMarix(int32_t rows, bool before) -{ - if (before) { - LOGD("marix_ss OutPutMarix before"); - } else { - LOGD("marix_ss OutPutMarix after"); - } - int32_t cols[5]; - for (int32_t i = 0; i < rows; i++) { - auto iterMain = flowMatrix_.find(i); - if (iterMain == flowMatrix_.end()) { - LOGD("marix_ss marix: %{public}d %{public}d %{public}d %{public}d %{public}d", -1, -1, -1, -1, -1); - continue; - } - std::map crossMap = iterMain->second; - for (int32_t j = 0; j < crossCount_; j++) { - auto iterCell = crossMap.find(j); - if (iterCell != crossMap.end()) { - cols[j] = iterCell->second; - } else { - cols[j] = -1; - } - } - } -} - -bool RenderWaterFlow::DeleteItemsInMarix(int32_t rows, int32_t itemIndex) -{ - bool deleteMainBeDelete = true; - int32_t main = -1; - int32_t cross = -1; - if (!GetItemMainCrossIndex(itemIndex, main, cross)) { - deleteMainBeDelete = false; - return deleteMainBeDelete; - } - for (int32_t i = 0; i < rows; i++) { - auto iter5 = flowMatrix_.find(i); - if (iter5 == flowMatrix_.end()) { - continue; - } - std::map mainMap2 = iter5->second; - for (int32_t j = 0; j < crossCount_; j++) { - auto iter6 = mainMap2.find(j); - if (iter6 == mainMap2.end()) { - continue; - } - if (iter6->second >= itemIndex) { - mainMap2.erase(j); - } - } - if (mainMap2.size() > 0) { - flowMatrix_[i] = mainMap2; - } else { - flowMatrix_.erase(i); - } - } - auto iter7 = flowMatrix_.find(main); - if (iter7 != flowMatrix_.end()) { - std::map mainMap = iter7->second; - for (int32_t k = 0; k < cross; k++) { - auto iteminf = mainMap.find(k); - if (iteminf == mainMap.end()) { - continue; - } - - int32_t Index = iteminf->second; - int32_t mainIndex = GetItemMainIndex(Index); - if (mainIndex == main) { - deleteMainBeDelete = false; - break; - } - } - } - return deleteMainBeDelete; -} -} // namespace OHOS::Ace::V2 \ No newline at end of file diff --git a/frameworks/core/components_v2/water_flow/render_water_flow.h b/frameworks/core/components_v2/water_flow/render_water_flow.h deleted file mode 100644 index edaf1f44..00000000 --- a/frameworks/core/components_v2/water_flow/render_water_flow.h +++ /dev/null @@ -1,327 +0,0 @@ -/* - * 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_V2_WATER_FLOW_RENDER_WATER_FLOW_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "core/components/common/layout/constants.h" -#include "core/components/common/properties/scroll_bar.h" -#include "core/components/positioned/positioned_component.h" -#include "core/components/scroll/scroll_bar_theme.h" -#include "core/components/scroll/scrollable.h" -#include "core/components/stack/stack_element.h" -#include "core/components_v2/water_flow/render_water_flow_item.h" -#include "core/components_v2/water_flow/water_flow_component.h" -#include "core/pipeline/base/render_node.h" - -namespace OHOS::Ace::V2 { -class WaterFlowEventInfo : public BaseEventInfo, public EventToJSONStringAdapter { - DECLARE_RELATIONSHIP_OF_CLASSES(WaterFlowEventInfo, BaseEventInfo, EventToJSONStringAdapter); - -public: - explicit WaterFlowEventInfo(int32_t scrollIndex) : BaseEventInfo("waterflow"), scrollIndex_(scrollIndex) {} - - ~WaterFlowEventInfo() = default; - - std::string ToJSONString() const override; - - int32_t GetScrollIndex() const - { - return scrollIndex_; - } - -private: - int32_t scrollIndex_ = 0; -}; - -typedef struct { - int32_t rowSpan = 0; - int32_t colSpan = 0; -} Span; - -class RenderWaterFlow : public RenderNode { - DECLARE_ACE_TYPE(RenderWaterFlow, RenderNode); - -public: - using BuildChildByIndex = std::function; - using GetChildSpanByIndex = std::function; - using DeleteChildByIndex = std::function; - - RenderWaterFlow() = default; - ~RenderWaterFlow() override; - - static RefPtr Create(); - - void Update(const RefPtr& component) override; - void CalAndPosItems(double& drawLength, int32_t& main); - void PerformLayout() override; - void OnPredictLayout(int64_t deadline) override; - - const std::list>& GetChildren() const override - { - return childrenInRect_; - } - - void SetBuildChildByIndex(BuildChildByIndex func) - { - buildChildByIndex_ = std::move(func); - } - - void SetDeleteChildByIndex(DeleteChildByIndex func) - { - deleteChildByIndex_ = std::move(func); - } - - void SetGetChildSpanByIndex(GetChildSpanByIndex func) - { - getChildSpanByIndex_ = std::move(func); - } - - void AddChildByIndex(int32_t index, const RefPtr& renderNode); - void RemoveChildByIndex(int32_t index) - { - auto item = items_.find(index); - if (item != items_.end()) { - RemoveChild(item->second); - items_.erase(item); - } - } - void ClearLayout(int32_t index = -1); - void ClearItems(int32_t index = 0); - void OnDataSourceUpdated(int32_t index); - bool CheckEndShowItemPlace(int32_t index); - - void SetTotalCount(int32_t totalCount) - { - if (totalCount_ == totalCount) { - return; - } - totalCount_ = totalCount; - totalCountFlag_ = true; - } - - double GetEstimatedHeight(); - // Used in WaterFlowPositionController - bool AnimateTo(const Dimension& position, float duration, const RefPtr& curve); - Offset CurrentOffset(); - void ScrollToEdge(ScrollEdgeType edgeType, bool smooth); - - Axis GetAxis() const - { - return useScrollable_ == SCROLLABLE::VERTICAL ? Axis::VERTICAL : Axis::HORIZONTAL; - } - - void OnPaintFinish() override; - - bool IsChildrenTouchEnable() override; - - size_t GetCachedSize() const - { - return endShowItemIndex_ - startShowItemIndex_; - } - - Offset GetLastOffset() const - { - return useScrollable_ == SCROLLABLE::VERTICAL ? Offset(0, lastOffset_) : Offset(lastOffset_, 0); - } - - void HandleAxisEvent(const AxisEvent& event) override; - - bool IsAxisScrollable(AxisDirection direction) override; - - WeakPtr CheckAxisNode() override; - - void OnChildAdded(const RefPtr& renderNode) override; - bool IsUseOnly() override; - int32_t RequestNextFocus(bool vertical, bool reverse); - void UpdateFocusInfo(int32_t focusIndex); - -protected: - int32_t GetItemSpan(const RefPtr& child, bool isRow) const; - bool GetItemSpanFromCache(int32_t index, int32_t& rowSpan, int32_t& colSpan); - int32_t GetIndexByFlow(int32_t row, int32_t column) const; - int32_t GetIndexByNode(const RefPtr& child) const; - // Handle direction key move - int32_t focusMove(KeyDirection direction); - void UpdateAccessibilityAttr(); - - std::vector ParseCrossLength(double size, double gap); - int32_t GetItemMainIndex(int32_t index) const; - void SetMainSize(Size& dst, const Size& src); - double GetSize(const Size& src, bool isMain = true) const; - void GetNextFlow(int32_t& curMain, int32_t& curCross) const; - void GetPreviousFlow(int32_t& curMain, int32_t& curCross); - LayoutParam MakeInnerLayoutParam(int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan) const; - void CalculateCrossSpan(int32_t mainIndex, int32_t cross, int32_t crossSpan, int32_t& calculateCrossSpan); - bool CheckFlowPlaced(int32_t index, int32_t row, int32_t col, int32_t& rowSpan, int32_t& colSpan); - - // Sets child position, the mainAxis does not contain the offset. - void SetChildPosition(const RefPtr& child, int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan); - - void CreateScrollable(); - void LayoutChild(const RefPtr& child, int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan, - bool needPosition = true); - void OnTouchTestHit( - const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; - bool UpdateScrollPosition(double offset, int32_t source); - void RecordLocation(); - - void CallGap(); - void InitialFlowProp(); - void CaculateViewPortSceneOne(); - bool CaculateViewPortSceneTwo(bool& NeedContinue); - void CaculateViewPort(); - double BuildLazyFlowLayout(int32_t index, double sizeNeed); - bool GetFlowSize(); - void BuildFlow(std::vector& cols); - double CalculateBlankOfEnd(); - double SupplyItems(bool& vailSupplyItem, int32_t mainIndex, int32_t itemIndex = -1, bool needPosition = true, - bool needRank = true); - bool CheckMainFull(int32_t mainIndex); - int32_t CalItemIndexInRank(int32_t mainIndex); - bool Rank(int32_t mainIndex, int32_t itemIndex = -1); - void DealCache(int32_t start, int32_t end); - void DeleteItems(int32_t index, bool isTail); - - void GetMinAndMaxIndex(int32_t& min, int32_t& max); - bool GetItemMainCrossIndex(int32_t index, int32_t& mainIndex, int32_t& crossIndex); - - bool NeedUpdate(const RefPtr& component); - - void CalculateWholeSize(double drawLength); - - void InitScrollBar(const RefPtr& component); - void InitScrollBarProxy(); - - void DoJump(double position, int32_t source); - void LoadForward(); - - double GetCurrentOffset() const - { - return startMainPos_ + currentOffset_ - firstItemOffset_; - } - - void SetScrollBarCallback(); - - void SetItemCalSizeNeeded(const RefPtr& child, bool need); - - bool GetItemCalSizeNeeded(const RefPtr& child) const; - - void CheckAndInsertItems(int32_t mainIndex, int32_t itemIndex); - - void OutPutMarix(int32_t rows, bool before); - - bool DeleteItemsInMarix(int32_t rows, int32_t itemIndex); - - enum class SCROLLABLE : uint32_t { - NO_SCROLL = 0, - VERTICAL, - HORIZONTAL, - }; - - SCROLLABLE useScrollable_ = SCROLLABLE::NO_SCROLL; - - std::unordered_map> items_; - std::set showItem_; - std::set inCache_; - std::list> childrenInRect_; - // Map structure: [Index - (rowSpan, columnSpan)] - std::map itemSpanCache_; - - RefPtr scrollable_; - bool reachHead_ = false; - bool reachTail_ = false; - std::optional firstLineToBottom_; - bool needCalculateViewPort_ = false; - double startMainPos_ = 0.0; - double endMainPos_ = 0.0; - double currentOffset_ = 0.0; - double animateDelta_ = 0.0; - double lastOffset_ = 0.0; - double firstItemOffset_ = 0.0; - int32_t startIndex_ = 0; - int32_t endIndex_ = -1; - - int32_t startShowItemIndex_ = 0; - int32_t endShowItemIndex_ = -1; - - int32_t startRankItemIndex_ = 0; - int32_t currentItemIndex_ = 0; - - double mainSize_ = 0.0; - double crossSize_ = 0.0; - int32_t mainCount_ = 0; - int32_t crossCount_ = 0; - double crossGap_ = 0.0; - double mainGap_ = 0.0; - int32_t totalCount_ = 0; - - // used for scrollbar - double scrollBarExtent_ = 0.0; - double mainScrollExtent_ = 0.0; - int32_t scrollBarOpacity_ = 0; - double estimateHeight_ = 0.0; - bool totalCountFlag_ = false; - Color scrollBarColor_; - - RefPtr scrollBarProxy_; - RefPtr scrollBar_; - RefPtr animator_; - RefPtr component_; - BuildChildByIndex buildChildByIndex_; - DeleteChildByIndex deleteChildByIndex_; - GetChildSpanByIndex getChildSpanByIndex_; - - int32_t loadingIndex_ = -1; - - int32_t cacheCount_ = 10; - - // add from RenderWaterFlowBase - bool isVertical_ = false; - bool updateFlag_ = false; - FlexDirection direction_ = FlexDirection::ROW; - FlexAlign crossAxisAlign_ = FlexAlign::CENTER; - - int32_t focusRow_ = -1; - int32_t focusCol_ = -1; - int32_t focusIndex_ = 0; - - double flowWidth_ = -1.0; - double flowHeight_ = -1.0; - double mainLength_ = 0.0; - Dimension userColGap_ = 0.0_px; - Dimension userRowGap_ = 0.0_px; - Dimension userMainLength_ = 0.0_px; - DisplayMode displayMode_ = DisplayMode::OFF; - bool rightToLeft_ = false; - // Map structure: [rowIndex - (columnIndex, index)] - std::map> flowMatrix_; - // Map structure: [Index - (rowIndex, columnIndex)] - std::map> flowMatrixByIndex_; - // Map structure: [rowIndex - columnIndex - (width, height)] - Size flowCells_; -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_H \ No newline at end of file diff --git a/frameworks/core/components_v2/water_flow/render_water_flow_creator.cpp b/frameworks/core/components_v2/water_flow/render_water_flow_creator.cpp deleted file mode 100644 index 58e59561..00000000 --- a/frameworks/core/components_v2/water_flow/render_water_flow_creator.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 "flutter_render_water_flow.h" -#include "rosen_render_water_flow.h" - -namespace OHOS::Ace::V2 { -RefPtr RenderWaterFlow::Create() -{ - if (SystemProperties::GetRosenBackendEnabled()) { -#ifdef ENABLE_ROSEN_BACKEND - return AceType::MakeRefPtr(); -#else - return nullptr; -#endif - } else { - return AceType::MakeRefPtr(); - } -} -} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/render_water_flow_item.cpp b/frameworks/core/components_v2/water_flow/render_water_flow_item.cpp deleted file mode 100644 index 2b47fc19..00000000 --- a/frameworks/core/components_v2/water_flow/render_water_flow_item.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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/water_flow/render_water_flow_item.h" - -#include "base/utils/utils.h" -#include "core/components_v2/water_flow/render_water_flow.h" -#include "core/components_v2/water_flow/water_flow_item_component.h" - -namespace OHOS::Ace::V2 { -RefPtr RenderWaterFlowItem::Create() -{ - return AceType::MakeRefPtr(); -} - -void RenderWaterFlowItem::Update(const RefPtr& component) -{ - const RefPtr flowItem = AceType::DynamicCast(component); - if (!flowItem) { - return; - } - SetColumnSpan(flowItem->GetColumnSpan()); - SetRowSpan(flowItem->GetRowSpan()); - SetForceRebuild(flowItem->ForceRebuild()); - onSelectId_ = flowItem->GetOnSelectId(); - selectable_ = flowItem->GetSelectable(); - MarkNeedLayout(); -} - -void RenderWaterFlowItem::PerformLayout() -{ - if (GetChildren().empty()) { - LOGE("RenderWaterFlowItem: no child found in RenderWaterFlowItem!"); - } else { - auto child = GetChildren().front(); - child->Layout(GetLayoutParam()); - child->SetPosition(Offset::Zero()); - SetLayoutSize(child->GetLayoutSize()); - } -} - -void RenderWaterFlowItem::HandleOnFocus() -{ - auto parent = GetParent().Upgrade(); - while (parent) { - auto waterFlow = AceType::DynamicCast(parent); - if (waterFlow) { - waterFlow->UpdateFocusInfo(index_); - break; - } - parent = parent->GetParent().Upgrade(); - } -} - -void RenderWaterFlowItem::SetColumnSpan(int32_t columnSpan) -{ - if (columnSpan <= 0) { - LOGW("Invalid columnSpan %{public}d", columnSpan); - return; - } - columnSpan_ = columnSpan; -} - -void RenderWaterFlowItem::SetRowSpan(int32_t rowSpan) -{ - if (rowSpan <= 0) { - LOGW("Invalid rowSpan %{public}d", rowSpan); - return; - } - rowSpan_ = rowSpan; -} -} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/render_water_flow_item.h b/frameworks/core/components_v2/water_flow/render_water_flow_item.h deleted file mode 100644 index bfc85fd3..00000000 --- a/frameworks/core/components_v2/water_flow/render_water_flow_item.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * 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_V2_WATER_FLOW_RENDER_WATER_FLOW_ITEM_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_ITEM_H - -#include "core/pipeline/base/render_node.h" - -namespace OHOS::Ace::V2 { -class RenderWaterFlowItem : public RenderNode { - DECLARE_ACE_TYPE(RenderWaterFlowItem, RenderNode); - -public: - using OnItemLongPressed = std::function&)>; - using OnSelectFunc = std::function; - - static RefPtr Create(); - - void Update(const RefPtr& component) override; - - void PerformLayout() override; - - void HandleOnFocus(); - - void SetColumnIndex(int32_t columnIndex); - void SetRowIndex(int32_t rowIndex); - void SetColumnSpan(int32_t columnSpan); - void SetRowSpan(int32_t rowSpan); - void SetForceRebuild(bool forceRebuild) - { - forceRebuild_ = forceRebuild; - } - - bool GetForceRebuild() const - { - return forceRebuild_; - } - - void SetBoundary() - { - TakeBoundary(); - } - - int32_t GetColumnSpan() const - { - return columnSpan_; - } - - int32_t GetRowSpan() const - { - return rowSpan_; - } - - void SetIndex(int32_t index) - { - index_ = index; - } - - bool ForceRebuild() const - { - return forceRebuild_; - } - - int32_t GetIndex() const - { - return index_; - } - - bool GetSelectable() const - { - return selectable_; - } - - OnSelectFunc GetOnSelectId() const - { - return onSelectId_; - } - - void MarkIsSelected(bool isSelected) - { - isSelected_ = isSelected; - } - - bool IsSelected() const - { - return isSelected_; - } - - void SetCalSizeNeeded(bool need) - { - needCalSize_ = need; - } - - bool GetCalSizeNeeded() const - { - return needCalSize_; - } - -private: - int32_t index_ = -1; - int32_t columnSpan_ = 1; - int32_t rowSpan_ = 1; - bool forceRebuild_ = false; - OnSelectFunc onSelectId_; - bool selectable_ = false; - bool isSelected_ = false; - bool needCalSize_ = true; -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_RENDER_WATER_FLOW_ITEM_H diff --git a/frameworks/core/components_v2/water_flow/rosen_render_water_flow.cpp b/frameworks/core/components_v2/water_flow/rosen_render_water_flow.cpp deleted file mode 100644 index 300321a6..00000000 --- a/frameworks/core/components_v2/water_flow/rosen_render_water_flow.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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/water_flow/rosen_render_water_flow.h" - -#include "render_service_client/core/ui/rs_node.h" - -#include "core/components/common/painter/rosen_scroll_bar_painter.h" -#include "core/pipeline/base/rosen_render_context.h" - -namespace OHOS::Ace::V2 { -void RosenRenderWaterFlow::Update(const RefPtr& component) -{ - RenderWaterFlow::Update(component); - auto rsNode = GetRSNode(); - if (rsNode == nullptr) { - return; - } - rsNode->SetClipToFrame(true); -} - -void RosenRenderWaterFlow::Paint(RenderContext& context, const Offset& offset) -{ - LOGD("Paint %{public}lf %{public}lf", GetLayoutSize().Width(), GetLayoutSize().Height()); - RenderNode::Paint(context, offset); - - // Notify scroll bar to update. - if (scrollBarProxy_) { - scrollBarProxy_->NotifyScrollBar(AceType::WeakClaim(this)); - } - - // render scroll bar - if (!scrollBar_ || !scrollBar_->NeedPaint()) { - GetEstimatedHeight(); - return; - } - 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) { - return; - } - 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); - Offset lastOffset = isVertical_ ? Offset(0, lastOffset_) : Offset(lastOffset_, 0); - scrollBar_->UpdateScrollBarRegion(offset, GetLayoutSize(), lastOffset, GetEstimatedHeight()); - RefPtr scrollPainter = AceType::MakeRefPtr(); - scrollPainter->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/water_flow/rosen_render_water_flow.h b/frameworks/core/components_v2/water_flow/rosen_render_water_flow.h deleted file mode 100644 index db7f02b7..00000000 --- a/frameworks/core/components_v2/water_flow/rosen_render_water_flow.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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_V2_WATER_FLOW_ROSEN_RENDER_WATER_FLOW_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_ROSEN_RENDER_WATER_FLOW_H - -#include "core/components_v2/water_flow/render_water_flow.h" - -namespace OHOS::Ace::V2 { -class RosenRenderWaterFlow : public RenderWaterFlow { - DECLARE_ACE_TYPE(RosenRenderWaterFlow, RenderWaterFlow); - -public: - RosenRenderWaterFlow() = default; - ~RosenRenderWaterFlow() override = default; - - void Update(const RefPtr& component) override; - void Paint(RenderContext& context, const Offset& offset) override; - -private: -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_ROSEN_RENDER_WATER_FLOW_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_component.cpp b/frameworks/core/components_v2/water_flow/water_flow_component.cpp deleted file mode 100644 index b4ed5362..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_component.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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/water_flow/water_flow_component.h" - -#include "core/components_v2/water_flow/render_water_flow.h" -#include "core/components_v2/water_flow/water_flow_element.h" -#include "core/pipeline/base/multi_composed_component.h" - -namespace OHOS::Ace::V2 { -RefPtr WaterFlowComponent::CreateElement() -{ - return AceType::MakeRefPtr(); -} - -RefPtr WaterFlowComponent::CreateRenderNode() -{ - return RenderWaterFlow::Create(); -} - -void WaterFlowComponent::SetMainLength(const Dimension& mainLength) -{ - if (mainLength.Value() < 0.0) { - LOGW("Invalid MainLength use 0px"); - return; - } - mainLength_ = mainLength; -} - -void WaterFlowComponent::SetColumnsGap(const Dimension& columnsGap) -{ - if (columnsGap.Value() < 0.0) { - LOGW("Invalid RowGap, use 0px"); - columnsGap_ = 0.0_px; - return; - } - columnsGap_ = columnsGap; -} - -void WaterFlowComponent::SetRowsGap(const Dimension& rowsGap) -{ - if (rowsGap.Value() < 0.0) { - LOGW("Invalid RowGap, use 0px"); - rowsGap_ = 0.0_px; - return; - } - rowsGap_ = rowsGap; -} - -void WaterFlowComponent::SetLayoutDirection(FlexDirection direction) -{ - if (direction < FlexDirection::ROW || direction > FlexDirection::COLUMN_REVERSE) { - LOGW("Invalid direction %{public}d", direction); - return; - } - direction_ = direction; -} - -void WaterFlowComponent::SetFlexAlign(FlexAlign flexAlign) -{ - if (flexAlign < FlexAlign::FLEX_START || flexAlign > FlexAlign::STRETCH) { - LOGW("Invalid flexAlign %{public}d", flexAlign); - return; - } - flexAlign_ = flexAlign; -} - -void WaterFlowComponent::SetController(const RefPtr& controller) -{ - controller_ = controller; -} - -void WaterFlowComponent::SetScrollBarProxy(const RefPtr& scrollBarProxy) -{ - scrollBarProxy_ = scrollBarProxy; -} - -void WaterFlowComponent::SetRightToLeft(bool rightToLeft) -{ - rightToLeft_ = rightToLeft; -} - -void WaterFlowComponent::SetScrolledEvent(const EventMarker& event) -{ - scrolledEvent_ = event; -} - -void WaterFlowComponent::SetScrollBarDisplayMode(DisplayMode displayMode) -{ - displayMode_ = displayMode; -} - -void WaterFlowComponent::SetScrollBarColor(const std::string& color) -{ - scrollBarColor_ = color; -} - -void WaterFlowComponent::SetScrollBarWidth(const std::string& width) -{ - scrollBarWidth_ = width; -} -} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_component.h b/frameworks/core/components_v2/water_flow/water_flow_component.h deleted file mode 100644 index bce75fed..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_component.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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_V2_WATER_FLOW_WATER_FLOW_COMPONENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_COMPONENT_H - -#include "base/utils/macros.h" -#include "core/components/common/layout/constants.h" -#include "core/components/common/properties/scroll_bar.h" -#include "core/components/scroll_bar/scroll_bar_proxy.h" -#include "core/components_v2/water_flow/water_flow_position_controller.h" -#include "core/pipeline/base/component_group.h" - -namespace OHOS::Ace::V2 { -class ACE_EXPORT WaterFlowComponent : public ComponentGroup { - DECLARE_ACE_TYPE(WaterFlowComponent, ComponentGroup); - -public: - WaterFlowComponent(const std::list>& children, int32_t crossSplice) - : ComponentGroup(children), crossSplice_(crossSplice) - {} - - ~WaterFlowComponent() override = default; - - RefPtr CreateElement() override; - RefPtr CreateRenderNode() override; - - void SetMainLength(const Dimension& mainLength); - void SetColumnsGap(const Dimension& columnsGap); - void SetRowsGap(const Dimension& rowsGap); - void SetFlexAlign(FlexAlign flexAlign); - void SetRightToLeft(bool rightToLeft); - void SetLayoutDirection(FlexDirection direction); - void SetController(const RefPtr& controller); - void SetScrollBarProxy(const RefPtr& scrollBarProxy); - void SetScrolledEvent(const EventMarker& event); - void SetScrollBarDisplayMode(DisplayMode displayMode); - void SetScrollBarColor(const std::string& color); - void SetScrollBarWidth(const std::string& width); - - int32_t GetCrossSplice() const - { - return crossSplice_; - } - - const Dimension& GetMainLength() const - { - return mainLength_; - } - - const Dimension& GetColumnsGap() const - { - return columnsGap_; - } - - const Dimension& GetRowsGap() const - { - return rowsGap_; - } - - FlexDirection GetDirection() const - { - return direction_; - } - - FlexAlign GetFlexAlign() const - { - return flexAlign_; - } - - const RefPtr& GetController() const - { - return controller_; - } - - const RefPtr& GetScrollBarProxy() const - { - return scrollBarProxy_; - } - - bool GetRightToLeft() const - { - return rightToLeft_; - } - - const EventMarker& GetScrolledEvent() const - { - return scrolledEvent_; - } - - DisplayMode GetScrollBarDisplayMode() - { - return displayMode_; - } - - const std::string& GetScrollBarColor() const - { - return scrollBarColor_; - } - - const std::string& GetScrollBarWidth() const - { - return scrollBarWidth_; - } - -private: - int32_t crossSplice_ = 0; - Dimension mainLength_ = 0.0_px; - Dimension columnsGap_ = 0.0_px; - Dimension rowsGap_ = 0.0_px; - FlexDirection direction_ = FlexDirection::COLUMN; - FlexAlign flexAlign_ = FlexAlign::CENTER; - bool rightToLeft_ = false; - - // scroll bar attribute - std::string scrollBarColor_; - std::string scrollBarWidth_; - DisplayMode displayMode_ = DisplayMode::ON; - RefPtr controller_; - RefPtr scrollBarProxy_; - EventMarker scrolledEvent_; -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_COMPONENT_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_element.cpp b/frameworks/core/components_v2/water_flow/water_flow_element.cpp deleted file mode 100644 index f9328b8e..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_element.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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/water_flow/water_flow_element.h" - -#include "base/log/log.h" -#include "base/utils/utils.h" -#include "core/components/proxy/render_item_proxy.h" -#include "core/components_v2/water_flow/render_water_flow.h" -#include "core/components_v2/water_flow/water_flow_component.h" -#include "core/components_v2/water_flow/water_flow_item_component.h" - -namespace OHOS::Ace::V2 { -void WaterFlowElement::Update() -{ - RenderElement::Update(); - RefPtr render = AceType::DynamicCast(renderNode_); - if (!render) { - return; - } - render->OnDataSourceUpdated(0); -} - -RefPtr WaterFlowElement::CreateRenderNode() -{ - auto render = RenderElement::CreateRenderNode(); - RefPtr renderWaterFlow = AceType::DynamicCast(render); - if (renderWaterFlow) { - renderWaterFlow->SetBuildChildByIndex([weak = WeakClaim(this)](int32_t index) { - auto element = weak.Upgrade(); - if (!element) { - return false; - } - return element->BuildChildByIndex(index); - }); - - renderWaterFlow->SetDeleteChildByIndex([weak = WeakClaim(this)](int32_t index) { - auto element = weak.Upgrade(); - if (!element) { - return; - } - element->DeleteChildByIndex(index); - }); - - renderWaterFlow->SetGetChildSpanByIndex( - [weak = WeakClaim(this)](int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) { - auto element = weak.Upgrade(); - if (!element) { - return false; - } - return element->GetItemSpanByIndex(index, isHorizontal, itemMainSpan, itemCrossSpan); - }); - } - - return render; -} - -void WaterFlowElement::PerformBuild() -{ - auto component = AceType::DynamicCast(component_); - ACE_DCHECK(component); // MUST be WaterFlowComponent - V2::ElementProxyHost::UpdateChildren(component->GetChildren()); -} - -bool WaterFlowElement::BuildChildByIndex(int32_t index) -{ - if (index < 0) { - return false; - } - auto element = GetElementByIndex(index); - if (!element) { - LOGE("GetElementByIndex failed index=[%d]", index); - return false; - } - auto renderNode = element->GetRenderNode(); - if (!renderNode) { - LOGE("GetRenderNode failed"); - return false; - } - RefPtr waterFlow = AceType::DynamicCast(renderNode_); - if (!waterFlow) { - return false; - } - waterFlow->AddChildByIndex(index, renderNode); - return true; -} - -bool WaterFlowElement::GetItemSpanByIndex( - int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan) -{ - if (index < 0) { - return false; - } - auto component = GetComponentByIndex(index); - auto flowItem = AceType::DynamicCast(component); - - if (!flowItem) { - return false; - } - if (isHorizontal) { - itemMainSpan = flowItem->GetColumnSpan(); - itemCrossSpan = flowItem->GetRowSpan(); - } else { - itemMainSpan = flowItem->GetRowSpan(); - itemCrossSpan = flowItem->GetColumnSpan(); - } - return true; -} - -void WaterFlowElement::DeleteChildByIndex(int32_t index) -{ - ReleaseElementByIndex(index); -} - -bool WaterFlowElement::RequestNextFocus(bool vertical, bool reverse, const Rect& rect) -{ - RefPtr waterFlow = AceType::DynamicCast(renderNode_); - if (!waterFlow) { - LOGE("Render waterFlow is null."); - return false; - } - LOGI("RequestNextFocus vertical:%{public}d reverse:%{public}d.", vertical, reverse); - bool ret = false; - while (!ret) { - int32_t focusIndex = waterFlow->RequestNextFocus(vertical, reverse); - int32_t size = GetChildrenList().size(); - if (focusIndex < 0 || focusIndex >= size) { - return false; - } - auto iter = GetChildrenList().begin(); - std::advance(iter, focusIndex); - auto focusNode = *iter; - if (!focusNode) { - LOGE("Target focus node is null."); - return false; - } - // If current Node can not obtain focus, move to next. - ret = focusNode->RequestFocusImmediately(); - } - return ret; -} - -void WaterFlowElement::ApplyRenderChild(const RefPtr& renderChild) -{ - if (!renderChild) { - LOGE("Element child is null"); - return; - } - - if (!renderNode_) { - LOGE("RenderElement don't have a render node"); - return; - } - renderNode_->AddChild(renderChild->GetRenderNode()); -} - -RefPtr WaterFlowElement::OnUpdateElement(const RefPtr& element, const RefPtr& component) -{ - return UpdateChild(element, component); -} - -RefPtr WaterFlowElement::OnMakeEmptyComponent() -{ - return AceType::MakeRefPtr(); -} - -void WaterFlowElement::OnDataSourceUpdated(size_t startIndex) -{ - auto context = context_.Upgrade(); - if (context) { - context->AddPostFlushListener(AceType::Claim(this)); - } - RefPtr render = AceType::DynamicCast(renderNode_); - if (!render) { - return; - } - render->OnDataSourceUpdated(static_cast(startIndex)); - render->SetTotalCount(ElementProxyHost::TotalCount()); -} - -void WaterFlowElement::OnPostFlush() -{ - ReleaseRedundantComposeIds(); -} - -size_t WaterFlowElement::GetReloadedCheckNum() -{ - RefPtr render = AceType::DynamicCast(renderNode_); - if (render) { - size_t cachedNum = render->GetCachedSize(); - if (cachedNum > 0) { - return cachedNum; - } - } - return ElementProxyHost::GetReloadedCheckNum(); -} - -void WaterFlowElement::Dump() -{ - DumpProxy(); -} -} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_element.h b/frameworks/core/components_v2/water_flow/water_flow_element.h deleted file mode 100644 index 3c895c2c..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_element.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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_V2_WATER_FLOW_WATER_FLOW_ELEMENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ELEMENT_H - -#include "base/utils/noncopyable.h" -#include "core/components_v2/common/element_proxy.h" -#include "core/focus/focus_node.h" -#include "core/pipeline/base/render_element.h" - -namespace OHOS::Ace::V2 { -class WaterFlowElement : public RenderElement, public FocusGroup, public FlushEvent, private V2::ElementProxyHost { - DECLARE_ACE_TYPE(WaterFlowElement, RenderElement, FocusGroup); - -public: - void Update() override; - void PerformBuild() override; - bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override; - - bool BuildChildByIndex(int32_t index); - void DeleteChildByIndex(int32_t index); - bool GetItemSpanByIndex(int32_t index, bool isHorizontal, int32_t& itemMainSpan, int32_t& itemCrossSpan); - size_t GetReloadedCheckNum() override; - void OnPostFlush() override; - void Dump() override; - -private: - RefPtr CreateRenderNode() override; - void ApplyRenderChild(const RefPtr& renderChild) override; - - RefPtr OnUpdateElement(const RefPtr& element, const RefPtr& component) override; - RefPtr OnMakeEmptyComponent() override; - void OnDataSourceUpdated(size_t startIndex) override; -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ELEMENT_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_item_component.cpp b/frameworks/core/components_v2/water_flow/water_flow_item_component.cpp deleted file mode 100644 index ed3184e4..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_item_component.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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/water_flow/water_flow_item_component.h" - -#include "core/components_v2/water_flow/render_water_flow_item.h" -#include "core/components_v2/water_flow/water_flow_item_element.h" - -namespace OHOS::Ace::V2 { -RefPtr WaterFlowItemComponent::CreateElement() -{ - return AceType::MakeRefPtr(); -} - -RefPtr WaterFlowItemComponent::CreateRenderNode() -{ - return RenderWaterFlowItem::Create(); -} - -void WaterFlowItemComponent::SetColumnSpan(int32_t columnSpan) -{ - if (columnSpan <= 0) { - LOGW("Invalid columnSpan %{public}d", columnSpan); - return; - } - columnSpan_ = columnSpan; -} - -void WaterFlowItemComponent::SetRowSpan(int32_t rowSpan) -{ - if (rowSpan <= 0) { - LOGW("Invalid rowSpan %{public}d", rowSpan); - return; - } - rowSpan_ = rowSpan; -} -} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_item_component.h b/frameworks/core/components_v2/water_flow/water_flow_item_component.h deleted file mode 100644 index 194b378d..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_item_component.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * 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_V2_WATER_FLOW_WATER_FLOW_ITEM_COMPONENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_COMPONENT_H - -#include "base/utils/macros.h" -#include "core/pipeline/base/sole_child_component.h" - -namespace OHOS::Ace::V2 { -using OnSelectFunc = std::function; - -class ACE_EXPORT WaterFlowItemComponent : public SoleChildComponent { - DECLARE_ACE_TYPE(WaterFlowItemComponent, SoleChildComponent); - -public: - WaterFlowItemComponent() = default; - explicit WaterFlowItemComponent(const RefPtr& child) : SoleChildComponent(child) {} - ~WaterFlowItemComponent() override = default; - - RefPtr CreateRenderNode() override; - - RefPtr CreateElement() override; - - void SetColumnIndex(int32_t columnIndex); - void SetRowIndex(int32_t rowIndex); - void SetColumnSpan(int32_t columnSpan); - void SetRowSpan(int32_t rowSpan); - void SetForceRebuild(bool forceRebuild) - { - forceRebuild_ = forceRebuild; - } - - void SetClickedEventId(const EventMarker& eventId) - { - clickEventId_ = eventId; - } - - const EventMarker& GetClickedEventId() const - { - return clickEventId_; - } - - int32_t GetColumnSpan() const - { - return columnSpan_; - } - - int32_t GetRowSpan() const - { - return rowSpan_; - } - - bool ForceRebuild() const - { - return forceRebuild_; - } - - bool GetSelectable() const - { - return selectable_; - } - - void SetSelectable(bool selectable) - { - selectable_ = selectable; - } - - OnSelectFunc GetOnSelectId() const - { - return onSelectId_; - } - - void SetOnSelectId(const OnSelectFunc& onSelectId) - { - onSelectId_ = onSelectId; - } - -private: - EventMarker clickEventId_; - int32_t columnSpan_ = 1; - int32_t rowSpan_ = 1; - bool forceRebuild_ = false; - OnSelectFunc onSelectId_; - bool selectable_ = false; -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_COMPONENT_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_item_element.cpp b/frameworks/core/components_v2/water_flow/water_flow_item_element.cpp deleted file mode 100644 index d9469115..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_item_element.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/water_flow/water_flow_item_element.h" - -#include "core/components_v2/water_flow/render_water_flow_item.h" - -namespace OHOS::Ace::V2 { -RefPtr WaterFlowItemElement::CreateRenderNode() -{ - SetOnFocusCallback([weak = WeakClaim(this)](void) { - auto element = weak.Upgrade(); - if (element) { - element->HandleOnFocus(); - } - }); - return SoleChildElement::CreateRenderNode(); -} - -void WaterFlowItemElement::HandleOnFocus() -{ - auto waterFlowItem = AceType::DynamicCast(GetRenderNode()); - if (waterFlowItem) { - waterFlowItem->HandleOnFocus(); - } -} -} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_item_element.h b/frameworks/core/components_v2/water_flow/water_flow_item_element.h deleted file mode 100644 index 1c88869e..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_item_element.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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_V2_WATER_FLOW_WATER_FLOW_ITEM_ELEMENT_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_ELEMENT_H - -#include "core/pipeline/base/sole_child_element.h" - -namespace OHOS::Ace::V2 { -class WaterFlowItemElement : public SoleChildElement, public FocusGroup { - DECLARE_ACE_TYPE(WaterFlowItemElement, SoleChildElement, FocusGroup); - -public: - void HandleOnFocus(); - - bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override - { - // waterflow Item just one child, all focus move event make it blur. - return false; - } - -private: - RefPtr CreateRenderNode() override; -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_ELEMENT_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_position_controller.cpp b/frameworks/core/components_v2/water_flow/water_flow_position_controller.cpp deleted file mode 100644 index 221f53cd..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_position_controller.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/water_flow/water_flow_position_controller.h" - -#include "core/components_v2/water_flow/render_water_flow.h" -#include "core/components_v2/water_flow/water_flow_scroll_controller.h" - -namespace OHOS::Ace::V2 { -void WaterFlowPositionController::JumpTo(int32_t index, int32_t source) -{ - auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); - if (!waterFlow) { - return; - } - return; -} - -bool WaterFlowPositionController::AnimateTo(const Dimension& position, float duration, const RefPtr& curve) -{ - auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); - if (!waterFlow) { - return false; - } - return waterFlow->AnimateTo(position, duration, curve); -} - -Offset WaterFlowPositionController::GetCurrentOffset() const -{ - auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); - if (!waterFlow) { - return Offset::Zero(); - } - return waterFlow->CurrentOffset(); -} - -Axis WaterFlowPositionController::GetScrollDirection() const -{ - auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); - if (!waterFlow) { - return Axis::VERTICAL; - } - return waterFlow->GetAxis(); -} - -void WaterFlowPositionController::ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth) -{ - auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); - if (!waterFlow) { - return; - } - waterFlow->ScrollToEdge(scrollEdgeType, smooth); -} -} // namespace OHOS::Ace::V2 diff --git a/frameworks/core/components_v2/water_flow/water_flow_position_controller.h b/frameworks/core/components_v2/water_flow/water_flow_position_controller.h deleted file mode 100644 index d3f025a4..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_position_controller.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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_V2_WATER_FLOW_WATER_FLOW_POSITION_CONTROLLER_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_POSITION_CONTROLLER_H - -#include "core/components/scroll/scroll_controller_interface.h" -#include "core/components/scroll/scrollable.h" - -namespace OHOS::Ace::V2 { -class ACE_EXPORT WaterFlowPositionController : public ScrollController { - DECLARE_ACE_TYPE(WaterFlowPositionController, ScrollController); - -public: - WaterFlowPositionController() = default; - ~WaterFlowPositionController() override = default; - Axis GetScrollDirection() const override; - - void JumpTo(int32_t index, int32_t source = SCROLL_FROM_JUMP) override; - bool AnimateTo(const Dimension& position, float duration, const RefPtr& curve) override; - void ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth) override; - - Offset GetCurrentOffset() const override; -}; -} // namespace OHOS::Ace::V2 -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_POSITION_CONTROLLER_H diff --git a/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.cpp b/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.cpp deleted file mode 100644 index f642f8b0..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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/water_flow/water_flow_scroll_controller.h" - -#include "core/components_v2/water_flow/render_water_flow.h" - -namespace OHOS::Ace::V2 { -void WaterFlowScrollController::MarkScrollRender() -{ - auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); - if (waterFlow) { - waterFlow->MarkNeedLayout(); - } -} - -bool WaterFlowScrollController::CheckScroll() -{ - auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); - return waterFlow != nullptr; -} - -bool WaterFlowScrollController::UpdateScrollPosition(const double offset, int32_t source) -{ - if (!callback_) { - return true; - } - auto waterFlow = AceType::DynamicCast(scroll_.Upgrade()); - if (!waterFlow || NearZero(waterFlow->GetEstimatedHeight())) { - return true; - } - double height = waterFlow->GetLayoutSize().Height(); - double estimateHeight = waterFlow->GetEstimatedHeight(); - if (NearZero(estimateHeight)) { - return false; - } - double activeHeight = height * height / estimateHeight; - if (!NearEqual(height, activeHeight)) { - if (NearZero(height)) { - return false; - } - double value = offset * estimateHeight / height; - return callback_(value, source); - } - return true; -} - -void WaterFlowScrollController::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/water_flow/water_flow_scroll_controller.h b/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.h deleted file mode 100644 index 417cc97b..00000000 --- a/frameworks/core/components_v2/water_flow/water_flow_scroll_controller.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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_V2_WATER_FLOW_WATER_FLOW_SCROLL_CONTROLLER_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_SCROLL_CONTROLLER_H - -#include "core/components/scroll/scroll_bar_controller.h" - -namespace OHOS::Ace::V2 { -class WaterFlowScrollController : public ScrollBarController { - DECLARE_ACE_TYPE(WaterFlowScrollController, ScrollBarController); - -public: - WaterFlowScrollController() = default; - ~WaterFlowScrollController() 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_V2_WATER_FLOW_WATER_FLOW_SCROLL_CONTROLLER_H \ No newline at end of file