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_column_bridge.h"
16
17 #include "core/interfaces/native/node/api.h"
18 #include "core/components/common/layout/constants.h"
19
20 namespace OHOS::Ace::NG {
21 constexpr int NUM_0 = 0;
22 constexpr int NUM_1 = 1;
23
SetJustifyContent(ArkUIRuntimeCallInfo * runtimeCallInfo)24 ArkUINativeModuleValue ColumnBridge::SetJustifyContent(ArkUIRuntimeCallInfo* runtimeCallInfo)
25 {
26 EcmaVM* vm = runtimeCallInfo->GetVM();
27 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
28 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
29 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
30 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
31 int32_t flexAlign = static_cast<int32_t>(FlexAlign::FLEX_START);
32 if (secondArg->IsInt()) {
33 flexAlign = secondArg->Int32Value(vm);
34 if ((flexAlign == static_cast<int32_t>(FlexAlign::FLEX_START)) ||
35 (flexAlign == static_cast<int32_t>(FlexAlign::FLEX_END)) ||
36 (flexAlign == static_cast<int32_t>(FlexAlign::CENTER)) ||
37 (flexAlign == static_cast<int32_t>(FlexAlign::SPACE_BETWEEN)) ||
38 (flexAlign == static_cast<int32_t>(FlexAlign::SPACE_AROUND)) ||
39 (flexAlign == static_cast<int32_t>(FlexAlign::SPACE_EVENLY))) {
40 GetArkUIInternalNodeAPI()->GetColumnModifier().SetColumnJustifyContent(nativeNode, flexAlign);
41 } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
42 GetArkUIInternalNodeAPI()->GetColumnModifier().ResetColumnJustifyContent(nativeNode);
43 }
44 }
45 GetArkUIInternalNodeAPI()->GetColumnModifier().SetColumnJustifyContent(nativeNode, flexAlign);
46 return panda::JSValueRef::Undefined(vm);
47 }
48
ResetJustifyContent(ArkUIRuntimeCallInfo * runtimeCallInfo)49 ArkUINativeModuleValue ColumnBridge::ResetJustifyContent(ArkUIRuntimeCallInfo* runtimeCallInfo)
50 {
51 EcmaVM* vm = runtimeCallInfo->GetVM();
52 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
53 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
54 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
55 GetArkUIInternalNodeAPI()->GetColumnModifier().ResetColumnJustifyContent(nativeNode);
56 return panda::JSValueRef::Undefined(vm);
57 }
58
SetAlignItems(ArkUIRuntimeCallInfo * runtimeCallInfo)59 ArkUINativeModuleValue ColumnBridge::SetAlignItems(ArkUIRuntimeCallInfo* runtimeCallInfo)
60 {
61 EcmaVM* vm = runtimeCallInfo->GetVM();
62 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
63 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
64 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
65 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
66 int32_t value;
67 if (secondArg->IsNumber()) {
68 value = secondArg->Int32Value(vm);
69 if ((value == static_cast<int32_t>(FlexAlign::FLEX_START)) ||
70 (value == static_cast<int32_t>(FlexAlign::FLEX_END)) ||
71 (value == static_cast<int32_t>(FlexAlign::CENTER)) ||
72 (value == static_cast<int32_t>(FlexAlign::STRETCH))) {
73 GetArkUIInternalNodeAPI()->GetColumnModifier().SetColumnAlignItems(nativeNode, value);
74 } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
75 GetArkUIInternalNodeAPI()->GetColumnModifier().ResetColumnAlignItems(nativeNode);
76 }
77 } else {
78 GetArkUIInternalNodeAPI()->GetColumnModifier().ResetColumnAlignItems(nativeNode);
79 }
80 return panda::JSValueRef::Undefined(vm);
81 }
82
ResetAlignItems(ArkUIRuntimeCallInfo * runtimeCallInfo)83 ArkUINativeModuleValue ColumnBridge::ResetAlignItems(ArkUIRuntimeCallInfo* runtimeCallInfo)
84 {
85 EcmaVM* vm = runtimeCallInfo->GetVM();
86 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
87 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
88 void* nativeNode = firstArg->ToNativePointer(vm)->Value();
89 GetArkUIInternalNodeAPI()->GetColumnModifier().ResetColumnAlignItems(nativeNode);
90 return panda::JSValueRef::Undefined(vm);
91 }
92 }
93