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 RefPtr<ResourceObject> spaceResObj;
101 ArkTSUtils::ParseJsDimensionVp(vm, secondArg, space, spaceResObj, false);
102 if (LessNotEqual(space.Value(), 0.0)) {
103 GetArkUINodeModifiers()->getColumnModifier()->resetColumnSpace(nativeNode);
104 return panda::JSValueRef::Undefined(vm);
105 }
106 auto spaceRawPtr = AceType::RawPtr(spaceResObj);
107 GetArkUINodeModifiers()->getColumnModifier()->setColumnSpace(
108 nativeNode, space.Value(), static_cast<int>(space.Unit()), spaceRawPtr);
109 return panda::JSValueRef::Undefined(vm);
110 }
111
ResetSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)112 ArkUINativeModuleValue ColumnBridge::ResetSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
113 {
114 EcmaVM* vm = runtimeCallInfo->GetVM();
115 CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
116 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
117 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
118 GetArkUINodeModifiers()->getColumnModifier()->resetColumnSpace(nativeNode);
119 return panda::JSValueRef::Undefined(vm);
120 }
121
SetReverse(ArkUIRuntimeCallInfo * runtimeCallInfo)122 ArkUINativeModuleValue ColumnBridge::SetReverse(ArkUIRuntimeCallInfo* runtimeCallInfo)
123 {
124 EcmaVM* vm = runtimeCallInfo->GetVM();
125 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
126 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
127 Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
128 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
129 auto hasValue = secondArg->IsBoolean();
130 if (!hasValue) {
131 GetArkUINodeModifiers()->getColumnModifier()->setColumnReverse(nativeNode, true);
132 return panda::JSValueRef::Undefined(vm);
133 }
134 auto isReverse = secondArg->ToBoolean(vm)->Value();
135 GetArkUINodeModifiers()->getColumnModifier()->setColumnReverse(nativeNode, isReverse);
136 return panda::JSValueRef::Undefined(vm);
137 }
138
ResetReverse(ArkUIRuntimeCallInfo * runtimeCallInfo)139 ArkUINativeModuleValue ColumnBridge::ResetReverse(ArkUIRuntimeCallInfo* runtimeCallInfo)
140 {
141 EcmaVM* vm = runtimeCallInfo->GetVM();
142 CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
143 Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
144 auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
145 GetArkUINodeModifiers()->getColumnModifier()->resetColumnReverse(nativeNode);
146 return panda::JSValueRef::Undefined(vm);
147 }
148
149 } // namespace OHOS::Ace::NG
150