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 "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.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 auto nativeNode = nodePtr(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 GetArkUINodeModifiers()->getColumnModifier()->setColumnJustifyContent(nativeNode, flexAlign);
41 } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
42 GetArkUINodeModifiers()->getColumnModifier()->resetColumnJustifyContent(nativeNode);
43 }
44 }
45 GetArkUINodeModifiers()->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 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
55 GetArkUINodeModifiers()->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 auto nativeNode = nodePtr(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)) || (value == static_cast<int32_t>(FlexAlign::STRETCH))) {
72 GetArkUINodeModifiers()->getColumnModifier()->setColumnAlignItems(nativeNode, value);
73 } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
74 GetArkUINodeModifiers()->getColumnModifier()->resetColumnAlignItems(nativeNode);
75 }
76 } else {
77 GetArkUINodeModifiers()->getColumnModifier()->resetColumnAlignItems(nativeNode);
78 }
79 return panda::JSValueRef::Undefined(vm);
80 }
81
ResetAlignItems(ArkUIRuntimeCallInfo * runtimeCallInfo)82 ArkUINativeModuleValue ColumnBridge::ResetAlignItems(ArkUIRuntimeCallInfo* runtimeCallInfo)
83 {
84 EcmaVM* vm = runtimeCallInfo->GetVM();
85 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
86 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
87 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
88 GetArkUINodeModifiers()->getColumnModifier()->resetColumnAlignItems(nativeNode);
89 return panda::JSValueRef::Undefined(vm);
90 }
91
SetSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)92 ArkUINativeModuleValue ColumnBridge::SetSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
93 {
94 EcmaVM* vm = runtimeCallInfo->GetVM();
95 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
96 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
97 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
98 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
99 CalcDimension space;
100 ArkTSUtils::ParseJsDimensionVp(vm, secondArg, space, false);
101 if (LessNotEqual(space.Value(), 0.0)) {
102 GetArkUINodeModifiers()->getColumnModifier()->resetColumnSpace(nativeNode);
103 return panda::JSValueRef::Undefined(vm);
104 }
105 GetArkUINodeModifiers()->getColumnModifier()->setColumnSpace(
106 nativeNode, space.Value(), static_cast<int>(space.Unit()));
107 return panda::JSValueRef::Undefined(vm);
108 }
109
ResetSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)110 ArkUINativeModuleValue ColumnBridge::ResetSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
111 {
112 EcmaVM* vm = runtimeCallInfo->GetVM();
113 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
114 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
115 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
116 GetArkUINodeModifiers()->getColumnModifier()->resetColumnSpace(nativeNode);
117 return panda::JSValueRef::Undefined(vm);
118 }
119
SetReverse(ArkUIRuntimeCallInfo * runtimeCallInfo)120 ArkUINativeModuleValue ColumnBridge::SetReverse(ArkUIRuntimeCallInfo* runtimeCallInfo)
121 {
122 EcmaVM* vm = runtimeCallInfo->GetVM();
123 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
124 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
125 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
126 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
127 auto hasValue = secondArg->IsBoolean();
128 if (!hasValue) {
129 GetArkUINodeModifiers()->getColumnModifier()->setColumnReverse(nativeNode, true);
130 return panda::JSValueRef::Undefined(vm);
131 }
132 auto isReverse = secondArg->ToBoolean(vm)->Value();
133 GetArkUINodeModifiers()->getColumnModifier()->setColumnReverse(nativeNode, isReverse);
134 return panda::JSValueRef::Undefined(vm);
135 }
136
ResetReverse(ArkUIRuntimeCallInfo * runtimeCallInfo)137 ArkUINativeModuleValue ColumnBridge::ResetReverse(ArkUIRuntimeCallInfo* runtimeCallInfo)
138 {
139 EcmaVM* vm = runtimeCallInfo->GetVM();
140 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
141 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
142 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
143 GetArkUINodeModifiers()->getColumnModifier()->resetColumnReverse(nativeNode);
144 return panda::JSValueRef::Undefined(vm);
145 }
146
147 } // namespace OHOS::Ace::NG
148