* Copyright (c) 2025 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 CAPI0805_2_ARKUILISTNODE_H
#define CAPI0805_2_ARKUILISTNODE_H
#include "ArkUINode.h"
namespace NativeModule {
namespace ListConstants {
static constexpr float DEFAULT_MAIN_SIZE = 60.0f;
static constexpr int32_t INITIAL_ARRAY_SIZE = 10;
static constexpr int32_t SPLICE_START_INDEX = 5;
static constexpr int32_t SPLICE_DELETE_COUNT = 0;
static constexpr int32_t SPLICE_INSERT_COUNT = 5;
static constexpr int32_t LOOP_START_INDEX = 5;
static constexpr int32_t LOOP_END_INDEX = 10;
static constexpr float ITEM_SIZE = 100.0f;
static constexpr int32_t TEST_INDEX = 5;
static constexpr size_t ATTRIBUTE_ITEM_COUNT = 1;
}
class ArkUIListNode : public ArkUINode {
public:
ArkUIListNode()
: ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_LIST)) {}
~ArkUIListNode() override {}
void SetListItemAlign(int32_t align)
{
assert(handle_);
ArkUI_NumberValue value[] = {{ .i32 = align }};
ArkUI_AttributeItem item = { value, 1 };
nativeModule_->setAttribute(handle_, NODE_LIST_ALIGN_LIST_ITEM, &item);
}
void SetChildrenMainSize(void *mainSize)
{
assert(handle_);
ArkUI_AttributeItem item = { .object = mainSize };
nativeModule_->setAttribute(handle_, NODE_LIST_CHILDREN_MAIN_SIZE, &item);
}
std::string SetChildrenMainSizeExample()
{
assert(handle_);
std::string mainSize = "";
auto childrenMainSize = OH_ArkUI_ListChildrenMainSizeOption_Create();
auto err = OH_ArkUI_ListChildrenMainSizeOption_SetDefaultMainSize(childrenMainSize,
ListConstants::DEFAULT_MAIN_SIZE);
mainSize += "SetDefaultMainSizeErr: " + std::to_string(err);
mainSize += "\n";
auto size = OH_ArkUI_ListChildrenMainSizeOption_GetDefaultMainSize(childrenMainSize);
mainSize += "defaultMainSize: " + std::to_string(size);
mainSize += "\n";
OH_ArkUI_ListChildrenMainSizeOption_Resize(childrenMainSize, ListConstants::INITIAL_ARRAY_SIZE);
err = OH_ArkUI_ListChildrenMainSizeOption_Splice(childrenMainSize,
ListConstants::SPLICE_START_INDEX,
ListConstants::SPLICE_DELETE_COUNT,
ListConstants::SPLICE_INSERT_COUNT);
mainSize += "spliceErr: " + std::to_string(err);
mainSize += "\n";
for (int i = ListConstants::LOOP_START_INDEX; i < ListConstants::LOOP_END_INDEX; i++) {
err = OH_ArkUI_ListChildrenMainSizeOption_UpdateSize(childrenMainSize, i, ListConstants::ITEM_SIZE);
}
mainSize += "UpdateSizeErr: " + std::to_string(err);
mainSize += "\n";
size = OH_ArkUI_ListChildrenMainSizeOption_GetMainSize(childrenMainSize, ListConstants::TEST_INDEX);
mainSize += "index [5] size: " + std::to_string(size);
mainSize += "\n";
SetChildrenMainSize(childrenMainSize);
OH_ArkUI_ListChildrenMainSizeOption_Dispose(childrenMainSize);
return mainSize;
}
};
class ArkUIListItemNode : public ArkUINode {
public:
ArkUIListItemNode()
: ArkUINode((NativeModuleInstance::GetInstance()->GetNativeNodeAPI())->createNode(ARKUI_NODE_LIST_ITEM)) {}
~ArkUIListItemNode() override {}
};
}
#endif