* 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.
*/
#include <arkui/native_node_napi.h>
#include <js_native_api.h>
#include "NativeEntry.h"
#include "examples/guidelineOptionExample.h"
#include "examples/layoutConstraintExample.h"
#include "examples/alignRuleOptionExample.h"
#include "examples/barrierOptionExample.h"
#include "examples/layoutPolicyExample.h"
#include "examples/listChildrenMainSizeExample.h"
#include "examples/itemAlignmentExample.h"
#include "examples/relativeLayoutChainExample.h"
#include "examples/flexExample.h"
#include "examples/stackExample.h"
#include "examples/rowExample.h"
#include "examples/columnExample.h"
#include "examples/layoutPositionExample.h"
#include "examples/safeAreaExample.h"
#include "examples/refreshOffsetChangeExample.h"
#include "examples/positionEdgesExample.h"
#include "examples/pixelRoundExample.h"
namespace NativeModule {
template<typename CreateFuncType>
napi_value CreateNativeRootImpl(napi_env env, napi_callback_info info, CreateFuncType createFunc)
{
size_t argc = 1;
napi_value args[1] = {nullptr};
if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok) {
return nullptr;
}
ArkUI_NodeContentHandle contentHandle;
if (OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle) != 0) {
return nullptr;
}
auto node = createFunc();
NativeEntry::GetInstance()->SetRootNode(contentHandle, node);
return nullptr;
}
napi_value DestroyNativeRootImpl(napi_env env, napi_callback_info info)
{
size_t argc = 1;
napi_value args[1] = {nullptr};
if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok) {
return nullptr;
}
ArkUI_NodeContentHandle contentHandle;
if (OH_ArkUI_GetNodeContentFromNapiValue(env, args[0], &contentHandle) != 0) {
return nullptr;
}
NativeEntry::GetInstance()->DisposeRootNode(contentHandle);
return nullptr;
}
#define DEFINE_CREATE_DESTROY_FUNCTIONS(ModuleName, CreateFunc) \
napi_value Create##ModuleName##NativeRoot(napi_env env, napi_callback_info info) { \
return CreateNativeRootImpl(env, info, CreateFunc); \
} \
napi_value Destroy##ModuleName##NativeRoot(napi_env env, napi_callback_info info) { \
return DestroyNativeRootImpl(env, info); \
}
DEFINE_CREATE_DESTROY_FUNCTIONS(LayoutConstraint, CreateLayoutConstraintExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(AlignRuleOption, CreateAlignRuleOptionExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(GuidelineOption, CreateGuidelineOptionExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(BarrierOption, CreateBarrierOptionExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(ListChildrenMainSize, CreateListChildrenMainSizExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(ItemAlignment, itemAligmentExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(RelativeLayoutChain, RelativeLayoutChainExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(Flex, CreateFlexExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(Stack, CreateStackExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(Row, CreateRowExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(Column, CreateColumnExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(LayoutPosition, CreateLayoutPositionExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(SafeArea, SafeAreaExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(RefreshOffsetEvent, CreateRefreshOffsetEventExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(LayoutPolicy, CreateLayoutPolicyExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(PositionEdges, CreatePositionEdgesExample)
DEFINE_CREATE_DESTROY_FUNCTIONS(PixelRound, CreatePixelRoundExample)
}