• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "frameworks/bridge/declarative_frontend/jsview/js_calendar.h"
17 
18 #include <cstdint>
19 #include <optional>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/log/ace_scoring_log.h"
23 #include "base/memory/ace_type.h"
24 #include "base/utils/utils.h"
25 #include "bridge/declarative_frontend/engine/js_ref_ptr.h"
26 #include "core/common/ace_application_info.h"
27 #include "core/common/container.h"
28 #include "core/components/common/properties/color.h"
29 #include "core/components_ng/base/view_stack_processor.h"
30 #include "core/components_ng/pattern/calendar/calendar_controller_ng.h"
31 #include "core/components_ng/pattern/calendar/calendar_month_view.h"
32 #include "core/components_ng/pattern/calendar/calendar_paint_property.h"
33 #include "core/components_ng/pattern/calendar/calendar_view.h"
34 #include "frameworks/bridge/declarative_frontend/jsview/js_calendar_controller.h"
35 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
36 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
37 
38 namespace OHOS::Ace::Framework {
39 namespace {
40 
41 constexpr int32_t CALENDAR_INVALID = -1;
42 
43 } // namespace
44 
JSBind(BindingTarget globalObj)45 void JSCalendar::JSBind(BindingTarget globalObj)
46 {
47     JSClass<JSCalendar>::Declare("Calendar");
48     MethodOptions opt = MethodOptions::NONE;
49     JSClass<JSCalendar>::StaticMethod("create", &JSCalendar::Create, opt);
50     JSClass<JSCalendar>::StaticMethod("showLunar", &JSCalendar::SetShowLunar, opt);
51     JSClass<JSCalendar>::StaticMethod("showHoliday", &JSCalendar::SetShowHoliday, opt);
52     JSClass<JSCalendar>::StaticMethod("needSlide", &JSCalendar::SetNeedSlide, opt);
53     JSClass<JSCalendar>::StaticMethod("startOfWeek", &JSCalendar::SetStartOfWeek, opt);
54     JSClass<JSCalendar>::StaticMethod("offDays", &JSCalendar::SetOffDays, opt);
55     JSClass<JSCalendar>::StaticMethod("onSelectChange", &JSCalendar::JsOnSelectedChange, opt);
56     JSClass<JSCalendar>::StaticMethod("onRequestData", &JSCalendar::JsOnRequestData, opt);
57     JSClass<JSCalendar>::StaticMethod("direction", &JSCalendar::SetDirection, opt);
58     JSClass<JSCalendar>::StaticMethod("currentDayStyle", &JSCalendar::SetCurrentDayStyle, opt);
59     JSClass<JSCalendar>::StaticMethod("nonCurrentDayStyle", &JSCalendar::SetNonCurrentDayStyle, opt);
60     JSClass<JSCalendar>::StaticMethod("todayStyle", &JSCalendar::SetTodayStyle, opt);
61     JSClass<JSCalendar>::StaticMethod("weekStyle", &JSCalendar::SetWeekStyle, opt);
62     JSClass<JSCalendar>::StaticMethod("workStateStyle", &JSCalendar::SetWorkStateStyle, opt);
63     JSClass<JSCalendar>::Inherit<JSViewAbstract>();
64     JSClass<JSCalendar>::Bind<>(globalObj);
65 }
66 
Create(const JSCallbackInfo & info)67 void JSCalendar::Create(const JSCallbackInfo& info)
68 {
69     if (info.Length() != 1 || !info[0]->IsObject()) {
70         return;
71     }
72     auto obj = JSRef<JSObject>::Cast(info[0]);
73     auto date = JSRef<JSObject>::Cast(obj->GetProperty("date"));
74     auto currentData = JSRef<JSObject>::Cast(obj->GetProperty("currentData"));
75     auto preData = JSRef<JSObject>::Cast(obj->GetProperty("preData"));
76     auto nextData = JSRef<JSObject>::Cast(obj->GetProperty("nextData"));
77     auto controllerObj = obj->GetProperty("controller");
78     if (Container::IsCurrentUseNewPipeline()) {
79         auto yearValue = date->GetProperty("year");
80         auto monthValue = date->GetProperty("month");
81         auto dayValue = date->GetProperty("day");
82         if (!yearValue->IsNumber() || !monthValue->IsNumber() || !dayValue->IsNumber()) {
83             return;
84         }
85         CalendarDay day;
86         day.month.year = yearValue->ToNumber<int32_t>();
87         day.month.month = monthValue->ToNumber<int32_t>();
88         day.day = dayValue->ToNumber<int32_t>();
89         NG::CalendarData calendarData;
90         calendarData.date = day;
91         ObtainedMonth currentMonthData = GetCurrentData(currentData);
92         ObtainedMonth preMonthData = GetPreData(preData);
93         ObtainedMonth nextMonthData = GetNextData(nextData);
94         calendarData.currentData = currentMonthData;
95         calendarData.preData = preMonthData;
96         calendarData.nextData = nextMonthData;
97         if (controllerObj->IsObject()) {
98             auto jsCalendarController = JSRef<JSObject>::Cast(controllerObj).Unwrap<JSCalendarController>();
99             if (jsCalendarController) {
100                 auto controller = jsCalendarController->GetControllerNg();
101                 calendarData.controller = controller;
102             }
103         }
104         NG::CalendarView::Create(calendarData);
105         return;
106     }
107 
108     auto calendarComponent = AceType::MakeRefPtr<OHOS::Ace::CalendarComponentV2>("", "calendar");
109     SetDate(date, calendarComponent);
110     SetCurrentData(currentData, calendarComponent);
111     SetPreData(preData, calendarComponent);
112     SetNextData(nextData, calendarComponent);
113     if (controllerObj->IsObject()) {
114         auto jsCalendarController = JSRef<JSObject>::Cast(controllerObj)->Unwrap<JSCalendarController>();
115         if (jsCalendarController) {
116             auto controllerV2 = jsCalendarController->GetController();
117             calendarComponent->SetControllerV2(controllerV2);
118         }
119     }
120     auto theme = GetTheme<CalendarTheme>();
121     calendarComponent->SetCalendarTheme(theme);
122     calendarComponent->SetV2Component(true);
123     ViewStackProcessor::GetInstance()->Push(calendarComponent);
124 }
125 
SetCalendarData(const JSRef<JSObject> & obj,MonthState monthState,const RefPtr<CalendarComponentV2> & component)126 void JSCalendar::SetCalendarData(
127     const JSRef<JSObject>& obj, MonthState monthState, const RefPtr<CalendarComponentV2>& component)
128 {
129     CHECK_NULL_VOID(component);
130 
131 #if defined(PREVIEW)
132     if (obj->IsUndefined()) {
133         LOGE("obj is undefined");
134         return;
135     }
136 #endif
137 
138     auto yearValue = obj->GetProperty("year");
139     auto monthValue = obj->GetProperty("month");
140     auto arrayValue = obj->GetProperty("data");
141     auto data = JsonUtil::ParseJsonString(arrayValue->ToString());
142     if (!yearValue->IsNumber() || !monthValue->IsNumber() || !data->IsArray()) {
143         return;
144     }
145     ObtainedMonth obtainedMonth;
146     obtainedMonth.year = yearValue->ToNumber<int32_t>();
147     obtainedMonth.month = monthValue->ToNumber<int32_t>();
148     std::vector<CalendarDay> days;
149     auto child = data->GetChild();
150     while (child && child->IsValid()) {
151         CalendarDay day;
152         day.index = child->GetInt("index");
153         day.lunarMonth = child->GetString("lunarMonth");
154         day.lunarDay = child->GetString("lunarDay");
155         day.dayMark = child->GetString("dayMark");
156         day.dayMarkValue = child->GetString("dayMarkValue");
157         day.month.year = child->GetInt("year");
158         day.month.month = child->GetInt("month");
159         day.day = child->GetInt("day");
160         if (day.day == 1 && obtainedMonth.firstDayIndex == CALENDAR_INVALID) {
161             obtainedMonth.firstDayIndex = day.index;
162         }
163         day.isFirstOfLunar = child->GetBool("isFirstOfLunar");
164         day.hasSchedule = child->GetBool("hasSchedule");
165         day.markLunarDay = child->GetBool("markLunarDay");
166         days.emplace_back(std::move(day));
167         child = child->GetNext();
168     }
169     obtainedMonth.days = days;
170     component->SetCalendarData(obtainedMonth);
171 }
172 
GetCalendarData(const JSRef<JSObject> & obj,MonthState monthState)173 ObtainedMonth JSCalendar::GetCalendarData(const JSRef<JSObject>& obj, MonthState monthState)
174 {
175 #if defined(PREVIEW)
176     if (obj->IsUndefined()) {
177         LOGE("obj is undefined");
178         return ObtainedMonth();
179     }
180 #endif
181 
182     auto yearValue = obj->GetProperty("year");
183     auto monthValue = obj->GetProperty("month");
184     auto arrayValue = obj->GetProperty("data");
185     auto data = JsonUtil::ParseJsonString(arrayValue->ToString());
186     if (!yearValue->IsNumber() || !monthValue->IsNumber() || !data->IsArray()) {
187         return ObtainedMonth();
188     }
189     ObtainedMonth obtainedMonth;
190     obtainedMonth.year = yearValue->ToNumber<int32_t>();
191     obtainedMonth.month = monthValue->ToNumber<int32_t>();
192     std::vector<CalendarDay> days;
193     auto child = data->GetChild();
194     while (child && child->IsValid()) {
195         CalendarDay day;
196         day.index = child->GetInt("index");
197         day.lunarMonth = child->GetString("lunarMonth");
198         day.lunarDay = child->GetString("lunarDay");
199         day.dayMark = child->GetString("dayMark");
200         day.dayMarkValue = child->GetString("dayMarkValue");
201         day.month.year = child->GetInt("year");
202         day.month.month = child->GetInt("month");
203         day.day = child->GetInt("day");
204         if (day.day == 1 && obtainedMonth.firstDayIndex == CALENDAR_INVALID) {
205             obtainedMonth.firstDayIndex = day.index;
206         }
207         day.isFirstOfLunar = child->GetBool("isFirstOfLunar");
208         day.hasSchedule = child->GetBool("hasSchedule");
209         day.markLunarDay = child->GetBool("markLunarDay");
210         days.emplace_back(std::move(day));
211         child = child->GetNext();
212     }
213     obtainedMonth.days = days;
214     return obtainedMonth;
215 }
216 
SetCardCalendar(bool cardCalendar)217 void JSCalendar::SetCardCalendar(bool cardCalendar)
218 {
219     auto component = GetComponent();
220     CHECK_NULL_VOID(component);
221 
222     component->SetCardCalendar(cardCalendar);
223 }
224 
SetDate(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)225 void JSCalendar::SetDate(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
226 {
227     if (component) {
228         auto yearValue = obj->GetProperty("year");
229         auto monthValue = obj->GetProperty("month");
230         auto dayValue = obj->GetProperty("day");
231         if (!yearValue->IsNumber() || !monthValue->IsNumber() || !dayValue->IsNumber()) {
232             return;
233         }
234         CalendarDay day;
235         day.month.year = yearValue->ToNumber<int32_t>();
236         day.month.month = monthValue->ToNumber<int32_t>();
237         day.day = dayValue->ToNumber<int32_t>();
238         component->SetCalendarDate(day);
239     }
240 }
241 
SetHolidays(const std::string & holidays)242 void JSCalendar::SetHolidays(const std::string& holidays)
243 {
244     auto component = GetComponent();
245     CHECK_NULL_VOID(component);
246 
247     component->SetHolidays(holidays);
248 }
249 
SetOffDays(int32_t offDays)250 void JSCalendar::SetOffDays(int32_t offDays)
251 {
252     uint32_t bit = 0b1;
253     std::string result;
254     const static int32_t dayOfWeek = 7;
255     for (auto i = 0; i < dayOfWeek; ++i) {
256         if (bit & static_cast<uint32_t>(offDays)) {
257             result += std::to_string(i);
258             result += ",";
259         }
260         bit <<= 1;
261     }
262     if (Container::IsCurrentUseNewPipeline()) {
263         NG::CalendarView::SetOffDays(result);
264         return;
265     }
266     auto component = GetComponent();
267     CHECK_NULL_VOID(component);
268 
269     component->SetOffDays(result);
270 }
271 
SetShowHoliday(const JSCallbackInfo & info)272 void JSCalendar::SetShowHoliday(const JSCallbackInfo& info)
273 {
274     bool showHoliday = true;
275     if (info.Length() < 1) {
276         LOGE("The info is wrong, it is supposed to have atleast 1 arguments");
277         return;
278     }
279     if (info[0]->IsBoolean()) {
280         showHoliday = info[0]->ToBoolean();
281     }
282     if (Container::IsCurrentUseNewPipeline()) {
283         NG::CalendarView::SetShowHoliday(showHoliday);
284         return;
285     }
286     auto component = GetComponent();
287     CHECK_NULL_VOID(component);
288     component->SetShowHoliday(showHoliday);
289 }
290 
SetShowLunar(const JSCallbackInfo & info)291 void JSCalendar::SetShowLunar(const JSCallbackInfo& info)
292 {
293     bool showLunar = false;
294     if (info.Length() < 1) {
295         LOGE("The info is wrong, it is supposed to have atleast 1 arguments");
296         return;
297     }
298     if (info[0]->IsBoolean()) {
299         showLunar = info[0]->ToBoolean();
300     }
301     if (Container::IsCurrentUseNewPipeline()) {
302         NG::CalendarView::SetShowLunar(showLunar);
303         return;
304     }
305     auto component = GetComponent();
306     CHECK_NULL_VOID(component);
307 
308     component->SetShowLunar(showLunar);
309 }
310 
SetStartOfWeek(const JSCallbackInfo & info)311 void JSCalendar::SetStartOfWeek(const JSCallbackInfo& info)
312 {
313     if (info.Length() < 1) {
314         LOGE("The info is wrong, it is supposed to have atleast 1 arguments");
315         return;
316     }
317     if (info[0]->IsNumber()) {
318         auto startOfWeek = info[0]->ToNumber<int32_t>();
319         if (Container::IsCurrentUseNewPipeline()) {
320             NG::CalendarView::SetStartOfWeek(NG::Week(startOfWeek));
321             return;
322         }
323         auto component = GetComponent();
324         CHECK_NULL_VOID(component);
325 
326         if (0 <= startOfWeek && startOfWeek < 7) {
327             component->SetStartDayOfWeek(startOfWeek);
328         }
329     }
330 }
331 
SetNeedSlide(const JSCallbackInfo & info)332 void JSCalendar::SetNeedSlide(const JSCallbackInfo& info)
333 {
334     bool needSlide = false;
335     if (info.Length() < 1) {
336         LOGE("The info is wrong, it is supposed to have atleast 1 arguments");
337         return;
338     }
339     if (info[0]->IsBoolean()) {
340         needSlide = info[0]->ToBoolean();
341     }
342     if (Container::IsCurrentUseNewPipeline()) {
343         NG::CalendarView::SetNeedSlide(needSlide);
344         return;
345     }
346     auto component = GetComponent();
347     CHECK_NULL_VOID(component);
348     component->SetNeedSlide(needSlide);
349 }
350 
SetWorkDays(const std::string & workDays)351 void JSCalendar::SetWorkDays(const std::string& workDays)
352 {
353     auto component = GetComponent();
354     CHECK_NULL_VOID(component);
355 
356     component->SetWorkDays(workDays);
357 }
358 
GetComponent()359 RefPtr<CalendarComponentV2> JSCalendar::GetComponent()
360 {
361     auto stack = ViewStackProcessor::GetInstance();
362     if (!stack) {
363         return nullptr;
364     }
365     auto component = AceType::DynamicCast<CalendarComponentV2>(stack->GetMainComponent());
366     if (AceApplicationInfo::GetInstance().IsRightToLeft()) {
367         component->SetTextDirection(TextDirection::RTL);
368     }
369     return component;
370 }
371 
JsOnSelectedChange(const JSCallbackInfo & info)372 void JSCalendar::JsOnSelectedChange(const JSCallbackInfo& info)
373 {
374     if (Container::IsCurrentUseNewPipeline()) {
375         auto selectedChangeFuc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
376         auto selectedChange = [execCtx = info.GetExecutionContext(), func = std::move(selectedChangeFuc)](
377                                   const std::string& info) {
378             JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
379             std::vector<std::string> keys = { "year", "month", "day" };
380             ACE_SCORING_EVENT("Calendar.onSelectedChange");
381             func->Execute(keys, info);
382         };
383         NG::CalendarView::SetSelectedChangeEvent(selectedChange);
384         return;
385     }
386     auto component = GetComponent();
387     if (info[0]->IsFunction() && component) {
388         auto selectedChangeFuc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
389         EventMarker onSelectedChangeId(
390             [execCtx = info.GetExecutionContext(), func = std::move(selectedChangeFuc)](const std::string& info) {
391                 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
392                 std::vector<std::string> keys = { "year", "month", "day" };
393                 ACE_SCORING_EVENT("Calendar.onSelectedChange");
394                 func->Execute(keys, info);
395             });
396         component->SetSelectedChangeEvent(onSelectedChangeId);
397     }
398 }
399 
JsOnRequestData(const JSCallbackInfo & info)400 void JSCalendar::JsOnRequestData(const JSCallbackInfo& info)
401 {
402     if (Container::IsCurrentUseNewPipeline()) {
403         auto requestDataFuc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
404         auto requestData = [execCtx = info.GetExecutionContext(), func = std::move(requestDataFuc)](
405                                const std::string& info) {
406             JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
407             ACE_SCORING_EVENT("Calendar.onRequestData");
408             std::vector<std::string> keys = { "year", "month", "currentMonth", "currentYear", "monthState" };
409             func->Execute(keys, info);
410         };
411         NG::CalendarView::SetOnRequestDataEvent(std::move(requestData));
412         return;
413     }
414     auto component = GetComponent();
415     if (info[0]->IsFunction() && component) {
416         auto requestDataFuc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
417         EventMarker onRequestDataId(
418             [execCtx = info.GetExecutionContext(), func = std::move(requestDataFuc)](const std::string& info) {
419                 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
420                 std::vector<std::string> keys = { "year", "month", "currentMonth", "currentYear", "monthState" };
421                 ACE_SCORING_EVENT("Calendar.onRequestData");
422                 func->Execute(keys, info);
423             });
424         component->SetRequestDataEvent(onRequestDataId);
425     }
426 }
427 
SetCurrentData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)428 void JSCalendar::SetCurrentData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
429 {
430     SetCalendarData(obj, MonthState::CUR_MONTH, component);
431 }
432 
GetCurrentData(const JSRef<JSObject> & obj)433 ObtainedMonth JSCalendar::GetCurrentData(const JSRef<JSObject>& obj)
434 {
435     return GetCalendarData(obj, MonthState::CUR_MONTH);
436 }
437 
SetPreData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)438 void JSCalendar::SetPreData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
439 {
440     SetCalendarData(obj, MonthState::PRE_MONTH, component);
441 }
442 
GetPreData(const JSRef<JSObject> & obj)443 ObtainedMonth JSCalendar::GetPreData(const JSRef<JSObject>& obj)
444 {
445     return GetCalendarData(obj, MonthState::PRE_MONTH);
446 }
447 
SetNextData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)448 void JSCalendar::SetNextData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
449 {
450     SetCalendarData(obj, MonthState::NEXT_MONTH, component);
451 }
452 
GetNextData(const JSRef<JSObject> & obj)453 ObtainedMonth JSCalendar::GetNextData(const JSRef<JSObject>& obj)
454 {
455     return GetCalendarData(obj, MonthState::NEXT_MONTH);
456 }
457 
SetDirection(const JSCallbackInfo & info)458 void JSCalendar::SetDirection(const JSCallbackInfo& info)
459 {
460     if (info.Length() < 1) {
461         LOGE("The info is wrong, it is supposed to have atleast 1 arguments");
462         return;
463     }
464     if (info[0]->IsNumber()) {
465         auto dir = info[0]->ToNumber<int32_t>();
466         if (Container::IsCurrentUseNewPipeline()) {
467             NG::CalendarView::SetDirection(Axis(dir));
468             return;
469         }
470         auto component = GetComponent();
471         CHECK_NULL_VOID(component);
472         if (dir == 0) {
473             component->SetAxis(Axis::VERTICAL);
474         } else if (dir == 1) {
475             component->SetAxis(Axis::HORIZONTAL);
476         }
477     }
478 }
479 
SetCurrentDayStyle(const JSCallbackInfo & info)480 void JSCalendar::SetCurrentDayStyle(const JSCallbackInfo& info)
481 {
482     auto obj = JSRef<JSObject>::Cast(info[0]);
483 
484     if (info.Length() < 1 || !info[0]->IsObject()) {
485         LOGW("Invalid params");
486         return;
487     }
488     if (Container::IsCurrentUseNewPipeline()) {
489         NG::CurrentDayStyle currentDayStyle;
490         Color dayColor;
491         if (ConvertFromJSValue(obj->GetProperty("dayColor"), dayColor)) {
492             currentDayStyle.UpdateDayColor(dayColor);
493         }
494         Color lunarColor;
495         if (ConvertFromJSValue(obj->GetProperty("lunarColor"), lunarColor)) {
496             currentDayStyle.UpdateLunarColor(lunarColor);
497         }
498         Color markLunarColor;
499         if (ConvertFromJSValue(obj->GetProperty("markLunarColor"), markLunarColor)) {
500             currentDayStyle.UpdateMarkLunarColor(markLunarColor);
501         }
502         Dimension dayFontSize;
503         if (ParseJsDimensionFp(obj->GetProperty("dayFontSize"), dayFontSize)) {
504             currentDayStyle.UpdateDayFontSize(dayFontSize);
505         }
506         Dimension lunarDayFontSize;
507         if (ParseJsDimensionFp(obj->GetProperty("lunarDayFontSize"), lunarDayFontSize)) {
508             currentDayStyle.UpdateLunarDayFontSize(lunarDayFontSize);
509         }
510         Dimension dayHeight;
511         if (ParseJsDimensionFp(obj->GetProperty("dayHeight"), dayHeight)) {
512             currentDayStyle.UpdateDayHeight(dayHeight);
513         }
514         Dimension dayWidth;
515         if (ParseJsDimensionFp(obj->GetProperty("dayWidth"), dayWidth)) {
516             currentDayStyle.UpdateDayWidth(dayWidth);
517         }
518         Dimension gregorianCalendarHeight;
519         if (ParseJsDimensionFp(obj->GetProperty("gregorianCalendarHeight"), gregorianCalendarHeight)) {
520             currentDayStyle.UpdateGregorianCalendarHeight(gregorianCalendarHeight);
521         }
522         Dimension lunarHeight;
523         if (ParseJsDimensionFp(obj->GetProperty("lunarHeight"), lunarHeight)) {
524             currentDayStyle.UpdateLunarHeight(lunarHeight);
525         }
526         Dimension dayYAxisOffset;
527         if (ParseJsDimensionFp(obj->GetProperty("dayYAxisOffset"), dayYAxisOffset)) {
528             currentDayStyle.UpdateDayYAxisOffset(dayYAxisOffset);
529         }
530         Dimension lunarDayYAxisOffset;
531         if (ParseJsDimensionFp(obj->GetProperty("lunarDayYAxisOffset"), lunarDayYAxisOffset)) {
532             currentDayStyle.UpdateLunarDayYAxisOffset(lunarDayYAxisOffset);
533         }
534         Dimension underscoreXAxisOffset;
535         if (ParseJsDimensionFp(obj->GetProperty("underscoreXAxisOffset"), underscoreXAxisOffset)) {
536             currentDayStyle.UpdateUnderscoreXAxisOffset(underscoreXAxisOffset);
537         }
538         Dimension underscoreYAxisOffset;
539         if (ParseJsDimensionFp(obj->GetProperty("underscoreYAxisOffset"), underscoreYAxisOffset)) {
540             currentDayStyle.UpdateUnderscoreYAxisOffset(underscoreYAxisOffset);
541         }
542         Dimension scheduleMarkerXAxisOffset;
543         if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerXAxisOffset"), scheduleMarkerXAxisOffset)) {
544             currentDayStyle.UpdateScheduleMarkerXAxisOffset(scheduleMarkerXAxisOffset);
545         }
546         Dimension scheduleMarkerYAxisOffset;
547         if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerYAxisOffset"), scheduleMarkerYAxisOffset)) {
548             currentDayStyle.UpdateScheduleMarkerYAxisOffset(scheduleMarkerYAxisOffset);
549         }
550         Dimension colSpace;
551         if (ParseJsDimensionFp(obj->GetProperty("colSpace"), colSpace)) {
552             currentDayStyle.UpdateColSpace(colSpace);
553         }
554         Dimension dailyFiveRowSpace;
555         if (ParseJsDimensionFp(obj->GetProperty("dailyFiveRowSpace"), dailyFiveRowSpace)) {
556             currentDayStyle.UpdateDailyFiveRowSpace(dailyFiveRowSpace);
557         }
558         Dimension dailySixRowSpace;
559         if (ParseJsDimensionFp(obj->GetProperty("dailySixRowSpace"), dailySixRowSpace)) {
560             currentDayStyle.UpdateDailySixRowSpace(dailySixRowSpace);
561         }
562         Dimension underscoreWidth;
563         if (ParseJsDimensionFp(obj->GetProperty("underscoreWidth"), underscoreWidth)) {
564             currentDayStyle.UpdateUnderscoreWidth(underscoreWidth);
565         }
566         Dimension underscoreLength;
567         if (ParseJsDimensionFp(obj->GetProperty("underscoreLength"), underscoreLength)) {
568             currentDayStyle.UpdateUnderscoreLength(underscoreLength);
569         }
570         Dimension scheduleMarkerRadius;
571         if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerRadius"), scheduleMarkerRadius)) {
572             currentDayStyle.UpdateScheduleMarkerRadius(scheduleMarkerRadius);
573         }
574         Dimension boundaryRowOffset;
575         if (ParseJsDimensionFp(obj->GetProperty("boundaryRowOffset"), boundaryRowOffset)) {
576             currentDayStyle.UpdateBoundaryRowOffset(boundaryRowOffset);
577         }
578         Dimension boundaryColOffset;
579         if (ParseJsDimensionFp(obj->GetProperty("boundaryColOffset"), boundaryColOffset)) {
580             currentDayStyle.UpdateBoundaryColOffset(boundaryColOffset);
581         }
582         NG::CalendarView::SetCurrentDayStyle(currentDayStyle);
583         return;
584     }
585     auto component = GetComponent();
586     CHECK_NULL_VOID(component);
587 
588     auto& themePtr = component->GetCalendarTheme();
589     CHECK_NULL_VOID(themePtr);
590     auto& theme = themePtr->GetCalendarTheme();
591     ConvertFromJSValue(obj->GetProperty("dayColor"), theme.dayColor);
592     ConvertFromJSValue(obj->GetProperty("lunarColor"), theme.lunarColor);
593     ConvertFromJSValue(obj->GetProperty("markLunarColor"), theme.markLunarColor);
594     Dimension dayFontSize;
595     if (ParseJsDimensionFp(obj->GetProperty("dayFontSize"), dayFontSize)) {
596         theme.dayFontSize = dayFontSize;
597     }
598     Dimension lunarDayFontSize;
599     if (ParseJsDimensionFp(obj->GetProperty("lunarDayFontSize"), lunarDayFontSize)) {
600         theme.lunarDayFontSize = lunarDayFontSize;
601     }
602     ConvertFromJSValue(obj->GetProperty("dayHeight"), theme.dayHeight);
603     ConvertFromJSValue(obj->GetProperty("dayWidth"), theme.dayWidth);
604     ConvertFromJSValue(obj->GetProperty("gregorianCalendarHeight"), theme.gregorianCalendarHeight);
605     ConvertFromJSValue(obj->GetProperty("lunarHeight"), theme.lunarHeight);
606     ConvertFromJSValue(obj->GetProperty("dayYAxisOffset"), theme.dayYAxisOffset);
607     ConvertFromJSValue(obj->GetProperty("lunarDayYAxisOffset"), theme.lunarDayYAxisOffset);
608     ConvertFromJSValue(obj->GetProperty("underscoreXAxisOffset"), theme.underscoreXAxisOffset);
609     ConvertFromJSValue(obj->GetProperty("underscoreYAxisOffset"), theme.underscoreYAxisOffset);
610     ConvertFromJSValue(obj->GetProperty("scheduleMarkerXAxisOffset"), theme.scheduleMarkerXAxisOffset);
611     ConvertFromJSValue(obj->GetProperty("scheduleMarkerYAxisOffset"), theme.scheduleMarkerYAxisOffset);
612     ConvertFromJSValue(obj->GetProperty("colSpace"), theme.colSpace);
613     ConvertFromJSValue(obj->GetProperty("dailyFiveRowSpace"), theme.dailyFiveRowSpace);
614     ConvertFromJSValue(obj->GetProperty("dailySixRowSpace"), theme.dailySixRowSpace);
615     ConvertFromJSValue(obj->GetProperty("underscoreWidth"), theme.underscoreWidth);
616     ConvertFromJSValue(obj->GetProperty("underscoreLength"), theme.underscoreLength);
617     ConvertFromJSValue(obj->GetProperty("scheduleMarkerRadius"), theme.scheduleMarkerRadius);
618     ConvertFromJSValue(obj->GetProperty("boundaryRowOffset"), theme.boundaryRowOffset);
619     ConvertFromJSValue(obj->GetProperty("boundaryColOffset"), theme.boundaryColOffset);
620     ConvertFromJSValue(obj->GetProperty("touchCircleStrokeWidth"), theme.touchCircleStrokeWidth);
621 }
622 
SetNonCurrentDayStyle(const JSCallbackInfo & info)623 void JSCalendar::SetNonCurrentDayStyle(const JSCallbackInfo& info)
624 {
625     if (info.Length() < 1 || !info[0]->IsObject()) {
626         LOGW("Invalid params");
627         return;
628     }
629     auto obj = JSRef<JSObject>::Cast(info[0]);
630     if (Container::IsCurrentUseNewPipeline()) {
631         NG::NonCurrentDayStyle nonCurrentDayStyle;
632         Color nonCurrentMonthDayColor;
633         if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthDayColor"), nonCurrentMonthDayColor)) {
634             nonCurrentDayStyle.UpdateNonCurrentMonthDayColor(nonCurrentMonthDayColor);
635         }
636         Color nonCurrentMonthLunarColor;
637         if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthLunarColor"), nonCurrentMonthLunarColor)) {
638             nonCurrentDayStyle.UpdateNonCurrentMonthLunarColor(nonCurrentMonthLunarColor);
639         }
640         Color nonCurrentMonthWorkDayMarkColor;
641         if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthWorkDayMarkColor"), nonCurrentMonthWorkDayMarkColor)) {
642             nonCurrentDayStyle.UpdateNonCurrentMonthWorkDayMarkColor(nonCurrentMonthWorkDayMarkColor);
643         }
644         Color nonCurrentMonthOffDayMarkColor;
645         if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthOffDayMarkColor"), nonCurrentMonthOffDayMarkColor)) {
646             nonCurrentDayStyle.UpdateNonCurrentMonthOffDayMarkColor(nonCurrentMonthOffDayMarkColor);
647         }
648         NG::CalendarView::SetNonCurrentDayStyle(nonCurrentDayStyle);
649         return;
650     }
651 
652     auto component = GetComponent();
653     if (!component) {
654         return;
655     }
656     auto& themePtr = component->GetCalendarTheme();
657     if (!themePtr) {
658         return;
659     }
660     auto& theme = themePtr->GetCalendarTheme();
661     ConvertFromJSValue(obj->GetProperty("nonCurrentMonthDayColor"), theme.nonCurrentMonthDayColor);
662     ConvertFromJSValue(obj->GetProperty("nonCurrentMonthLunarColor"), theme.nonCurrentMonthLunarColor);
663     ConvertFromJSValue(obj->GetProperty("nonCurrentMonthWorkDayMarkColor"), theme.nonCurrentMonthWorkDayMarkColor);
664     ConvertFromJSValue(obj->GetProperty("nonCurrentMonthOffDayMarkColor"), theme.nonCurrentMonthOffDayMarkColor);
665 }
666 
SetTodayStyle(const JSCallbackInfo & info)667 void JSCalendar::SetTodayStyle(const JSCallbackInfo& info)
668 {
669     if (info.Length() < 1 || !info[0]->IsObject()) {
670         LOGW("Invalid params");
671         return;
672     }
673     auto obj = JSRef<JSObject>::Cast(info[0]);
674     if (Container::IsCurrentUseNewPipeline()) {
675         NG::TodayStyle todayStyle;
676         Color focusedDayColor;
677         if (ConvertFromJSValue(obj->GetProperty("focusedDayColor"), focusedDayColor)) {
678             todayStyle.UpdateFocusedDayColor(focusedDayColor);
679         }
680         Color focusedLunarColor;
681         if (ConvertFromJSValue(obj->GetProperty("focusedLunarColor"), focusedLunarColor)) {
682             todayStyle.UpdateFocusedLunarColor(focusedLunarColor);
683         }
684         Color focusedAreaBackgroundColor;
685         if (ConvertFromJSValue(obj->GetProperty("focusedAreaBackgroundColor"), focusedAreaBackgroundColor)) {
686             todayStyle.UpdateFocusedAreaBackgroundColor(focusedAreaBackgroundColor);
687         }
688         Dimension focusedAreaRadius;
689         if (ConvertFromJSValue(obj->GetProperty("focusedAreaRadius"), focusedAreaRadius)) {
690             todayStyle.UpdateFocusedAreaRadius(focusedAreaRadius);
691         }
692         NG::CalendarView::SetTodayStyle(todayStyle);
693         return;
694     }
695     auto component = GetComponent();
696     if (!component) {
697         return;
698     }
699 
700     auto& themePtr = component->GetCalendarTheme();
701     if (!themePtr) {
702         return;
703     }
704     auto& theme = themePtr->GetCalendarTheme();
705     ConvertFromJSValue(obj->GetProperty("focusedDayColor"), theme.focusedDayColor);
706     ConvertFromJSValue(obj->GetProperty("focusedLunarColor"), theme.focusedLunarColor);
707     ConvertFromJSValue(obj->GetProperty("focusedAreaBackgroundColor"), theme.focusedAreaBackgroundColor);
708     ConvertFromJSValue(obj->GetProperty("focusedAreaRadius"), theme.focusedAreaRadius);
709 }
710 
SetWeekStyle(const JSCallbackInfo & info)711 void JSCalendar::SetWeekStyle(const JSCallbackInfo& info)
712 {
713     if (info.Length() < 1 || !info[0]->IsObject()) {
714         LOGW("Invalid params");
715         return;
716     }
717     auto obj = JSRef<JSObject>::Cast(info[0]);
718     if (Container::IsCurrentUseNewPipeline()) {
719         NG::WeekStyle weekStyle;
720         Color weekColor;
721         if (ConvertFromJSValue(obj->GetProperty("weekColor"), weekColor)) {
722             weekStyle.UpdateWeekColor(weekColor);
723         }
724         Color weekendDayColor;
725         if (ConvertFromJSValue(obj->GetProperty("weekendDayColor"), weekendDayColor)) {
726             weekStyle.UpdateWeekendDayColor(weekendDayColor);
727         }
728         Color weekendLunarColor;
729         if (ConvertFromJSValue(obj->GetProperty("weekendLunarColor"), weekendLunarColor)) {
730             weekStyle.UpdateWeekendLunarColor(weekendLunarColor);
731         }
732         Dimension weekFontSize;
733         if (ParseJsDimensionFp(obj->GetProperty("weekFontSize"), weekFontSize)) {
734             weekStyle.UpdateWeekFontSize(weekFontSize);
735         }
736         Dimension weekHeight;
737         if (ConvertFromJSValue(obj->GetProperty("weekHeight"), weekHeight)) {
738             weekStyle.UpdateWeekHeight(weekHeight);
739         }
740         Dimension weekWidth;
741         if (ConvertFromJSValue(obj->GetProperty("weekWidth"), weekWidth)) {
742             weekStyle.UpdateWeekWidth(weekWidth);
743         }
744         Dimension weekAndDayRowSpace;
745         if (ConvertFromJSValue(obj->GetProperty("weekAndDayRowSpace"), weekAndDayRowSpace)) {
746             weekStyle.UpdateWeekAndDayRowSpace(weekAndDayRowSpace);
747         }
748         NG::CalendarView::SetWeekStyle(weekStyle);
749         return;
750     }
751     auto component = GetComponent();
752     if (!component) {
753         return;
754     }
755 
756     auto& themePtr = component->GetCalendarTheme();
757     if (!themePtr) {
758         return;
759     }
760     auto& theme = themePtr->GetCalendarTheme();
761     ConvertFromJSValue(obj->GetProperty("weekColor"), theme.weekColor);
762     ConvertFromJSValue(obj->GetProperty("weekendDayColor"), theme.weekendDayColor);
763     ConvertFromJSValue(obj->GetProperty("weekendLunarColor"), theme.weekendLunarColor);
764     Dimension weekFontSize;
765     if (ParseJsDimensionFp(obj->GetProperty("weekFontSize"), weekFontSize)) {
766         theme.weekFontSize = weekFontSize;
767     }
768     ConvertFromJSValue(obj->GetProperty("weekHeight"), theme.weekHeight);
769     ConvertFromJSValue(obj->GetProperty("weekWidth"), theme.weekWidth);
770     ConvertFromJSValue(obj->GetProperty("weekAndDayRowSpace"), theme.weekAndDayRowSpace);
771 }
772 
SetWorkStateStyle(const JSCallbackInfo & info)773 void JSCalendar::SetWorkStateStyle(const JSCallbackInfo& info)
774 {
775     if (info.Length() < 1 || !info[0]->IsObject()) {
776         LOGW("Invalid params");
777         return;
778     }
779     auto obj = JSRef<JSObject>::Cast(info[0]);
780     if (Container::IsCurrentUseNewPipeline()) {
781         NG::WorkStateStyle workStateStyle;
782         Color workDayMarkColor;
783         if (ConvertFromJSValue(obj->GetProperty("workDayMarkColor"), workDayMarkColor)) {
784             workStateStyle.UpdateWorkDayMarkColor(workDayMarkColor);
785         }
786         Color offDayMarkColor;
787         if (ConvertFromJSValue(obj->GetProperty("offDayMarkColor"), offDayMarkColor)) {
788             workStateStyle.UpdateOffDayMarkColor(offDayMarkColor);
789         }
790         Dimension workDayMarkSize;
791         if (ConvertFromJSValue(obj->GetProperty("workDayMarkSize"), workDayMarkSize)) {
792             workStateStyle.UpdateWorkDayMarkSize(workDayMarkSize);
793         }
794         Dimension offDayMarkSize;
795         if (ConvertFromJSValue(obj->GetProperty("offDayMarkSize"), offDayMarkSize)) {
796             workStateStyle.UpdateOffDayMarkSize(offDayMarkSize);
797         }
798         Dimension workStateWidth;
799         if (ConvertFromJSValue(obj->GetProperty("workStateWidth"), workStateWidth)) {
800             workStateStyle.UpdateWorkStateWidth(workStateWidth);
801         }
802         Dimension workStateHorizontalMovingDistance;
803         if (ConvertFromJSValue(
804                 obj->GetProperty("workStateHorizontalMovingDistance"), workStateHorizontalMovingDistance)) {
805             workStateStyle.UpdateWorkStateHorizontalMovingDistance(workStateHorizontalMovingDistance);
806         }
807         Dimension workStateVerticalMovingDistance;
808         if (ConvertFromJSValue(obj->GetProperty("workStateVerticalMovingDistance"), workStateVerticalMovingDistance)) {
809             workStateStyle.UpdateWorkStateVerticalMovingDistance(workStateVerticalMovingDistance);
810         }
811         NG::CalendarView::SetWorkStateStyle(workStateStyle);
812         return;
813     }
814     auto component = GetComponent();
815     CHECK_NULL_VOID(component);
816 
817     auto& themePtr = component->GetCalendarTheme();
818     CHECK_NULL_VOID(themePtr);
819     auto& theme = themePtr->GetCalendarTheme();
820     ConvertFromJSValue(obj->GetProperty("workDayMarkColor"), theme.workDayMarkColor);
821     ConvertFromJSValue(obj->GetProperty("offDayMarkColor"), theme.offDayMarkColor);
822     ConvertFromJSValue(obj->GetProperty("workDayMarkSize"), theme.workDayMarkSize);
823     ConvertFromJSValue(obj->GetProperty("offDayMarkSize"), theme.offDayMarkSize);
824     ConvertFromJSValue(obj->GetProperty("workStateWidth"), theme.workStateWidth);
825     ConvertFromJSValue(obj->GetProperty("workStateHorizontalMovingDistance"), theme.workStateHorizontalMovingDistance);
826     ConvertFromJSValue(obj->GetProperty("workStateVerticalMovingDistance"), theme.workStateVerticalMovingDistance);
827 }
828 
829 } // namespace OHOS::Ace::Framework
830