• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include "base/geometry/dimension.h"
18 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
19 
20 namespace OHOS::Ace::NG {
SetAlignItems(ArkUIRuntimeCallInfo * runtimeCallInfo)21 ArkUINativeModuleValue RowBridge::SetAlignItems(ArkUIRuntimeCallInfo* runtimeCallInfo)
22 {
23     EcmaVM* vm = runtimeCallInfo->GetVM();
24     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
25     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
26     Local<JSValueRef> alignItemsArg = runtimeCallInfo->GetCallArgRef(1);
27     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
28     if (alignItemsArg->IsNumber()) {
29         int32_t alignItems = alignItemsArg->Int32Value(vm);
30         if ((alignItems == static_cast<int32_t>(FlexAlign::FLEX_START)) ||
31             (alignItems == static_cast<int32_t>(FlexAlign::FLEX_END)) ||
32             (alignItems == static_cast<int32_t>(FlexAlign::CENTER)) ||
33             (alignItems == static_cast<int32_t>(FlexAlign::STRETCH))) {
34             GetArkUINodeModifiers()->getRowModifier()->setRowAlignItems(nativeNode, alignItems);
35         } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
36             GetArkUINodeModifiers()->getRowModifier()->resetRowAlignItems(nativeNode);
37         }
38     } else {
39         GetArkUINodeModifiers()->getRowModifier()->resetRowAlignItems(nativeNode);
40     }
41     return panda::JSValueRef::Undefined(vm);
42 }
43 
ResetAlignItems(ArkUIRuntimeCallInfo * runtimeCallInfo)44 ArkUINativeModuleValue RowBridge::ResetAlignItems(ArkUIRuntimeCallInfo* runtimeCallInfo)
45 {
46     EcmaVM* vm = runtimeCallInfo->GetVM();
47     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
48     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
49     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
50     GetArkUINodeModifiers()->getRowModifier()->resetRowAlignItems(nativeNode);
51     return panda::JSValueRef::Undefined(vm);
52 }
53 
SetJustifyContent(ArkUIRuntimeCallInfo * runtimeCallInfo)54 ArkUINativeModuleValue RowBridge::SetJustifyContent(ArkUIRuntimeCallInfo* runtimeCallInfo)
55 {
56     EcmaVM* vm = runtimeCallInfo->GetVM();
57     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
58     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
59     Local<JSValueRef> justifyContentArg = runtimeCallInfo->GetCallArgRef(1);
60     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
61     if (justifyContentArg->IsNumber()) {
62         int32_t justifyContent = justifyContentArg->Int32Value(vm);
63         if ((justifyContent == static_cast<int32_t>(FlexAlign::FLEX_START)) ||
64             (justifyContent == static_cast<int32_t>(FlexAlign::FLEX_END)) ||
65             (justifyContent == static_cast<int32_t>(FlexAlign::CENTER)) ||
66             (justifyContent == static_cast<int32_t>(FlexAlign::SPACE_BETWEEN)) ||
67             (justifyContent == static_cast<int32_t>(FlexAlign::SPACE_AROUND)) ||
68             (justifyContent == static_cast<int32_t>(FlexAlign::SPACE_EVENLY))) {
69             GetArkUINodeModifiers()->getRowModifier()->setRowJustifyContent(nativeNode, justifyContent);
70         } else if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TEN)) {
71             GetArkUINodeModifiers()->getRowModifier()->resetRowJustifyContent(nativeNode);
72         }
73     } else {
74         GetArkUINodeModifiers()->getRowModifier()->resetRowJustifyContent(nativeNode);
75     }
76     return panda::JSValueRef::Undefined(vm);
77 }
78 
ResetJustifyContent(ArkUIRuntimeCallInfo * runtimeCallInfo)79 ArkUINativeModuleValue RowBridge::ResetJustifyContent(ArkUIRuntimeCallInfo* runtimeCallInfo)
80 {
81     EcmaVM* vm = runtimeCallInfo->GetVM();
82     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
83     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(0);
84     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
85     GetArkUINodeModifiers()->getRowModifier()->resetRowJustifyContent(nativeNode);
86     return panda::JSValueRef::Undefined(vm);
87 }
88 
SetSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)89 ArkUINativeModuleValue RowBridge::SetSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
90 {
91     EcmaVM* vm = runtimeCallInfo->GetVM();
92     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
93     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
94     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
95     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
96     CalcDimension space;
97     RefPtr<ResourceObject> spaceResObj;
98     ArkTSUtils::ParseJsDimensionVp(vm, secondArg, space, spaceResObj, false);
99     if (LessNotEqual(space.Value(), 0.0)) {
100         GetArkUINodeModifiers()->getRowModifier()->resetRowSpace(nativeNode);
101         return panda::JSValueRef::Undefined(vm);
102     }
103     auto spaceRawPtr = AceType::RawPtr(spaceResObj);
104     GetArkUINodeModifiers()->getRowModifier()->setRowSpace(
105         nativeNode, space.Value(), static_cast<int>(space.Unit()), spaceRawPtr);
106     return panda::JSValueRef::Undefined(vm);
107 }
108 
ResetSpace(ArkUIRuntimeCallInfo * runtimeCallInfo)109 ArkUINativeModuleValue RowBridge::ResetSpace(ArkUIRuntimeCallInfo* runtimeCallInfo)
110 {
111     EcmaVM* vm = runtimeCallInfo->GetVM();
112     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
113     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
114     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
115     GetArkUINodeModifiers()->getRowModifier()->resetRowSpace(nativeNode);
116     return panda::JSValueRef::Undefined(vm);
117 }
118 
SetReverse(ArkUIRuntimeCallInfo * runtimeCallInfo)119 ArkUINativeModuleValue RowBridge::SetReverse(ArkUIRuntimeCallInfo* runtimeCallInfo)
120 {
121     EcmaVM* vm = runtimeCallInfo->GetVM();
122     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
123     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
124     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
125     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
126     auto hasValue = secondArg->IsBoolean();
127     if (!hasValue) {
128         GetArkUINodeModifiers()->getRowModifier()->setRowReverse(nativeNode, true);
129         return panda::JSValueRef::Undefined(vm);
130     }
131     auto isReverse = secondArg->ToBoolean(vm)->Value();
132     GetArkUINodeModifiers()->getRowModifier()->setRowReverse(nativeNode, isReverse);
133     return panda::JSValueRef::Undefined(vm);
134 }
135 
ResetReverse(ArkUIRuntimeCallInfo * runtimeCallInfo)136 ArkUINativeModuleValue RowBridge::ResetReverse(ArkUIRuntimeCallInfo* runtimeCallInfo)
137 {
138     EcmaVM* vm = runtimeCallInfo->GetVM();
139     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
140     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
141     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
142     GetArkUINodeModifiers()->getRowModifier()->resetRowReverse(nativeNode);
143     return panda::JSValueRef::Undefined(vm);
144 }
145 
146 } // namespace OHOS::Ace::NG
147