1 /*
2 * Copyright (c) 2021-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 "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/ui_node.h"
30 #include "core/components_ng/base/view_stack_processor.h"
31 #include "core/components_ng/pattern/calendar/calendar_model_ng.h"
32 #include "core/pipeline/pipeline_context.h"
33 #include "frameworks/bridge/declarative_frontend/jsview/js_calendar_controller.h"
34 #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
35 #include "frameworks/bridge/declarative_frontend/jsview/models/calendar_model_impl.h"
36
37 namespace OHOS::Ace {
38 std::unique_ptr<CalendarModel> CalendarModel::instance_ = nullptr;
39 std::mutex CalendarModel::mutex_;
40
GetInstance()41 CalendarModel* CalendarModel::GetInstance()
42 {
43 if (!instance_) {
44 std::lock_guard<std::mutex> lock(mutex_);
45 if (!instance_) {
46 #ifdef NG_BUILD
47 instance_.reset(new NG::CalendarModelNG());
48 #else
49 if (Container::IsCurrentUseNewPipeline()) {
50 instance_.reset(new NG::CalendarModelNG());
51 } else {
52 instance_.reset(new Framework::CalendarModelImpl());
53 }
54 #endif
55 }
56 }
57 return instance_.get();
58 }
59 } // namespace OHOS::Ace
60
61 namespace OHOS::Ace::Framework {
62 namespace {
63 constexpr int32_t CALENDAR_INVALID = -1;
64 } // namespace
65
JSBind(BindingTarget globalObj)66 void JSCalendar::JSBind(BindingTarget globalObj)
67 {
68 JSClass<JSCalendar>::Declare("Calendar");
69 MethodOptions opt = MethodOptions::NONE;
70 JSClass<JSCalendar>::StaticMethod("create", &JSCalendar::Create, opt);
71 JSClass<JSCalendar>::StaticMethod("showLunar", &JSCalendar::SetShowLunar, opt);
72 JSClass<JSCalendar>::StaticMethod("showHoliday", &JSCalendar::SetShowHoliday, opt);
73 JSClass<JSCalendar>::StaticMethod("needSlide", &JSCalendar::SetNeedSlide, opt);
74 JSClass<JSCalendar>::StaticMethod("startOfWeek", &JSCalendar::SetStartOfWeek, opt);
75 JSClass<JSCalendar>::StaticMethod("offDays", &JSCalendar::SetOffDays, opt);
76 JSClass<JSCalendar>::StaticMethod("onSelectChange", &JSCalendar::JsOnSelectedChange, opt);
77 JSClass<JSCalendar>::StaticMethod("onRequestData", &JSCalendar::JsOnRequestData, opt);
78 JSClass<JSCalendar>::StaticMethod("direction", &JSCalendar::SetDirection, opt);
79 JSClass<JSCalendar>::StaticMethod("currentDayStyle", &JSCalendar::SetCurrentDayStyle, opt);
80 JSClass<JSCalendar>::StaticMethod("nonCurrentDayStyle", &JSCalendar::SetNonCurrentDayStyle, opt);
81 JSClass<JSCalendar>::StaticMethod("todayStyle", &JSCalendar::SetTodayStyle, opt);
82 JSClass<JSCalendar>::StaticMethod("weekStyle", &JSCalendar::SetWeekStyle, opt);
83 JSClass<JSCalendar>::StaticMethod("workStateStyle", &JSCalendar::SetWorkStateStyle, opt);
84 JSClass<JSCalendar>::InheritAndBind<JSViewAbstract>(globalObj);
85 }
86
Create(const JSCallbackInfo & info)87 void JSCalendar::Create(const JSCallbackInfo& info)
88 {
89 if (!info[0]->IsObject()) {
90 return;
91 }
92 auto obj = JSRef<JSObject>::Cast(info[0]);
93 auto dataJsVal = obj->GetProperty("date");
94 auto currentDataJsVal = obj->GetProperty("currentData");
95 auto preDataJsVal = obj->GetProperty("preData");
96 auto nextDataJsVal = obj->GetProperty("nextData");
97 if (!(dataJsVal->IsObject() && currentDataJsVal->IsObject() && preDataJsVal->IsObject() &&
98 nextDataJsVal->IsObject())) {
99 return;
100 }
101 auto date = JSRef<JSObject>::Cast(dataJsVal);
102 auto currentData = JSRef<JSObject>::Cast(currentDataJsVal);
103 auto preData = JSRef<JSObject>::Cast(preDataJsVal);
104 auto nextData = JSRef<JSObject>::Cast(nextDataJsVal);
105 auto controllerObj = obj->GetProperty("controller");
106 auto yearValue = date->GetProperty("year");
107 auto monthValue = date->GetProperty("month");
108 auto dayValue = date->GetProperty("day");
109 if (!yearValue->IsNumber() || !monthValue->IsNumber() || !dayValue->IsNumber()) {
110 return;
111 }
112 CalendarDay day;
113 day.month.year = yearValue->ToNumber<int32_t>();
114 day.month.month = monthValue->ToNumber<int32_t>();
115 day.day = dayValue->ToNumber<int32_t>();
116 CalendarModelData calendarData;
117 calendarData.date = day;
118 ObtainedMonth currentMonthData = GetCurrentData(currentData);
119 ObtainedMonth preMonthData = GetPreData(preData);
120 ObtainedMonth nextMonthData = GetNextData(nextData);
121 calendarData.currentData = currentMonthData;
122 calendarData.preData = preMonthData;
123 calendarData.nextData = nextMonthData;
124 if (controllerObj->IsObject()) {
125 auto jsCalendarController = JSRef<JSObject>::Cast(controllerObj)->Unwrap<JSCalendarController>();
126 if (jsCalendarController) {
127 jsCalendarController->SetInstanceId(Container::CurrentId());
128 calendarData.controller = jsCalendarController->GetController();
129 }
130 }
131 CalendarModel::GetInstance()->Create(calendarData);
132 }
133
SetCalendarData(const JSRef<JSObject> & obj,MonthState monthState,const RefPtr<CalendarComponentV2> & component)134 void JSCalendar::SetCalendarData(
135 const JSRef<JSObject>& obj, MonthState monthState, const RefPtr<CalendarComponentV2>& component)
136 {
137 CHECK_NULL_VOID(component);
138
139 #if defined(PREVIEW)
140 if (obj->IsUndefined()) {
141 return;
142 }
143 #endif
144
145 component->SetCalendarData(GetCalendarData(obj, monthState));
146 }
147
GetCalendarData(const JSRef<JSObject> & obj,MonthState monthState)148 ObtainedMonth JSCalendar::GetCalendarData(const JSRef<JSObject>& obj, MonthState monthState)
149 {
150 #if defined(PREVIEW)
151 if (obj->IsUndefined()) {
152 return ObtainedMonth();
153 }
154 #endif
155
156 auto yearValue = obj->GetProperty("year");
157 auto monthValue = obj->GetProperty("month");
158 auto arrayValue = obj->GetProperty("data");
159 if (!yearValue->IsNumber() || !monthValue->IsNumber() || !arrayValue->IsArray()) {
160 return ObtainedMonth();
161 }
162 ObtainedMonth obtainedMonth;
163 obtainedMonth.year = yearValue->ToNumber<int32_t>();
164 obtainedMonth.month = monthValue->ToNumber<int32_t>();
165 std::vector<CalendarDay> days;
166 JSRef<JSArray> dataArray = JSRef<JSArray>::Cast(arrayValue);
167 size_t length = dataArray->Length();
168 for (size_t i = 0; i < length; ++i) {
169 CalendarDay day;
170 JSRef<JSVal> item = dataArray->GetValueAt(i);
171 if (!item->IsObject()) {
172 days.emplace_back(std::move(day));
173 continue;
174 }
175 JSRef<JSObject> itemObj = JSRef<JSObject>::Cast(item);
176 day.index = itemObj->GetPropertyValue<int32_t>("index", 0);
177 day.lunarMonth = itemObj->GetPropertyValue<std::string>("lunarMonth", "");
178 day.lunarDay = itemObj->GetPropertyValue<std::string>("lunarDay", "");
179 day.dayMark = itemObj->GetPropertyValue<std::string>("dayMark", "");
180 day.dayMarkValue = itemObj->GetPropertyValue<std::string>("dayMarkValue", "");
181 day.month.year = itemObj->GetPropertyValue<int32_t>("year", 0);
182 day.month.month = itemObj->GetPropertyValue<int32_t>("month", 0);
183 day.day = itemObj->GetPropertyValue<int32_t>("day", 0);
184 if (day.day == 1 && obtainedMonth.firstDayIndex == CALENDAR_INVALID) {
185 obtainedMonth.firstDayIndex = day.index;
186 }
187 day.isFirstOfLunar = itemObj->GetPropertyValue<bool>("isFirstOfLunar", false);
188 day.hasSchedule = itemObj->GetPropertyValue<bool>("hasSchedule", false);
189 day.markLunarDay = itemObj->GetPropertyValue<bool>("markLunarDay", false);
190 days.emplace_back(std::move(day));
191 }
192 obtainedMonth.days = days;
193 return obtainedMonth;
194 }
195
SetCardCalendar(bool cardCalendar)196 void JSCalendar::SetCardCalendar(bool cardCalendar)
197 {
198 auto component = GetComponent();
199 CHECK_NULL_VOID(component);
200
201 component->SetCardCalendar(cardCalendar);
202 }
203
SetDate(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)204 void JSCalendar::SetDate(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
205 {
206 if (component) {
207 auto yearValue = obj->GetProperty("year");
208 auto monthValue = obj->GetProperty("month");
209 auto dayValue = obj->GetProperty("day");
210 if (!yearValue->IsNumber() || !monthValue->IsNumber() || !dayValue->IsNumber()) {
211 return;
212 }
213 CalendarDay day;
214 day.month.year = yearValue->ToNumber<int32_t>();
215 day.month.month = monthValue->ToNumber<int32_t>();
216 day.day = dayValue->ToNumber<int32_t>();
217 component->SetCalendarDate(day);
218 }
219 }
220
SetHolidays(const std::string & holidays)221 void JSCalendar::SetHolidays(const std::string& holidays)
222 {
223 auto component = GetComponent();
224 CHECK_NULL_VOID(component);
225
226 component->SetHolidays(holidays);
227 }
228
SetOffDays(int32_t offDays)229 void JSCalendar::SetOffDays(int32_t offDays)
230 {
231 uint32_t bit = 0b1;
232 std::string result;
233 const static int32_t dayOfWeek = 7;
234 for (auto i = 0; i < dayOfWeek; ++i) {
235 if (bit & static_cast<uint32_t>(offDays)) {
236 result += std::to_string(i);
237 result += ",";
238 }
239 bit <<= 1;
240 }
241
242 CalendarModel::GetInstance()->SetOffDays(result);
243 }
244
SetShowHoliday(const JSCallbackInfo & info)245 void JSCalendar::SetShowHoliday(const JSCallbackInfo& info)
246 {
247 bool showHoliday = true;
248 if (info[0]->IsBoolean()) {
249 showHoliday = info[0]->ToBoolean();
250 }
251 CalendarModel::GetInstance()->SetShowHoliday(showHoliday);
252 }
253
SetShowLunar(const JSCallbackInfo & info)254 void JSCalendar::SetShowLunar(const JSCallbackInfo& info)
255 {
256 bool showLunar = false;
257 if (info[0]->IsBoolean()) {
258 showLunar = info[0]->ToBoolean();
259 }
260 CalendarModel::GetInstance()->SetShowLunar(showLunar);
261 }
262
SetStartOfWeek(const JSCallbackInfo & info)263 void JSCalendar::SetStartOfWeek(const JSCallbackInfo& info)
264 {
265 if (info[0]->IsNumber()) {
266 auto startOfWeek = info[0]->ToNumber<int32_t>();
267 CalendarModel::GetInstance()->SetStartOfWeek(startOfWeek);
268 }
269 }
270
SetNeedSlide(const JSCallbackInfo & info)271 void JSCalendar::SetNeedSlide(const JSCallbackInfo& info)
272 {
273 bool needSlide = false;
274 if (info[0]->IsBoolean()) {
275 needSlide = info[0]->ToBoolean();
276 }
277 CalendarModel::GetInstance()->SetNeedSlide(needSlide);
278 }
279
SetWorkDays(const std::string & workDays)280 void JSCalendar::SetWorkDays(const std::string& workDays)
281 {
282 auto component = GetComponent();
283 CHECK_NULL_VOID(component);
284
285 component->SetWorkDays(workDays);
286 }
287
GetComponent()288 RefPtr<CalendarComponentV2> JSCalendar::GetComponent()
289 {
290 auto stack = ViewStackProcessor::GetInstance();
291 if (!stack) {
292 return nullptr;
293 }
294 auto component = AceType::DynamicCast<CalendarComponentV2>(stack->GetMainComponent());
295 if (AceApplicationInfo::GetInstance().IsRightToLeft()) {
296 component->SetTextDirection(TextDirection::RTL);
297 }
298 return component;
299 }
300
JsOnSelectedChange(const JSCallbackInfo & info)301 void JSCalendar::JsOnSelectedChange(const JSCallbackInfo& info)
302 {
303 if (!info[0]->IsFunction()) {
304 return;
305 }
306 if (info[0]->IsFunction()) {
307 auto frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
308 auto selectedChangeFuc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
309 auto selectedChange = [execCtx = info.GetExecutionContext(), func = std::move(selectedChangeFuc),
310 node = frameNode](const std::string& info) {
311 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
312 std::vector<std::string> keys = { "year", "month", "day" };
313 ACE_SCORING_EVENT("Calendar.onSelectedChange");
314 PipelineContext::SetCallBackNode(node);
315 func->Execute(keys, info);
316 };
317 CalendarModel::GetInstance()->SetSelectedChangeEvent(std::move(selectedChange));
318 }
319 }
320
JsOnRequestData(const JSCallbackInfo & info)321 void JSCalendar::JsOnRequestData(const JSCallbackInfo& info)
322 {
323 if (!info[0]->IsFunction()) {
324 return;
325 }
326 WeakPtr<NG::FrameNode> frameNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode());
327 auto requestDataFuc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[0]));
328 auto requestData = [execCtx = info.GetExecutionContext(), func = std::move(requestDataFuc), node = frameNode](
329 const std::string& info) {
330 JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
331 ACE_SCORING_EVENT("Calendar.onRequestData");
332 std::vector<std::string> keys = { "year", "month", "currentMonth", "currentYear", "monthState" };
333 PipelineContext::SetCallBackNode(node);
334 func->Execute(keys, info);
335 };
336 CalendarModel::GetInstance()->SetOnRequestDataEvent(std::move(requestData));
337 }
338
SetCurrentData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)339 void JSCalendar::SetCurrentData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
340 {
341 SetCalendarData(obj, MonthState::CUR_MONTH, component);
342 }
343
GetCurrentData(const JSRef<JSObject> & obj)344 ObtainedMonth JSCalendar::GetCurrentData(const JSRef<JSObject>& obj)
345 {
346 return GetCalendarData(obj, MonthState::CUR_MONTH);
347 }
348
SetPreData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)349 void JSCalendar::SetPreData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
350 {
351 SetCalendarData(obj, MonthState::PRE_MONTH, component);
352 }
353
GetPreData(const JSRef<JSObject> & obj)354 ObtainedMonth JSCalendar::GetPreData(const JSRef<JSObject>& obj)
355 {
356 return GetCalendarData(obj, MonthState::PRE_MONTH);
357 }
358
SetNextData(const JSRef<JSObject> & obj,const RefPtr<CalendarComponentV2> & component)359 void JSCalendar::SetNextData(const JSRef<JSObject>& obj, const RefPtr<CalendarComponentV2>& component)
360 {
361 SetCalendarData(obj, MonthState::NEXT_MONTH, component);
362 }
363
GetNextData(const JSRef<JSObject> & obj)364 ObtainedMonth JSCalendar::GetNextData(const JSRef<JSObject>& obj)
365 {
366 return GetCalendarData(obj, MonthState::NEXT_MONTH);
367 }
368
SetDirection(const JSCallbackInfo & info)369 void JSCalendar::SetDirection(const JSCallbackInfo& info)
370 {
371 if (info[0]->IsNumber()) {
372 auto dir = info[0]->ToNumber<int32_t>();
373 CalendarModel::GetInstance()->SetDirection(dir);
374 }
375 }
376
SetCurrentDayStyle(const JSCallbackInfo & info)377 void JSCalendar::SetCurrentDayStyle(const JSCallbackInfo& info)
378 {
379 if (!info[0]->IsObject()) {
380 return;
381 }
382 auto obj = JSRef<JSObject>::Cast(info[0]);
383 CurrentDayStyleData currentDayStyleData;
384 Color dayColor;
385 if (ConvertFromJSValue(obj->GetProperty("dayColor"), dayColor)) {
386 currentDayStyleData.dayColor = dayColor;
387 }
388 Color lunarColor;
389 if (ConvertFromJSValue(obj->GetProperty("lunarColor"), lunarColor)) {
390 currentDayStyleData.lunarColor = lunarColor;
391 }
392 Color markLunarColor;
393 if (ConvertFromJSValue(obj->GetProperty("markLunarColor"), markLunarColor)) {
394 currentDayStyleData.markLunarColor = markLunarColor;
395 }
396 CalcDimension dayFontSize;
397 if (ParseJsDimensionFp(obj->GetProperty("dayFontSize"), dayFontSize)) {
398 currentDayStyleData.dayFontSize = dayFontSize;
399 }
400 CalcDimension lunarDayFontSize;
401 if (ParseJsDimensionFp(obj->GetProperty("lunarDayFontSize"), lunarDayFontSize)) {
402 currentDayStyleData.lunarDayFontSize = lunarDayFontSize;
403 }
404 CalcDimension dayHeight;
405 if (ParseJsDimensionFp(obj->GetProperty("dayHeight"), dayHeight)) {
406 currentDayStyleData.dayHeight = dayHeight;
407 }
408 CalcDimension dayWidth;
409 if (ParseJsDimensionFp(obj->GetProperty("dayWidth"), dayWidth)) {
410 currentDayStyleData.dayWidth = dayWidth;
411 }
412 CalcDimension gregorianCalendarHeight;
413 if (ParseJsDimensionFp(obj->GetProperty("gregorianCalendarHeight"), gregorianCalendarHeight)) {
414 currentDayStyleData.gregorianCalendarHeight = gregorianCalendarHeight;
415 }
416 CalcDimension lunarHeight;
417 if (ParseJsDimensionFp(obj->GetProperty("lunarHeight"), lunarHeight)) {
418 currentDayStyleData.lunarHeight = lunarHeight;
419 }
420 CalcDimension dayYAxisOffset;
421 if (ParseJsDimensionFp(obj->GetProperty("dayYAxisOffset"), dayYAxisOffset)) {
422 currentDayStyleData.dayYAxisOffset = dayYAxisOffset;
423 }
424 CalcDimension lunarDayYAxisOffset;
425 if (ParseJsDimensionFp(obj->GetProperty("lunarDayYAxisOffset"), lunarDayYAxisOffset)) {
426 currentDayStyleData.lunarDayYAxisOffset = lunarDayYAxisOffset;
427 }
428 CalcDimension underscoreXAxisOffset;
429 if (ParseJsDimensionFp(obj->GetProperty("underscoreXAxisOffset"), underscoreXAxisOffset)) {
430 currentDayStyleData.underscoreXAxisOffset = underscoreXAxisOffset;
431 }
432 CalcDimension underscoreYAxisOffset;
433 if (ParseJsDimensionFp(obj->GetProperty("underscoreYAxisOffset"), underscoreYAxisOffset)) {
434 currentDayStyleData.underscoreYAxisOffset = underscoreYAxisOffset;
435 }
436 CalcDimension scheduleMarkerXAxisOffset;
437 if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerXAxisOffset"), scheduleMarkerXAxisOffset)) {
438 currentDayStyleData.scheduleMarkerXAxisOffset = scheduleMarkerXAxisOffset;
439 }
440 CalcDimension scheduleMarkerYAxisOffset;
441 if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerYAxisOffset"), scheduleMarkerYAxisOffset)) {
442 currentDayStyleData.scheduleMarkerYAxisOffset = scheduleMarkerYAxisOffset;
443 }
444 CalcDimension colSpace;
445 if (ParseJsDimensionFp(obj->GetProperty("colSpace"), colSpace)) {
446 currentDayStyleData.colSpace = colSpace;
447 }
448 CalcDimension dailyFiveRowSpace;
449 if (ParseJsDimensionFp(obj->GetProperty("dailyFiveRowSpace"), dailyFiveRowSpace)) {
450 currentDayStyleData.dailyFiveRowSpace = dailyFiveRowSpace;
451 }
452 CalcDimension dailySixRowSpace;
453 if (ParseJsDimensionFp(obj->GetProperty("dailySixRowSpace"), dailySixRowSpace)) {
454 currentDayStyleData.dailySixRowSpace = dailySixRowSpace;
455 }
456 CalcDimension underscoreWidth;
457 if (ParseJsDimensionFp(obj->GetProperty("underscoreWidth"), underscoreWidth)) {
458 currentDayStyleData.underscoreWidth = underscoreWidth;
459 }
460 CalcDimension underscoreLength;
461 if (ParseJsDimensionFp(obj->GetProperty("underscoreLength"), underscoreLength)) {
462 currentDayStyleData.underscoreLength = underscoreLength;
463 }
464 CalcDimension scheduleMarkerRadius;
465 if (ParseJsDimensionFp(obj->GetProperty("scheduleMarkerRadius"), scheduleMarkerRadius)) {
466 currentDayStyleData.scheduleMarkerRadius = scheduleMarkerRadius;
467 }
468 CalcDimension boundaryRowOffset;
469 if (ParseJsDimensionFp(obj->GetProperty("boundaryRowOffset"), boundaryRowOffset)) {
470 currentDayStyleData.boundaryRowOffset = boundaryRowOffset;
471 }
472 CalcDimension boundaryColOffset;
473 if (ParseJsDimensionFp(obj->GetProperty("boundaryColOffset"), boundaryColOffset)) {
474 currentDayStyleData.boundaryColOffset = boundaryColOffset;
475 }
476
477 CurrentDayStyleData CurrentDayStyleDataImpl;
478 ConvertFromJSValue(obj->GetProperty("dayColor"), CurrentDayStyleDataImpl.dayColor);
479 ConvertFromJSValue(obj->GetProperty("lunarColor"), CurrentDayStyleDataImpl.lunarColor);
480 ConvertFromJSValue(obj->GetProperty("markLunarColor"), CurrentDayStyleDataImpl.markLunarColor);
481 CalcDimension dayFontSize_impl;
482 if (ParseJsDimensionFp(obj->GetProperty("dayFontSize"), dayFontSize_impl)) {
483 CurrentDayStyleDataImpl.dayFontSize = dayFontSize_impl;
484 }
485 CalcDimension lunarDayFontSize_impl;
486 if (ParseJsDimensionFp(obj->GetProperty("lunarDayFontSize"), lunarDayFontSize_impl)) {
487 CurrentDayStyleDataImpl.lunarDayFontSize = lunarDayFontSize_impl;
488 }
489 ConvertFromJSValue(obj->GetProperty("dayHeight"), CurrentDayStyleDataImpl.dayHeight);
490 ConvertFromJSValue(obj->GetProperty("dayWidth"), CurrentDayStyleDataImpl.dayWidth);
491 ConvertFromJSValue(obj->GetProperty("gregorianCalendarHeight"), CurrentDayStyleDataImpl.gregorianCalendarHeight);
492 ConvertFromJSValue(obj->GetProperty("lunarHeight"), CurrentDayStyleDataImpl.lunarHeight);
493 ConvertFromJSValue(obj->GetProperty("dayYAxisOffset"), CurrentDayStyleDataImpl.dayYAxisOffset);
494 ConvertFromJSValue(obj->GetProperty("lunarDayYAxisOffset"), CurrentDayStyleDataImpl.lunarDayYAxisOffset);
495 ConvertFromJSValue(obj->GetProperty("underscoreXAxisOffset"), CurrentDayStyleDataImpl.underscoreXAxisOffset);
496 ConvertFromJSValue(obj->GetProperty("underscoreYAxisOffset"), CurrentDayStyleDataImpl.underscoreYAxisOffset);
497 ConvertFromJSValue(obj->GetProperty("scheduleMarkerXAxisOffset"),
498 CurrentDayStyleDataImpl.scheduleMarkerXAxisOffset);
499 ConvertFromJSValue(obj->GetProperty("scheduleMarkerYAxisOffset"),
500 CurrentDayStyleDataImpl.scheduleMarkerYAxisOffset);
501 ConvertFromJSValue(obj->GetProperty("colSpace"), CurrentDayStyleDataImpl.colSpace);
502 ConvertFromJSValue(obj->GetProperty("dailyFiveRowSpace"), CurrentDayStyleDataImpl.dailyFiveRowSpace);
503 ConvertFromJSValue(obj->GetProperty("dailySixRowSpace"), CurrentDayStyleDataImpl.dailySixRowSpace);
504 ConvertFromJSValue(obj->GetProperty("underscoreWidth"), CurrentDayStyleDataImpl.underscoreWidth);
505 ConvertFromJSValue(obj->GetProperty("underscoreLength"), CurrentDayStyleDataImpl.underscoreLength);
506 ConvertFromJSValue(obj->GetProperty("scheduleMarkerRadius"), CurrentDayStyleDataImpl.scheduleMarkerRadius);
507 ConvertFromJSValue(obj->GetProperty("boundaryRowOffset"), CurrentDayStyleDataImpl.boundaryRowOffset);
508 ConvertFromJSValue(obj->GetProperty("boundaryColOffset"), CurrentDayStyleDataImpl.boundaryColOffset);
509 ConvertFromJSValue(obj->GetProperty("touchCircleStrokeWidth"), CurrentDayStyleDataImpl.touchCircleStrokeWidth);
510
511 CalendarModel::GetInstance()->SetCurrentDayStyle(currentDayStyleData, CurrentDayStyleDataImpl);
512 }
513
SetNonCurrentDayStyle(const JSCallbackInfo & info)514 void JSCalendar::SetNonCurrentDayStyle(const JSCallbackInfo& info)
515 {
516 if (info.Length() < 1 || !info[0]->IsObject()) {
517 return;
518 }
519 auto obj = JSRef<JSObject>::Cast(info[0]);
520 NonCurrentDayStyleData nonCurrentDayStyleData;
521 Color nonCurrentMonthDayColor;
522 if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthDayColor"), nonCurrentMonthDayColor)) {
523 nonCurrentDayStyleData.nonCurrentMonthDayColor = nonCurrentMonthDayColor;
524 }
525 Color nonCurrentMonthLunarColor;
526 if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthLunarColor"), nonCurrentMonthLunarColor)) {
527 nonCurrentDayStyleData.nonCurrentMonthLunarColor = nonCurrentMonthLunarColor;
528 }
529 Color nonCurrentMonthWorkDayMarkColor;
530 if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthWorkDayMarkColor"), nonCurrentMonthWorkDayMarkColor)) {
531 nonCurrentDayStyleData.nonCurrentMonthWorkDayMarkColor = nonCurrentMonthWorkDayMarkColor;
532 }
533 Color nonCurrentMonthOffDayMarkColor;
534 if (ConvertFromJSValue(obj->GetProperty("nonCurrentMonthOffDayMarkColor"), nonCurrentMonthOffDayMarkColor)) {
535 nonCurrentDayStyleData.nonCurrentMonthOffDayMarkColor = nonCurrentMonthOffDayMarkColor;
536 }
537 CalendarModel::GetInstance()->SetNonCurrentDayStyle(nonCurrentDayStyleData);
538 }
539
SetTodayStyle(const JSCallbackInfo & info)540 void JSCalendar::SetTodayStyle(const JSCallbackInfo& info)
541 {
542 if (info.Length() < 1 || !info[0]->IsObject()) {
543 return;
544 }
545 auto obj = JSRef<JSObject>::Cast(info[0]);
546 TodayStyleData todayStyle;
547 Color focusedDayColor;
548 if (ConvertFromJSValue(obj->GetProperty("focusedDayColor"), focusedDayColor)) {
549 todayStyle.focusedDayColor = focusedDayColor;
550 }
551 Color focusedLunarColor;
552 if (ConvertFromJSValue(obj->GetProperty("focusedLunarColor"), focusedLunarColor)) {
553 todayStyle.focusedLunarColor = focusedLunarColor;
554 }
555 Color focusedAreaBackgroundColor;
556 if (ConvertFromJSValue(obj->GetProperty("focusedAreaBackgroundColor"), focusedAreaBackgroundColor)) {
557 todayStyle.focusedAreaBackgroundColor = focusedAreaBackgroundColor;
558 }
559 CalcDimension focusedAreaRadius;
560 if (ConvertFromJSValue(obj->GetProperty("focusedAreaRadius"), focusedAreaRadius)) {
561 todayStyle.focusedAreaRadius = focusedAreaRadius;
562 }
563 CalendarModel::GetInstance()->SetTodayStyle(todayStyle);
564 }
565
SetWeekStyle(const JSCallbackInfo & info)566 void JSCalendar::SetWeekStyle(const JSCallbackInfo& info)
567 {
568 if (info.Length() < 1 || !info[0]->IsObject()) {
569 return;
570 }
571 auto obj = JSRef<JSObject>::Cast(info[0]);
572 WeekStyleData weekStyle;
573 Color weekColor;
574 if (ConvertFromJSValue(obj->GetProperty("weekColor"), weekColor)) {
575 weekStyle.weekColor = weekColor;
576 }
577 Color weekendDayColor;
578 if (ConvertFromJSValue(obj->GetProperty("weekendDayColor"), weekendDayColor)) {
579 weekStyle.weekendDayColor = weekendDayColor;
580 }
581 Color weekendLunarColor;
582 if (ConvertFromJSValue(obj->GetProperty("weekendLunarColor"), weekendLunarColor)) {
583 weekStyle.weekendLunarColor = weekendLunarColor;
584 }
585 CalcDimension weekFontSize;
586 if (ParseJsDimensionFp(obj->GetProperty("weekFontSize"), weekFontSize)) {
587 weekStyle.weekFontSize = weekFontSize;
588 }
589 CalcDimension weekHeight;
590 if (ConvertFromJSValue(obj->GetProperty("weekHeight"), weekHeight)) {
591 weekStyle.weekHeight = weekHeight;
592 }
593 CalcDimension weekWidth;
594 if (ConvertFromJSValue(obj->GetProperty("weekWidth"), weekWidth)) {
595 weekStyle.weekWidth = weekWidth;
596 }
597 CalcDimension weekAndDayRowSpace;
598 if (ConvertFromJSValue(obj->GetProperty("weekAndDayRowSpace"), weekAndDayRowSpace)) {
599 weekStyle.weekAndDayRowSpace = weekAndDayRowSpace;
600 }
601 CalendarModel::GetInstance()->SetWeekStyle(weekStyle);
602 }
603
SetWorkStateStyle(const JSCallbackInfo & info)604 void JSCalendar::SetWorkStateStyle(const JSCallbackInfo& info)
605 {
606 if (info.Length() < 1 || !info[0]->IsObject()) {
607 return;
608 }
609 auto obj = JSRef<JSObject>::Cast(info[0]);
610 WorkStateStyleData workStateStyle;
611 Color workDayMarkColor;
612 if (ConvertFromJSValue(obj->GetProperty("workDayMarkColor"), workDayMarkColor)) {
613 workStateStyle.workDayMarkColor = workDayMarkColor;
614 }
615 Color offDayMarkColor;
616 if (ConvertFromJSValue(obj->GetProperty("offDayMarkColor"), offDayMarkColor)) {
617 workStateStyle.offDayMarkColor = offDayMarkColor;
618 }
619 CalcDimension workDayMarkSize;
620 if (ConvertFromJSValue(obj->GetProperty("workDayMarkSize"), workDayMarkSize)) {
621 workStateStyle.workDayMarkSize = workDayMarkSize;
622 }
623 CalcDimension offDayMarkSize;
624 if (ConvertFromJSValue(obj->GetProperty("offDayMarkSize"), offDayMarkSize)) {
625 workStateStyle.offDayMarkSize = offDayMarkSize;
626 }
627 CalcDimension workStateWidth;
628 if (ConvertFromJSValue(obj->GetProperty("workStateWidth"), workStateWidth)) {
629 workStateStyle.workStateWidth = workStateWidth;
630 }
631 CalcDimension workStateHorizontalMovingDistance;
632 if (ConvertFromJSValue(
633 obj->GetProperty("workStateHorizontalMovingDistance"), workStateHorizontalMovingDistance)) {
634 workStateStyle.workStateHorizontalMovingDistance = workStateHorizontalMovingDistance;
635 }
636 CalcDimension workStateVerticalMovingDistance;
637 if (ConvertFromJSValue(obj->GetProperty("workStateVerticalMovingDistance"), workStateVerticalMovingDistance)) {
638 workStateStyle.workStateVerticalMovingDistance = workStateVerticalMovingDistance;
639 }
640 CalendarModel::GetInstance()->SetWorkStateStyle(workStateStyle);
641 }
642 } // namespace OHOS::Ace::Framework
643