mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-01 21:14:03 -04:00
回退 'Pull Request !2056 : wateflow组件需求'
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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<std::string, std::function<void(BindingTarget)>>
|
||||
{ "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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<std::string, std::function<void(BindingTarget)>>
|
||||
{"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)
|
||||
|
||||
@@ -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<FlexDirection> 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<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
|
||||
JSRef<JSVal> crossSplice = obj->GetProperty("crossSplice");
|
||||
if (!crossSplice->IsNumber()) {
|
||||
LOGW("Args is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
// create waterflow component
|
||||
std::list<RefPtr<OHOS::Ace::Component>> componentChildren;
|
||||
auto waterflowComponent =
|
||||
AceType::MakeRefPtr<V2::WaterFlowComponent>(componentChildren, crossSplice->ToNumber<int32_t>());
|
||||
|
||||
// mainLength
|
||||
JSRef<JSVal> 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<JSObject>::Cast(args[1])->Unwrap<JSScroller>();
|
||||
if (jsScroller) {
|
||||
auto positionController = AceType::MakeRefPtr<V2::WaterFlowPositionController>();
|
||||
jsScroller->SetController(positionController);
|
||||
waterflowComponent->SetController(positionController);
|
||||
|
||||
// Init scroll bar proxy.
|
||||
auto proxy = jsScroller->GetScrollBarProxy();
|
||||
if (!proxy) {
|
||||
proxy = AceType::MakeRefPtr<ScrollBarProxy>();
|
||||
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<JSWaterFlow>::Declare("WaterFlow");
|
||||
|
||||
MethodOptions opt = MethodOptions::NONE;
|
||||
JSClass<JSWaterFlow>::StaticMethod("create", &JSWaterFlow::Create, opt);
|
||||
JSClass<JSWaterFlow>::StaticMethod("columnsGap", &JSWaterFlow::SetColumnsGap, opt);
|
||||
JSClass<JSWaterFlow>::StaticMethod("rowsGap", &JSWaterFlow::SetRowsGap, opt);
|
||||
JSClass<JSWaterFlow>::StaticMethod("layoutDirection", &JSWaterFlow::SetLayoutDirection, opt);
|
||||
JSClass<JSWaterFlow>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
|
||||
JSClass<JSWaterFlow>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
|
||||
|
||||
JSClass<JSWaterFlow>::Inherit<JSContainerBase>();
|
||||
JSClass<JSWaterFlow>::Inherit<JSViewAbstract>();
|
||||
JSClass<JSWaterFlow>::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<V2::WaterFlowComponent>(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<V2::WaterFlowComponent>(component);
|
||||
if (waterflow) {
|
||||
waterflow->SetRowsGap(rowGap);
|
||||
}
|
||||
}
|
||||
|
||||
void JSWaterFlow::SetLayoutDirection(int32_t value)
|
||||
{
|
||||
if (value >= 0 && value < static_cast<int32_t>(LAYOUT_DIRECTION.size())) {
|
||||
auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
|
||||
auto waterflow = AceType::DynamicCast<V2::WaterFlowComponent>(component);
|
||||
if (waterflow) {
|
||||
// not support the other layoutDirection except default for now.
|
||||
waterflow->SetLayoutDirection(FlexDirection::COLUMN);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
@@ -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
|
||||
@@ -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<V2::WaterFlowItemComponent>();
|
||||
ViewStackProcessor::GetInstance()->Push(itemComponent);
|
||||
}
|
||||
|
||||
void JSWaterFlowItem::JSBind(BindingTarget globalObj)
|
||||
{
|
||||
LOGD("JSWaterFlowItem:JSBind");
|
||||
JSClass<JSWaterFlowItem>::Declare("FlowItem");
|
||||
|
||||
MethodOptions opt = MethodOptions::NONE;
|
||||
JSClass<JSWaterFlowItem>::StaticMethod("create", &JSWaterFlowItem::Create, opt);
|
||||
JSClass<JSWaterFlowItem>::StaticMethod("rowSpan", &JSWaterFlowItem::SetRowSpan, opt);
|
||||
JSClass<JSWaterFlowItem>::StaticMethod("columnSpan", &JSWaterFlowItem::SetColumnSpan, opt);
|
||||
|
||||
JSClass<JSWaterFlowItem>::Inherit<JSContainerBase>();
|
||||
JSClass<JSWaterFlowItem>::Inherit<JSViewAbstract>();
|
||||
JSClass<JSWaterFlowItem>::Bind<>(globalObj);
|
||||
}
|
||||
|
||||
void JSWaterFlowItem::SetRowSpan(int32_t rowSpan)
|
||||
{
|
||||
auto flowItem =
|
||||
AceType::DynamicCast<V2::WaterFlowItemComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
|
||||
if (flowItem) {
|
||||
flowItem->SetRowSpan(rowSpan);
|
||||
}
|
||||
}
|
||||
|
||||
void JSWaterFlowItem::SetColumnSpan(int32_t columnSpan)
|
||||
{
|
||||
auto flowItem =
|
||||
AceType::DynamicCast<V2::WaterFlowItemComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
|
||||
if (flowItem) {
|
||||
flowItem->SetColumnSpan(columnSpan);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
@@ -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
|
||||
@@ -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<Component> ViewStackProcessor::WrapComponents()
|
||||
std::unordered_map<std::string, RefPtr<Component>> videoMap;
|
||||
|
||||
bool isItemComponent = AceType::InstanceOf<V2::ListItemComponent>(mainComponent) ||
|
||||
AceType::InstanceOf<GridLayoutItemComponent>(mainComponent) ||
|
||||
AceType::InstanceOf<V2::WaterFlowItemComponent>(mainComponent);
|
||||
AceType::InstanceOf<GridLayoutItemComponent>(mainComponent);
|
||||
|
||||
RefPtr<Component> itemChildComponent;
|
||||
|
||||
@@ -818,7 +816,8 @@ RefPtr<Component> ViewStackProcessor::GetScoringComponent() const
|
||||
void ViewStackProcessor::CreateInspectorComposedComponent(const std::string& inspectorTag)
|
||||
{
|
||||
if (V2::InspectorComposedComponent::HasInspectorFinished(inspectorTag)) {
|
||||
auto composedComponent = AceType::MakeRefPtr<V2::InspectorComposedComponent>(GenerateId(), inspectorTag);
|
||||
auto composedComponent =
|
||||
AceType::MakeRefPtr<V2::InspectorComposedComponent>(GenerateId(), inspectorTag);
|
||||
auto& wrappingComponentsMap = componentsStack_.top();
|
||||
wrappingComponentsMap.emplace("inspector", composedComponent);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<RenderNode>& node) const
|
||||
{
|
||||
return AceType::InstanceOf<RenderScroll>(node) || AceType::InstanceOf<V2::RenderGridScroll>(node) ||
|
||||
AceType::InstanceOf<V2::RenderList>(node) || AceType::InstanceOf<V2::RenderWaterFlow>(node);
|
||||
AceType::InstanceOf<V2::RenderList>(node);
|
||||
}
|
||||
|
||||
Axis ScrollBarProxy::GetScrollableAxis(const RefPtr<RenderNode>& node) const
|
||||
@@ -226,10 +225,6 @@ Axis ScrollBarProxy::GetScrollableAxis(const RefPtr<RenderNode>& node) const
|
||||
if (renderList) {
|
||||
return renderList->GetAxis();
|
||||
}
|
||||
auto renderWaterFlow = AceType::DynamicCast<V2::RenderWaterFlow>(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<V2::RenderWaterFlow>(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<RenderNode>& scrollable, Axis scro
|
||||
scrollableAxis = renderList->GetAxis();
|
||||
scrollableChildPosition = renderList->GetLastOffset();
|
||||
}
|
||||
|
||||
auto renderWaterFlow = AceType::DynamicCast<V2::RenderWaterFlow>(scrollable);
|
||||
if (renderWaterFlow) {
|
||||
scrollBarAxis == Axis::VERTICAL ? scrollableChildSize.SetHeight(renderWaterFlow->GetEstimatedHeight())
|
||||
: scrollableChildSize.SetWidth(renderWaterFlow->GetEstimatedHeight());
|
||||
scrollableAxis = renderWaterFlow->GetAxis();
|
||||
scrollableChildPosition = renderWaterFlow->GetLastOffset();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
@@ -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) {
|
||||
|
||||
@@ -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" ]
|
||||
}
|
||||
@@ -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<PipelineContext> mockContext_;
|
||||
RefPtr<RenderWaterFlow> renderNode_;
|
||||
const int32_t render_component_count = 5;
|
||||
};
|
||||
|
||||
void RenderWaterFlowTest::SetUpTestCase() {}
|
||||
void RenderWaterFlowTest::TearDownTestCase() {}
|
||||
|
||||
void RenderWaterFlowTest::SetUp()
|
||||
{
|
||||
mockContext_ = MockRenderCommon::GetMockContext();
|
||||
renderNode_ = AceType::MakeRefPtr<RenderWaterFlow>();
|
||||
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<WaterFlowComponent>(Component);
|
||||
if (!waterflowComponent) {
|
||||
GTEST_LOG_(INFO) << "create WaterFlow component failed!";
|
||||
return;
|
||||
}
|
||||
RefPtr<WaterFlowPositionController> controller = AceType::MakeRefPtr<WaterFlowPositionController>();
|
||||
RefPtr<ScrollBarProxy> scrollBarProxy = AceType::MakeRefPtr<ScrollBarProxy>();
|
||||
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<ScrollBar>(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<WaterFlowComponent>(Component);
|
||||
if (!waterflowComponent) {
|
||||
GTEST_LOG_(INFO) << "create WaterFlow component failed!";
|
||||
return;
|
||||
}
|
||||
RefPtr<WaterFlowPositionController> controller = AceType::MakeRefPtr<WaterFlowPositionController>();
|
||||
RefPtr<ScrollBarProxy> scrollBarProxy = AceType::MakeRefPtr<ScrollBarProxy>();
|
||||
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<RenderWaterFlowItem>(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<V2::RenderWaterFlowItem> 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<AccessibilityNode>(nodeId, nodeName);
|
||||
WeakPtr<AccessibilityNode> 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<RenderWaterFlowItem>(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<double> rowlens;
|
||||
std::vector<double> 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<double> 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<RenderWaterFlowItem>(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<double> 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<RefPtr<RenderNode>>& 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
|
||||
@@ -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<Component> WaterFlowTestUtils::CreateComponent(FlexDirection direction, int32_t cols)
|
||||
{
|
||||
std::list<RefPtr<Component>> children;
|
||||
Dimension RowGap = 50.0_px;
|
||||
Dimension ColumnsGap = 50.0_px;
|
||||
RefPtr<V2::WaterFlowComponent> component = AceType::MakeRefPtr<V2::WaterFlowComponent>(children, cols);
|
||||
component->SetRowsGap(RowGap);
|
||||
component->SetColumnsGap(ColumnsGap);
|
||||
component->SetLayoutDirection(direction);
|
||||
return component;
|
||||
}
|
||||
|
||||
RefPtr<Component> WaterFlowTestUtils::CreateComponentItem(const int32_t& itemMainSpan, const int32_t& itemCrossSpan)
|
||||
{
|
||||
RefPtr<BoxComponent> box = AceType::MakeRefPtr<BoxComponent>();
|
||||
RefPtr<V2::WaterFlowItemComponent> ComponentItem = AceType::MakeRefPtr<V2::WaterFlowItemComponent>(box);
|
||||
auto flowItem = AceType::DynamicCast<V2::WaterFlowItemComponent>(ComponentItem);
|
||||
if (flowItem) {
|
||||
flowItem->SetRowSpan(itemMainSpan);
|
||||
flowItem->SetColumnSpan(itemCrossSpan);
|
||||
return flowItem;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
RefPtr<V2::RenderWaterFlowItem> WaterFlowTestUtils::CreateRenderItem(
|
||||
int32_t rowSpan, int32_t colSpan, int32_t index, const RefPtr<PipelineContext>& context)
|
||||
{
|
||||
constexpr double DIM_SIZE_VALUE_TEST = 150.0;
|
||||
RefPtr<BoxComponent> boxComponent = AceType::MakeRefPtr<BoxComponent>();
|
||||
RefPtr<RenderBox> renderBox = AceType::MakeRefPtr<RenderBox>();
|
||||
boxComponent->SetWidth(DIM_SIZE_VALUE_TEST);
|
||||
boxComponent->SetHeight(DIM_SIZE_VALUE_TEST);
|
||||
renderBox->Update(boxComponent);
|
||||
renderBox->Attach(context);
|
||||
RefPtr<V2::RenderWaterFlowItem> Renderitem = AceType::MakeRefPtr<V2::RenderWaterFlowItem>();
|
||||
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<RenderNode> WaterFlowTestUtils::CreateRenderItem(
|
||||
double width, double height, int32_t rowspan, int32_t colspan, const RefPtr<PipelineContext>& context)
|
||||
{
|
||||
RefPtr<RenderBox> parent = AceType::MakeRefPtr<RenderBox>();
|
||||
RefPtr<V2::RenderWaterFlowItem> child = AceType::MakeRefPtr<V2::RenderWaterFlowItem>();
|
||||
RefPtr<RenderBox> renderBox = AceType::MakeRefPtr<RenderBox>();
|
||||
parent->Attach(context);
|
||||
child->Attach(context);
|
||||
renderBox->Attach(context);
|
||||
RefPtr<BoxComponent> boxComponent = AceType::MakeRefPtr<BoxComponent>();
|
||||
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
|
||||
@@ -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<void(const std::string&, const std::string&)>;
|
||||
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<RenderNode> CreateRenderItem(
|
||||
double width, double height, int32_t rowspan, int32_t colspan, const RefPtr<PipelineContext>& context);
|
||||
static RefPtr<V2::RenderWaterFlowItem> CreateRenderItem(
|
||||
int32_t rowspan, int32_t colspan, int32_t index, const RefPtr<PipelineContext>& contex);
|
||||
static RefPtr<Component> CreateComponent(FlexDirection direction, int32_t cols);
|
||||
static RefPtr<Component> 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
|
||||
@@ -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" ]
|
||||
}
|
||||
@@ -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<ClipLayer>(
|
||||
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<FlutterRenderContext*>(&context);
|
||||
flutter::Canvas* canvas = renderContext->GetCanvas();
|
||||
Offset lastOffset = isVertical_ ? Offset(0, lastOffset_) : Offset(lastOffset_, 0);
|
||||
scrollBar_->UpdateScrollBarRegion(offset, GetLayoutSize(), lastOffset, GetEstimatedHeight());
|
||||
RefPtr<FlutterScrollBarPainter> scrollPainter = AceType::MakeRefPtr<FlutterScrollBarPainter>();
|
||||
scrollPainter->PaintBar(canvas, offset, GetPaintRect(), scrollBar_, GetGlobalOffset(), scrollBarOpacity_);
|
||||
if (scrollBar_->GetFirstLoad()) {
|
||||
scrollBar_->SetFirstLoad(false);
|
||||
scrollBar_->HandleScrollBarEnd();
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::V2
|
||||
@@ -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<Flutter::ClipLayer> layer_;
|
||||
};
|
||||
} // namespace OHOS::Ace::V2
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_FLUTTER_RENDER_WATER_FLOW_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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 <atomic>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<bool(int32_t)>;
|
||||
using GetChildSpanByIndex = std::function<bool(int32_t, bool, int32_t&, int32_t&)>;
|
||||
using DeleteChildByIndex = std::function<void(int32_t)>;
|
||||
|
||||
RenderWaterFlow() = default;
|
||||
~RenderWaterFlow() override;
|
||||
|
||||
static RefPtr<RenderNode> Create();
|
||||
|
||||
void Update(const RefPtr<Component>& component) override;
|
||||
void CalAndPosItems(double& drawLength, int32_t& main);
|
||||
void PerformLayout() override;
|
||||
void OnPredictLayout(int64_t deadline) override;
|
||||
|
||||
const std::list<RefPtr<RenderNode>>& 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>& 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>& 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<RenderNode> CheckAxisNode() override;
|
||||
|
||||
void OnChildAdded(const RefPtr<RenderNode>& renderNode) override;
|
||||
bool IsUseOnly() override;
|
||||
int32_t RequestNextFocus(bool vertical, bool reverse);
|
||||
void UpdateFocusInfo(int32_t focusIndex);
|
||||
|
||||
protected:
|
||||
int32_t GetItemSpan(const RefPtr<RenderNode>& 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<RenderNode>& child) const;
|
||||
// Handle direction key move
|
||||
int32_t focusMove(KeyDirection direction);
|
||||
void UpdateAccessibilityAttr();
|
||||
|
||||
std::vector<double> 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<RenderNode>& child, int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan);
|
||||
|
||||
void CreateScrollable();
|
||||
void LayoutChild(const RefPtr<RenderNode>& 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<double>& 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>& component);
|
||||
|
||||
void CalculateWholeSize(double drawLength);
|
||||
|
||||
void InitScrollBar(const RefPtr<Component>& 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<RenderNode>& child, bool need);
|
||||
|
||||
bool GetItemCalSizeNeeded(const RefPtr<RenderNode>& 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<int32_t, RefPtr<RenderNode>> items_;
|
||||
std::set<int32_t> showItem_;
|
||||
std::set<int32_t> inCache_;
|
||||
std::list<RefPtr<RenderNode>> childrenInRect_;
|
||||
// Map structure: [Index - (rowSpan, columnSpan)]
|
||||
std::map<int32_t, Span> itemSpanCache_;
|
||||
|
||||
RefPtr<Scrollable> scrollable_;
|
||||
bool reachHead_ = false;
|
||||
bool reachTail_ = false;
|
||||
std::optional<bool> 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> scrollBarProxy_;
|
||||
RefPtr<ScrollBar> scrollBar_;
|
||||
RefPtr<Animator> animator_;
|
||||
RefPtr<V2::WaterFlowComponent> 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<int32_t, std::map<int32_t, int32_t>> flowMatrix_;
|
||||
// Map structure: [Index - (rowIndex, columnIndex)]
|
||||
std::map<int32_t, std::map<int32_t, int32_t>> 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
|
||||
@@ -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<RenderNode> RenderWaterFlow::Create()
|
||||
{
|
||||
if (SystemProperties::GetRosenBackendEnabled()) {
|
||||
#ifdef ENABLE_ROSEN_BACKEND
|
||||
return AceType::MakeRefPtr<RosenRenderWaterFlow>();
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
} else {
|
||||
return AceType::MakeRefPtr<FlutterRenderWaterFlow>();
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::V2
|
||||
@@ -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<RenderNode> RenderWaterFlowItem::Create()
|
||||
{
|
||||
return AceType::MakeRefPtr<RenderWaterFlowItem>();
|
||||
}
|
||||
|
||||
void RenderWaterFlowItem::Update(const RefPtr<Component>& component)
|
||||
{
|
||||
const RefPtr<V2::WaterFlowItemComponent> flowItem = AceType::DynamicCast<V2::WaterFlowItemComponent>(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<RenderWaterFlow>(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
|
||||
@@ -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<bool(int32_t, const WeakPtr<RenderNode>&)>;
|
||||
using OnSelectFunc = std::function<void(bool)>;
|
||||
|
||||
static RefPtr<RenderNode> Create();
|
||||
|
||||
void Update(const RefPtr<Component>& 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
|
||||
@@ -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>& 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<RosenRenderContext*>(&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<RosenScrollBarPainter> scrollPainter = AceType::MakeRefPtr<RosenScrollBarPainter>();
|
||||
scrollPainter->PaintBar(canvas, offset, GetPaintRect(), scrollBar_, GetGlobalOffset(), scrollBarOpacity_);
|
||||
if (scrollBar_->GetFirstLoad()) {
|
||||
scrollBar_->SetFirstLoad(false);
|
||||
scrollBar_->HandleScrollBarEnd();
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::V2
|
||||
@@ -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>& 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
|
||||
@@ -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<Element> WaterFlowComponent::CreateElement()
|
||||
{
|
||||
return AceType::MakeRefPtr<WaterFlowElement>();
|
||||
}
|
||||
|
||||
RefPtr<RenderNode> 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<V2::WaterFlowPositionController>& controller)
|
||||
{
|
||||
controller_ = controller;
|
||||
}
|
||||
|
||||
void WaterFlowComponent::SetScrollBarProxy(const RefPtr<ScrollBarProxy>& 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
|
||||
@@ -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<RefPtr<Component>>& children, int32_t crossSplice)
|
||||
: ComponentGroup(children), crossSplice_(crossSplice)
|
||||
{}
|
||||
|
||||
~WaterFlowComponent() override = default;
|
||||
|
||||
RefPtr<Element> CreateElement() override;
|
||||
RefPtr<RenderNode> 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<V2::WaterFlowPositionController>& controller);
|
||||
void SetScrollBarProxy(const RefPtr<ScrollBarProxy>& 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<V2::WaterFlowPositionController>& GetController() const
|
||||
{
|
||||
return controller_;
|
||||
}
|
||||
|
||||
const RefPtr<ScrollBarProxy>& 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<V2::WaterFlowPositionController> controller_;
|
||||
RefPtr<ScrollBarProxy> scrollBarProxy_;
|
||||
EventMarker scrolledEvent_;
|
||||
};
|
||||
} // namespace OHOS::Ace::V2
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_COMPONENT_H
|
||||
@@ -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<RenderWaterFlow> render = AceType::DynamicCast<RenderWaterFlow>(renderNode_);
|
||||
if (!render) {
|
||||
return;
|
||||
}
|
||||
render->OnDataSourceUpdated(0);
|
||||
}
|
||||
|
||||
RefPtr<RenderNode> WaterFlowElement::CreateRenderNode()
|
||||
{
|
||||
auto render = RenderElement::CreateRenderNode();
|
||||
RefPtr<RenderWaterFlow> renderWaterFlow = AceType::DynamicCast<RenderWaterFlow>(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<V2::WaterFlowComponent>(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<RenderWaterFlow> waterFlow = AceType::DynamicCast<RenderWaterFlow>(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<WaterFlowItemComponent>(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<RenderWaterFlow> waterFlow = AceType::DynamicCast<RenderWaterFlow>(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<RenderElement>& 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<Element> WaterFlowElement::OnUpdateElement(const RefPtr<Element>& element, const RefPtr<Component>& component)
|
||||
{
|
||||
return UpdateChild(element, component);
|
||||
}
|
||||
|
||||
RefPtr<Component> WaterFlowElement::OnMakeEmptyComponent()
|
||||
{
|
||||
return AceType::MakeRefPtr<WaterFlowItemComponent>();
|
||||
}
|
||||
|
||||
void WaterFlowElement::OnDataSourceUpdated(size_t startIndex)
|
||||
{
|
||||
auto context = context_.Upgrade();
|
||||
if (context) {
|
||||
context->AddPostFlushListener(AceType::Claim(this));
|
||||
}
|
||||
RefPtr<RenderWaterFlow> render = AceType::DynamicCast<RenderWaterFlow>(renderNode_);
|
||||
if (!render) {
|
||||
return;
|
||||
}
|
||||
render->OnDataSourceUpdated(static_cast<int32_t>(startIndex));
|
||||
render->SetTotalCount(ElementProxyHost::TotalCount());
|
||||
}
|
||||
|
||||
void WaterFlowElement::OnPostFlush()
|
||||
{
|
||||
ReleaseRedundantComposeIds();
|
||||
}
|
||||
|
||||
size_t WaterFlowElement::GetReloadedCheckNum()
|
||||
{
|
||||
RefPtr<RenderWaterFlow> render = AceType::DynamicCast<RenderWaterFlow>(renderNode_);
|
||||
if (render) {
|
||||
size_t cachedNum = render->GetCachedSize();
|
||||
if (cachedNum > 0) {
|
||||
return cachedNum;
|
||||
}
|
||||
}
|
||||
return ElementProxyHost::GetReloadedCheckNum();
|
||||
}
|
||||
|
||||
void WaterFlowElement::Dump()
|
||||
{
|
||||
DumpProxy();
|
||||
}
|
||||
} // namespace OHOS::Ace::V2
|
||||
@@ -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<RenderNode> CreateRenderNode() override;
|
||||
void ApplyRenderChild(const RefPtr<RenderElement>& renderChild) override;
|
||||
|
||||
RefPtr<Element> OnUpdateElement(const RefPtr<Element>& element, const RefPtr<Component>& component) override;
|
||||
RefPtr<Component> 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
|
||||
@@ -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<Element> WaterFlowItemComponent::CreateElement()
|
||||
{
|
||||
return AceType::MakeRefPtr<WaterFlowItemElement>();
|
||||
}
|
||||
|
||||
RefPtr<RenderNode> 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
|
||||
@@ -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<void(bool)>;
|
||||
|
||||
class ACE_EXPORT WaterFlowItemComponent : public SoleChildComponent {
|
||||
DECLARE_ACE_TYPE(WaterFlowItemComponent, SoleChildComponent);
|
||||
|
||||
public:
|
||||
WaterFlowItemComponent() = default;
|
||||
explicit WaterFlowItemComponent(const RefPtr<Component>& child) : SoleChildComponent(child) {}
|
||||
~WaterFlowItemComponent() override = default;
|
||||
|
||||
RefPtr<RenderNode> CreateRenderNode() override;
|
||||
|
||||
RefPtr<Element> 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
|
||||
@@ -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<RenderNode> 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<RenderWaterFlowItem>(GetRenderNode());
|
||||
if (waterFlowItem) {
|
||||
waterFlowItem->HandleOnFocus();
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Ace::V2
|
||||
@@ -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<RenderNode> CreateRenderNode() override;
|
||||
};
|
||||
} // namespace OHOS::Ace::V2
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_WATER_FLOW_WATER_FLOW_ITEM_ELEMENT_H
|
||||
@@ -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<V2::RenderWaterFlow>(scroll_.Upgrade());
|
||||
if (!waterFlow) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool WaterFlowPositionController::AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve)
|
||||
{
|
||||
auto waterFlow = AceType::DynamicCast<V2::RenderWaterFlow>(scroll_.Upgrade());
|
||||
if (!waterFlow) {
|
||||
return false;
|
||||
}
|
||||
return waterFlow->AnimateTo(position, duration, curve);
|
||||
}
|
||||
|
||||
Offset WaterFlowPositionController::GetCurrentOffset() const
|
||||
{
|
||||
auto waterFlow = AceType::DynamicCast<V2::RenderWaterFlow>(scroll_.Upgrade());
|
||||
if (!waterFlow) {
|
||||
return Offset::Zero();
|
||||
}
|
||||
return waterFlow->CurrentOffset();
|
||||
}
|
||||
|
||||
Axis WaterFlowPositionController::GetScrollDirection() const
|
||||
{
|
||||
auto waterFlow = AceType::DynamicCast<V2::RenderWaterFlow>(scroll_.Upgrade());
|
||||
if (!waterFlow) {
|
||||
return Axis::VERTICAL;
|
||||
}
|
||||
return waterFlow->GetAxis();
|
||||
}
|
||||
|
||||
void WaterFlowPositionController::ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth)
|
||||
{
|
||||
auto waterFlow = AceType::DynamicCast<V2::RenderWaterFlow>(scroll_.Upgrade());
|
||||
if (!waterFlow) {
|
||||
return;
|
||||
}
|
||||
waterFlow->ScrollToEdge(scrollEdgeType, smooth);
|
||||
}
|
||||
} // namespace OHOS::Ace::V2
|
||||
@@ -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>& 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
|
||||
@@ -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<RenderWaterFlow>(scroll_.Upgrade());
|
||||
if (waterFlow) {
|
||||
waterFlow->MarkNeedLayout();
|
||||
}
|
||||
}
|
||||
|
||||
bool WaterFlowScrollController::CheckScroll()
|
||||
{
|
||||
auto waterFlow = AceType::DynamicCast<RenderWaterFlow>(scroll_.Upgrade());
|
||||
return waterFlow != nullptr;
|
||||
}
|
||||
|
||||
bool WaterFlowScrollController::UpdateScrollPosition(const double offset, int32_t source)
|
||||
{
|
||||
if (!callback_) {
|
||||
return true;
|
||||
}
|
||||
auto waterFlow = AceType::DynamicCast<RenderWaterFlow>(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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user