• 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 
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_calendar_picker_bridge.h"
17 #include "core/components/calendar/calendar_theme.h"
18 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
19 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
20 namespace OHOS::Ace::NG {
21 constexpr int NUM_0 = 0;
22 constexpr int NUM_1 = 1;
23 constexpr int NUM_2 = 2;
24 constexpr int NUM_3 = 3;
25 constexpr Dimension DEFAULT_TEXTSTYLE_FONTSIZE = 16.0_fp;
26 constexpr int PARAM_ARR_LENGTH_1 = 1;
27 const std::string FORMAT_FONT = "%s|%s";
28 
ParseCalendarPickerPadding(const EcmaVM * vm,const Local<JSValueRef> & value,CalcDimension & dim,ArkUISizeType & result)29 void ParseCalendarPickerPadding(
30     const EcmaVM* vm, const Local<JSValueRef>& value, CalcDimension& dim, ArkUISizeType& result)
31 {
32     if (ArkTSUtils::ParseJsDimensionVpNG(vm, value, dim)) {
33         if (LessOrEqual(dim.Value(), 0.0)) {
34             dim.SetValue(-1);
35             dim.SetUnit(DimensionUnit::VP);
36         }
37         result.unit = static_cast<int8_t>(dim.Unit());
38         if (dim.CalcValue() != "") {
39             result.string = dim.CalcValue().c_str();
40         } else {
41             result.value = dim.Value();
42         }
43     } else {
44         dim.SetValue(-1);
45         dim.SetUnit(DimensionUnit::VP);
46         result.unit = static_cast<int8_t>(dim.Unit());
47         result.value = dim.Value();
48     }
49 }
50 
GetMSByDate(const std::string & date)51 double GetMSByDate(const std::string& date)
52 {
53     auto json = JsonUtil::ParseJsonString(date);
54     if (!json || json->IsNull()) {
55         return 0.0f;
56     }
57 
58     std::tm dateTime {};
59     auto year = json->GetValue("year");
60     if (year && year->IsNumber()) {
61         dateTime.tm_year = year->GetInt() - 1900; // local date start from 1900
62     }
63     auto month = json->GetValue("month");
64     if (month && month->IsNumber()) {
65         dateTime.tm_mon = month->GetInt() - 1;
66     }
67     auto day = json->GetValue("day");
68     if (day && day->IsNumber()) {
69         dateTime.tm_mday = day->GetInt();
70     }
71     auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
72     auto local = std::localtime(&now);
73     CHECK_NULL_RETURN(local, 0.0f);
74     dateTime.tm_hour = local->tm_hour;
75     dateTime.tm_min = local->tm_min;
76     dateTime.tm_sec = local->tm_sec;
77     return Date::GetMilliSecondsByDateTime(dateTime);
78 }
79 
SetTextStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)80 ArkUINativeModuleValue CalendarPickerBridge::SetTextStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
81 {
82     EcmaVM* vm = runtimeCallInfo->GetVM();
83     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
84     auto pipeline = PipelineBase::GetCurrentContext();
85     CHECK_NULL_RETURN(pipeline, panda::NativePointerRef::New(vm, nullptr));
86     RefPtr<CalendarTheme> calendarTheme = pipeline->GetTheme<CalendarTheme>();
87     CHECK_NULL_RETURN(calendarTheme, panda::NativePointerRef::New(vm, nullptr));
88     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
89     Local<JSValueRef> colorArg = runtimeCallInfo->GetCallArgRef(NUM_1);
90     Local<JSValueRef> fontSizeArg = runtimeCallInfo->GetCallArgRef(NUM_2);
91     Local<JSValueRef> fontWeightArg = runtimeCallInfo->GetCallArgRef(NUM_3);
92     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
93     Color textColor = calendarTheme->GetEntryFontColor();
94     RefPtr<ResourceObject> textColorResObj;
95     ArkUIPickerTextStyleStruct textStyleStruct;
96     textStyleStruct.textColorSetByUser = false;
97     if (!colorArg->IsUndefined()) {
98         auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
99         if (ArkTSUtils::ParseJsColorAlpha(vm, colorArg, textColor, textColorResObj, nodeInfo)) {
100             textStyleStruct.textColorSetByUser = true;
101         }
102     }
103     CalcDimension fontSizeData(DEFAULT_TEXTSTYLE_FONTSIZE);
104     std::string fontSize = fontSizeData.ToString();
105     RefPtr<ResourceObject> fontSizeResObj;
106     if (ArkTSUtils::ParseJsDimensionFp(vm, fontSizeArg, fontSizeData, fontSizeResObj) &&
107         !fontSizeData.IsNegative() && fontSizeData.Unit() != DimensionUnit::PERCENT) {
108         fontSize = fontSizeData.ToString();
109     }
110     std::string fontWeight = "regular";
111     if (fontWeightArg->IsString(vm) || fontWeightArg->IsNumber()) {
112         fontWeight = fontWeightArg->ToString(vm)->ToString(vm);
113     }
114 
115     std::string fontInfo = StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), fontWeight.c_str());
116     textStyleStruct.fontInfo = fontInfo.c_str();
117     textStyleStruct.textColor = textColor.GetValue();
118     textStyleStruct.fontSizeRawPtr = AceType::RawPtr(fontSizeResObj);
119     textStyleStruct.textColorRawPtr = AceType::RawPtr(textColorResObj);
120     GetArkUINodeModifiers()->getCalendarPickerModifier()->setTextStyleWithResObj(nativeNode, &textStyleStruct);
121     return panda::JSValueRef::Undefined(vm);
122 }
123 
ResetTextStyle(ArkUIRuntimeCallInfo * runtimeCallInfo)124 ArkUINativeModuleValue CalendarPickerBridge::ResetTextStyle(ArkUIRuntimeCallInfo* runtimeCallInfo)
125 {
126     EcmaVM* vm = runtimeCallInfo->GetVM();
127     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
128     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
129     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
130     GetArkUINodeModifiers()->getCalendarPickerModifier()->resetTextStyle(nativeNode);
131     return panda::JSValueRef::Undefined(vm);
132 }
133 
SetEdgeAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)134 ArkUINativeModuleValue CalendarPickerBridge::SetEdgeAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
135 {
136     EcmaVM* vm = runtimeCallInfo->GetVM();
137     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
138     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
139     Local<JSValueRef> alignTypeArg = runtimeCallInfo->GetCallArgRef(NUM_1);
140     Local<JSValueRef> dxArg = runtimeCallInfo->GetCallArgRef(NUM_2);
141     Local<JSValueRef> dyArg = runtimeCallInfo->GetCallArgRef(NUM_3);
142     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
143     int alignType = NUM_2;
144     if (!alignTypeArg->IsNull() && !alignTypeArg->IsUndefined() && alignTypeArg->IsNumber()) {
145         alignType = alignTypeArg->ToNumber(vm)->Value();
146     }
147     CalcDimension dx;
148     CalcDimension dy;
149     RefPtr<ResourceObject> dxResObj;
150     RefPtr<ResourceObject> dyResObj;
151     if (!dxArg->IsNull() && !dxArg->IsUndefined()) {
152         ArkTSUtils::ParseJsDimensionVp(vm, dxArg, dx, dxResObj);
153     }
154     if (!dyArg->IsNull() && !dyArg->IsUndefined()) {
155         ArkTSUtils::ParseJsDimensionVp(vm, dyArg, dy, dyResObj);
156     }
157 
158     ArkUIPickerEdgeAlignStruct edgeAlignStruct;
159     edgeAlignStruct.dxValue = dx.Value();
160     edgeAlignStruct.dxUnit = static_cast<int>(dx.Unit());
161     edgeAlignStruct.dyValue = dy.Value();
162     edgeAlignStruct.dyUnit = static_cast<int>(dy.Unit());
163     edgeAlignStruct.dxRawPtr = AceType::RawPtr(dxResObj);
164     edgeAlignStruct.dyRawPtr = AceType::RawPtr(dyResObj);
165     edgeAlignStruct.alignType = alignType;
166     GetArkUINodeModifiers()->getCalendarPickerModifier()->setEdgeAlignWithResObj(nativeNode, &edgeAlignStruct);
167     return panda::JSValueRef::Undefined(vm);
168 }
169 
ResetEdgeAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)170 ArkUINativeModuleValue CalendarPickerBridge::ResetEdgeAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
171 {
172     EcmaVM* vm = runtimeCallInfo->GetVM();
173     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
174     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
175     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
176     GetArkUINodeModifiers()->getCalendarPickerModifier()->resetEdgeAlign(nativeNode);
177     return panda::JSValueRef::Undefined(vm);
178 }
179 
SetCalendarPickerPadding(ArkUIRuntimeCallInfo * runtimeCallInfo)180 ArkUINativeModuleValue CalendarPickerBridge::SetCalendarPickerPadding(ArkUIRuntimeCallInfo* runtimeCallInfo)
181 {
182     EcmaVM* vm = runtimeCallInfo->GetVM();
183     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
184     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
185     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
186     Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(1);    // 1: index of parameter top
187     Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(2);  // 2: index of parameter right
188     Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(3); // 3: index of parameter bottom
189     Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(4);   // 4: index of parameter left
190     if (leftArg->IsUndefined() && rightArg->IsUndefined() && topArg->IsUndefined() && bottomArg->IsUndefined()) {
191         GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerPadding(nativeNode);
192         return panda::JSValueRef::Undefined(vm);
193     }
194 
195     struct ArkUISizeType top = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
196     struct ArkUISizeType right = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
197     struct ArkUISizeType bottom = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
198     struct ArkUISizeType left = { 0.0, static_cast<int8_t>(DimensionUnit::VP), nullptr };
199 
200     CalcDimension topDim(0, DimensionUnit::VP);
201     CalcDimension rightDim(0, DimensionUnit::VP);
202     CalcDimension bottomDim(0, DimensionUnit::VP);
203     CalcDimension leftDim(0, DimensionUnit::VP);
204     ParseCalendarPickerPadding(vm, topArg, topDim, top);
205     ParseCalendarPickerPadding(vm, rightArg, rightDim, right);
206     ParseCalendarPickerPadding(vm, bottomArg, bottomDim, bottom);
207     ParseCalendarPickerPadding(vm, leftArg, leftDim, left);
208     GetArkUINodeModifiers()->getCalendarPickerModifier()->setCalendarPickerPadding(
209         nativeNode, &top, &right, &bottom, &left);
210 
211     return panda::JSValueRef::Undefined(vm);
212 }
213 
ResetCalendarPickerPadding(ArkUIRuntimeCallInfo * runtimeCallInfo)214 ArkUINativeModuleValue CalendarPickerBridge::ResetCalendarPickerPadding(ArkUIRuntimeCallInfo* runtimeCallInfo)
215 {
216     EcmaVM* vm = runtimeCallInfo->GetVM();
217     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
218     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
219     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
220     GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerPadding(nativeNode);
221     return panda::JSValueRef::Undefined(vm);
222 }
223 
SetCalendarPickerBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)224 ArkUINativeModuleValue CalendarPickerBridge::SetCalendarPickerBorder(ArkUIRuntimeCallInfo* runtimeCallInfo)
225 {
226     EcmaVM* vm = runtimeCallInfo->GetVM();
227     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
228     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
229     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
230 
231     Local<JSValueRef> leftArg = runtimeCallInfo->GetCallArgRef(5);   // 5: index of parameter left color
232     Local<JSValueRef> rightArg = runtimeCallInfo->GetCallArgRef(6);  // 6: index of parameter right color
233     Local<JSValueRef> topArg = runtimeCallInfo->GetCallArgRef(7);    // 7: index of parameter top color
234     Local<JSValueRef> bottomArg = runtimeCallInfo->GetCallArgRef(8); // 8: index of parameter bottom color
235 
236     CommonBridge::SetBorder(runtimeCallInfo);
237 
238     CalcDimension borderWidth;
239     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
240     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, borderWidth) || !borderWidth.IsValid()) {
241         GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerBorderWidth(nativeNode);
242         return panda::JSValueRef::Undefined(vm);
243     }
244 
245     if (leftArg->IsUndefined() && rightArg->IsUndefined() && topArg->IsUndefined() && bottomArg->IsUndefined()) {
246         auto pipeline = PipelineBase::GetCurrentContext();
247         CHECK_NULL_RETURN(pipeline, panda::NativePointerRef::New(vm, nullptr));
248         RefPtr<CalendarTheme> calendarTheme = pipeline->GetTheme<CalendarTheme>();
249         CHECK_NULL_RETURN(calendarTheme, panda::NativePointerRef::New(vm, nullptr));
250         GetArkUINodeModifiers()->getCalendarPickerModifier()->setCalendarPickerBorder(
251             nativeNode, calendarTheme->GetEntryBorderColor().GetValue());
252     }
253     return panda::JSValueRef::Undefined(vm);
254 }
255 
ResetCalendarPickerBorder(ArkUIRuntimeCallInfo * runtimeCallInfo)256 ArkUINativeModuleValue CalendarPickerBridge::ResetCalendarPickerBorder(ArkUIRuntimeCallInfo* runtimeCallInfo)
257 {
258     EcmaVM* vm = runtimeCallInfo->GetVM();
259     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
260     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
261     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
262     GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerBorder(nativeNode);
263     return panda::JSValueRef::Undefined(vm);
264 }
265 
SetCalendarPickerHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)266 ArkUINativeModuleValue CalendarPickerBridge::SetCalendarPickerHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
267 {
268     EcmaVM* vm = runtimeCallInfo->GetVM();
269     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
270     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
271     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
272     Local<JSValueRef> jsValue = runtimeCallInfo->GetCallArgRef(NUM_1);
273     CalcDimension height;
274     std::string calcStr;
275     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, jsValue, height)) {
276         GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerHeight(nativeNode);
277         if (jsValue->IsObject(vm)) {
278             auto obj = jsValue->ToObject(vm);
279             auto layoutPolicy = obj->Get(vm, panda::StringRef::NewFromUtf8(vm, "id_"));
280             if (layoutPolicy->IsString(vm)) {
281                 auto policy = ParseLayoutPolicy(layoutPolicy->ToString(vm)->ToString(vm));
282                 ViewAbstractModel::GetInstance()->UpdateLayoutPolicyProperty(policy, false);
283                 return panda::JSValueRef::Undefined(vm);
284             }
285         }
286     } else {
287         if (LessNotEqual(height.Value(), 0.0)) {
288             if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
289                 GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerHeight(nativeNode);
290                 ViewAbstractModel::GetInstance()->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false);
291                 return panda::JSValueRef::Undefined(vm);
292             }
293             height.SetValue(0.0);
294         }
295         if (height.Unit() == DimensionUnit::CALC) {
296             GetArkUINodeModifiers()->getCalendarPickerModifier()->setCalendarPickerHeight(
297                 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
298         } else {
299             GetArkUINodeModifiers()->getCalendarPickerModifier()->setCalendarPickerHeight(
300                 nativeNode, height.Value(), static_cast<int32_t>(height.Unit()));
301         }
302     }
303     ViewAbstractModel::GetInstance()->UpdateLayoutPolicyProperty(LayoutCalPolicy::NO_MATCH, false);
304     return panda::JSValueRef::Undefined(vm);
305 }
306 
ResetCalendarPickerHeight(ArkUIRuntimeCallInfo * runtimeCallInfo)307 ArkUINativeModuleValue CalendarPickerBridge::ResetCalendarPickerHeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
308 {
309     EcmaVM* vm = runtimeCallInfo->GetVM();
310     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
311     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
312     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
313     GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerHeight(nativeNode);
314     return panda::JSValueRef::Undefined(vm);
315 }
316 
SetCalendarPickerBorderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)317 ArkUINativeModuleValue CalendarPickerBridge::SetCalendarPickerBorderColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
318 {
319     EcmaVM* vm = runtimeCallInfo->GetVM();
320     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
321     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
322     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
323     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
324     Color color;
325     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
326         GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerBorderColor(nativeNode);
327     } else {
328         GetArkUINodeModifiers()->getCalendarPickerModifier()->setCalendarPickerBorderColor(
329             nativeNode, color.GetValue());
330     }
331     return panda::JSValueRef::Undefined(vm);
332 }
333 
ResetCalendarPickerBorderColor(ArkUIRuntimeCallInfo * runtimeCallInfo)334 ArkUINativeModuleValue CalendarPickerBridge::ResetCalendarPickerBorderColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
335 {
336     EcmaVM* vm = runtimeCallInfo->GetVM();
337     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
338     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
339     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
340     GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerBorderColor(nativeNode);
341     return panda::JSValueRef::Undefined(vm);
342 }
343 
SetCalendarPickerBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)344 ArkUINativeModuleValue CalendarPickerBridge::SetCalendarPickerBorderRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
345 {
346     EcmaVM* vm = runtimeCallInfo->GetVM();
347     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
348     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
349     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
350     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
351 
352     CalcDimension borderRadius;
353     if (!ArkTSUtils::ParseJsDimensionVpNG(vm, secondArg, borderRadius, true)) {
354         GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerBorderRadius(nativeNode);
355         return panda::JSValueRef::Undefined(vm);
356     }
357 
358     if (LessNotEqual(borderRadius.Value(), 0.0)) {
359         GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerBorderRadius(nativeNode);
360         return panda::JSValueRef::Undefined(vm);
361     }
362 
363     GetArkUINodeModifiers()->getCalendarPickerModifier()->setCalendarPickerBorderRadius(nativeNode,
364         borderRadius.Value(), static_cast<int>(borderRadius.Unit()));
365     return panda::JSValueRef::Undefined(vm);
366 }
367 
ResetCalendarPickerBorderRadius(ArkUIRuntimeCallInfo * runtimeCallInfo)368 ArkUINativeModuleValue CalendarPickerBridge::ResetCalendarPickerBorderRadius(ArkUIRuntimeCallInfo* runtimeCallInfo)
369 {
370     EcmaVM* vm = runtimeCallInfo->GetVM();
371     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
372     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
373     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
374     GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerBorderRadius(nativeNode);
375     return panda::JSValueRef::Undefined(vm);
376 }
377 
SetCalendarPickerMarkToday(ArkUIRuntimeCallInfo * runtimeCallInfo)378 ArkUINativeModuleValue CalendarPickerBridge::SetCalendarPickerMarkToday(ArkUIRuntimeCallInfo* runtimeCallInfo)
379 {
380     EcmaVM* vm = runtimeCallInfo->GetVM();
381     CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
382     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
383     Local<JSValueRef> markTodayArg = runtimeCallInfo->GetCallArgRef(1); // markToday value
384     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
385     auto nodeModifiers = GetArkUINodeModifiers();
386     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
387     if (!markTodayArg->IsUndefined() && !markTodayArg.IsNull() && markTodayArg->IsBoolean()) {
388         bool isMarkToday = markTodayArg->ToBoolean(vm)->Value();
389         nodeModifiers->getCalendarPickerModifier()->setCalendarPickerMarkToday(nativeNode, isMarkToday);
390     } else {
391         nodeModifiers->getCalendarPickerModifier()->resetCalendarPickerMarkToday(nativeNode);
392     }
393     return panda::JSValueRef::Undefined(vm);
394 }
395 
ResetCalendarPickerMarkToday(ArkUIRuntimeCallInfo * runtimeCallInfo)396 ArkUINativeModuleValue CalendarPickerBridge::ResetCalendarPickerMarkToday(ArkUIRuntimeCallInfo* runtimeCallInfo)
397 {
398     EcmaVM* vm = runtimeCallInfo->GetVM();
399     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
400     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
401     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
402     auto nodeModifiers = GetArkUINodeModifiers();
403     CHECK_NULL_RETURN(nodeModifiers, panda::JSValueRef::Undefined(vm));
404     nodeModifiers->getCalendarPickerModifier()->resetCalendarPickerMarkToday(nativeNode);
405     return panda::JSValueRef::Undefined(vm);
406 }
SetCalendarPickerOnChange(ArkUIRuntimeCallInfo * runtimeCallInfo)407 ArkUINativeModuleValue CalendarPickerBridge::SetCalendarPickerOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
408 {
409     EcmaVM* vm = runtimeCallInfo->GetVM();
410     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
411     uint32_t argsNumber = runtimeCallInfo->GetArgsNumber();
412     if (argsNumber != NUM_2) {
413         return panda::JSValueRef::Undefined(vm);
414     }
415     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
416     Local<JSValueRef> callbackArg = runtimeCallInfo->GetCallArgRef(NUM_1);
417     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
418     auto frameNode = reinterpret_cast<FrameNode*>(nativeNode);
419     CHECK_NULL_RETURN(frameNode, panda::NativePointerRef::New(vm, nullptr));
420     if (callbackArg->IsUndefined() || callbackArg->IsNull() || !callbackArg->IsFunction(vm)) {
421         GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerOnChange(nativeNode);
422         return panda::JSValueRef::Undefined(vm);
423     }
424     panda::Local<panda::FunctionRef> func = callbackArg->ToObject(vm);
425     std::function<void(const std::string&)> callback = [vm, frameNode, func = panda::CopyableGlobal(vm, func)](
426                                                            const std::string& dateStr) {
427         panda::LocalScope pandaScope(vm);
428         panda::TryCatch trycatch(vm);
429         PipelineContext::SetCallBackNode(AceType::WeakClaim(frameNode));
430         panda::Local<panda::DateRef> dateObj = panda::DateRef::New(vm, GetMSByDate(dateStr));
431         panda::Local<panda::JSValueRef> params[] = { dateObj };
432         func->Call(vm, func.ToLocal(), params, PARAM_ARR_LENGTH_1);
433     };
434     GetArkUINodeModifiers()->getCalendarPickerModifier()->setCalendarPickerOnChange(
435         nativeNode, reinterpret_cast<void*>(&callback));
436     return panda::JSValueRef::Undefined(vm);
437 }
ResetCalendarPickerOnChange(ArkUIRuntimeCallInfo * runtimeCallInfo)438 ArkUINativeModuleValue CalendarPickerBridge::ResetCalendarPickerOnChange(ArkUIRuntimeCallInfo* runtimeCallInfo)
439 {
440     EcmaVM* vm = runtimeCallInfo->GetVM();
441     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
442     Local<JSValueRef> nativeNodeArg = runtimeCallInfo->GetCallArgRef(NUM_0);
443     auto nativeNode = nodePtr(nativeNodeArg->ToNativePointer(vm)->Value());
444     GetArkUINodeModifiers()->getCalendarPickerModifier()->resetCalendarPickerOnChange(nativeNode);
445     return panda::JSValueRef::Undefined(vm);
446 }
447 } // namespace OHOS::Ace::NG
448