1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_row_bridge.h"
16 #include "base/geometry/dimension.h"
17 #include "core/interfaces/native/node/api.h"
18
19 namespace OHOS::Ace::NG {
SetAlignItems(ArkUIRuntimeCallInfo * runtimeCallInfo)20 ArkUINativeModuleValue RowBridge::SetAlignItems(ArkUIRuntimeCallInfo* runtimeCallInfo)
21 {
22 EcmaVM* vm = runtimeCallInfo->GetVM();
23 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
24 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
25 Local<JSValueRef> alignItemsArg = runtimeCallInfo->GetCallArgRef(1);
26 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
27 if (alignItemsArg->IsNumber()) {
28 int32_t alignItems = alignItemsArg->Int32Value(vm);
29 if ((alignItems == static_cast<int32_t>(FlexAlign::FLEX_START)) ||
30 (alignItems == static_cast<int32_t>(FlexAlign::FLEX_END)) ||
31 (alignItems == static_cast<int32_t>(FlexAlign::CENTER)) ||
32 (alignItems == static_cast<int32_t>(FlexAlign::STRETCH))) {
33 GetArkUIInternalNodeAPI()->GetRowModifier().SetRowAlignItems(nativeNode, alignItems);
34 } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
35 GetArkUIInternalNodeAPI()->GetRowModifier().ResetRowAlignItems(nativeNode);
36 }
37 } else {
38 GetArkUIInternalNodeAPI()->GetRowModifier().ResetRowAlignItems(nativeNode);
39 }
40 return panda::JSValueRef::Undefined(vm);
41 }
42
ResetAlignItems(ArkUIRuntimeCallInfo * runtimeCallInfo)43 ArkUINativeModuleValue RowBridge::ResetAlignItems(ArkUIRuntimeCallInfo* runtimeCallInfo)
44 {
45 EcmaVM* vm = runtimeCallInfo->GetVM();
46 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
47 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
48 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
49 GetArkUIInternalNodeAPI()->GetRowModifier().ResetRowAlignItems(nativeNode);
50 return panda::JSValueRef::Undefined(vm);
51 }
52
SetJustifyContent(ArkUIRuntimeCallInfo * runtimeCallInfo)53 ArkUINativeModuleValue RowBridge::SetJustifyContent(ArkUIRuntimeCallInfo* runtimeCallInfo)
54 {
55 EcmaVM* vm = runtimeCallInfo->GetVM();
56 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
57 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
58 Local<JSValueRef> justifyContentArg = runtimeCallInfo->GetCallArgRef(1);
59 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
60 if (justifyContentArg->IsNumber()) {
61 int32_t justifyContent = justifyContentArg->Int32Value(vm);
62 if ((justifyContent == static_cast<int32_t>(FlexAlign::FLEX_START)) ||
63 (justifyContent == static_cast<int32_t>(FlexAlign::FLEX_END)) ||
64 (justifyContent == static_cast<int32_t>(FlexAlign::CENTER)) ||
65 (justifyContent == static_cast<int32_t>(FlexAlign::SPACE_BETWEEN)) ||
66 (justifyContent == static_cast<int32_t>(FlexAlign::SPACE_AROUND)) ||
67 (justifyContent == static_cast<int32_t>(FlexAlign::SPACE_EVENLY))) {
68 GetArkUIInternalNodeAPI()->GetRowModifier().SetRowJustifyContent(nativeNode, justifyContent);
69 } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
70 GetArkUIInternalNodeAPI()->GetRowModifier().ResetRowJustifyContent(nativeNode);
71 }
72 } else {
73 GetArkUIInternalNodeAPI()->GetRowModifier().ResetRowJustifyContent(nativeNode);
74 }
75 return panda::JSValueRef::Undefined(vm);
76 }
77
ResetJustifyContent(ArkUIRuntimeCallInfo * runtimeCallInfo)78 ArkUINativeModuleValue RowBridge::ResetJustifyContent(ArkUIRuntimeCallInfo* runtimeCallInfo)
79 {
80 EcmaVM* vm = runtimeCallInfo->GetVM();
81 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
82 Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
83 void* nativeNode = nativeNodeArg->ToNativePointer(vm)->Value();
84 GetArkUIInternalNodeAPI()->GetRowModifier().ResetRowJustifyContent(nativeNode);
85 return panda::JSValueRef::Undefined(vm);
86 }
87 }
88