1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "core/components_ng/pattern/calendar_picker/calendar_dialog_view.h"
16 
17 #include <utility>
18 
19 #include "base/i18n/localization.h"
20 #include "base/memory/ace_type.h"
21 #include "base/utils/utils.h"
22 #include "core/components/common/properties/shadow_config.h"
23 #include "core/components/theme/icon_theme.h"
24 #include "core/components_ng/base/view_stack_processor.h"
25 #include "core/components_ng/pattern/button/button_pattern.h"
26 #include "core/components_ng/pattern/calendar/calendar_month_pattern.h"
27 #include "core/components_ng/pattern/calendar/calendar_paint_property.h"
28 #include "core/components_ng/pattern/calendar/calendar_pattern.h"
29 #include "core/components_ng/pattern/calendar_picker/calendar_picker_event_hub.h"
30 #include "core/components_ng/pattern/dialog/dialog_view.h"
31 #include "core/components_ng/pattern/divider/divider_pattern.h"
32 #include "core/components_ng/pattern/image/image_pattern.h"
33 #include "core/components_ng/pattern/picker/date_time_animation_controller.h"
34 #include "core/components_ng/pattern/picker/datepicker_pattern.h"
35 #include "core/components_ng/pattern/picker/datepicker_row_layout_property.h"
36 #include "core/components_ng/pattern/stack/stack_pattern.h"
37 #include "core/components_ng/pattern/swiper/swiper_pattern.h"
38 #include "core/components_ng/property/measure_property.h"
39 #include "core/components_v2/inspector/inspector_constants.h"
40 
41 namespace OHOS::Ace::NG {
42 namespace {
43 constexpr int32_t SWIPER_MONTHS_COUNT = 3;
44 constexpr int32_t CURRENT_MONTH_INDEX = 1;
45 constexpr Dimension DIALOG_WIDTH = 336.0_vp;
46 constexpr Dimension CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT = 4.0_vp;
47 constexpr size_t ACCEPT_BUTTON_INDEX = 0;
48 constexpr size_t CANCEL_BUTTON_INDEX = 1;
49 constexpr size_t CANCEL_BUTTON_FONT_COLOR_INDEX = 0;
50 constexpr size_t CANCEL_BUTTON_BACKGROUND_COLOR_INDEX = 1;
51 constexpr size_t ACCEPT_BUTTON_FONT_COLOR_INDEX = 2;
52 constexpr size_t ACCEPT_BUTTON_BACKGROUND_COLOR_INDEX = 3;
53 } // namespace
54 
55 DeviceOrientation CalendarDialogView::previousOrientation_ { DeviceOrientation::PORTRAIT };
56 
Show(const DialogProperties & dialogProperties,const CalendarSettingData & settingData,const std::vector<ButtonInfo> & buttonInfos,const std::map<std::string,NG::DialogEvent> & dialogEvent,const std::map<std::string,NG::DialogGestureEvent> & dialogCancelEvent)57 RefPtr<FrameNode> CalendarDialogView::Show(const DialogProperties& dialogProperties,
58     const CalendarSettingData& settingData, const std::vector<ButtonInfo>& buttonInfos,
59     const std::map<std::string, NG::DialogEvent>& dialogEvent,
60     const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent)
61 {
62     auto contentColumn = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
63         AceType::MakeRefPtr<CalendarDialogPattern>());
64     OperationsToPattern(contentColumn, settingData, dialogProperties, buttonInfos);
65     auto layoutProperty = contentColumn->GetLayoutProperty();
66     CHECK_NULL_RETURN(layoutProperty, nullptr);
67 
68     auto textDirection = layoutProperty->GetLayoutDirection();
69     if (settingData.entryNode.Upgrade() != nullptr) {
70         auto entryNode = settingData.entryNode.Upgrade();
71         textDirection = entryNode->GetLayoutProperty()->GetNonAutoLayoutDirection();
72         layoutProperty->UpdateLayoutDirection(textDirection);
73     }
74 
75     auto calendarNode = CreateCalendarNode(contentColumn, settingData, dialogEvent);
76     CHECK_NULL_RETURN(calendarNode, nullptr);
77     auto calendarLayoutProperty = calendarNode->GetLayoutProperty();
78     CHECK_NULL_RETURN(calendarLayoutProperty, nullptr);
79     calendarLayoutProperty->UpdateLayoutDirection(textDirection);
80 
81     auto titleNode = CreateTitleNode(calendarNode);
82     CHECK_NULL_RETURN(titleNode, nullptr);
83     auto titleLayoutProperty = titleNode->GetLayoutProperty();
84     CHECK_NULL_RETURN(titleLayoutProperty, nullptr);
85 
86     titleLayoutProperty->UpdateLayoutDirection(textDirection);
87     titleNode->MountToParent(contentColumn);
88     calendarNode->MountToParent(contentColumn);
89 
90     auto dialogNode = DialogView::CreateDialogNode(dialogProperties, contentColumn);
91     CHECK_NULL_RETURN(dialogNode, nullptr);
92     auto dialogLayoutProperty = dialogNode->GetLayoutProperty();
93     CHECK_NULL_RETURN(dialogLayoutProperty, nullptr);
94     dialogLayoutProperty->UpdateLayoutDirection(textDirection);
95     CreateChildNode(contentColumn, dialogNode, dialogProperties);
96     if (!settingData.entryNode.Upgrade()) {
97         auto contentRow =
98             CreateOptionsNode(dialogNode, calendarNode, dialogEvent, std::move(dialogCancelEvent), buttonInfos);
99         contentRow->MountToParent(contentColumn);
100         UpdateDialogDefaultFocus(contentRow, contentColumn);
101     }
102 
103     contentColumn->MarkModifyDone();
104     calendarNode->MarkModifyDone();
105     dialogNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
106     return dialogNode;
107 }
108 
CreateChildNode(const RefPtr<FrameNode> & contentColumn,const RefPtr<FrameNode> & dialogNode,const DialogProperties & dialogProperties)109 void CalendarDialogView::CreateChildNode(const RefPtr<FrameNode>& contentColumn,
110     const RefPtr<FrameNode>& dialogNode, const DialogProperties& dialogProperties)
111 {
112     auto layoutProperty = contentColumn->GetLayoutProperty();
113     CHECK_NULL_VOID(layoutProperty);
114     auto pipelineContext = dialogNode->GetContext();
115     CHECK_NULL_VOID(pipelineContext);
116     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
117     RefPtr<DialogTheme> dialogTheme = pipelineContext->GetTheme<DialogTheme>();
118     CHECK_NULL_VOID(theme);
119     PaddingProperty padding;
120     padding.top = CalcLength(theme->GetCalendarTitleRowTopPadding());
121     padding.bottom = CalcLength(theme->GetCalendarTitleRowTopPadding() - CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT);
122     layoutProperty->UpdatePadding(padding);
123     auto childNode = AceType::DynamicCast<FrameNode>(dialogNode->GetFirstChild());
124     CHECK_NULL_VOID(childNode);
125     auto renderContext = childNode->GetRenderContext();
126     CHECK_NULL_VOID(renderContext);
127     if (dialogProperties.customStyle) {
128         layoutProperty->UpdateUserDefinedIdealSize(CalcSize(NG::CalcLength(DIALOG_WIDTH), std::nullopt));
129         BorderRadiusProperty radius;
130         radius.SetRadius(theme->GetDialogBorderRadius());
131         renderContext->UpdateBorderRadius(radius);
132     }
133 
134     UpdateBackgroundStyle(renderContext, dialogProperties);
135 }
136 
OperationsToPattern(const RefPtr<FrameNode> & frameNode,const CalendarSettingData & settingData,const DialogProperties & dialogProperties,const std::vector<ButtonInfo> & buttonInfos)137 void CalendarDialogView::OperationsToPattern(
138     const RefPtr<FrameNode>& frameNode, const CalendarSettingData& settingData,
139     const DialogProperties& dialogProperties, const std::vector<ButtonInfo>& buttonInfos)
140 {
141     auto pattern = frameNode->GetPattern<CalendarDialogPattern>();
142     CHECK_NULL_VOID(pattern);
143     pattern->SetEntryNode(settingData.entryNode);
144     pattern->SetDialogOffset(OffsetF(dialogProperties.offset.GetX().Value(), dialogProperties.offset.GetY().Value()));
145     pattern->SetCurrentButtonInfo(buttonInfos);
146     pattern->SetCurrentSettingData(settingData);
147     SetPreviousOrientation();
148     pattern->InitSurfaceChangedCallback();
149     DisableResetOptionButtonColor(pattern, buttonInfos);
150 }
151 
DisableResetOptionButtonColor(const RefPtr<CalendarDialogPattern> & calendarDialogPattern,const std::vector<ButtonInfo> & buttonInfos)152 void CalendarDialogView::DisableResetOptionButtonColor(
153     const RefPtr<CalendarDialogPattern>& calendarDialogPattern, const std::vector<ButtonInfo>& buttonInfos)
154 {
155     CHECK_NULL_VOID(calendarDialogPattern);
156     size_t fontColorIndex = 0;
157     size_t backgoundColorIndex = 0;
158     for (size_t index = 0; index < buttonInfos.size(); index++) {
159         if (index == 0) {
160             fontColorIndex = ACCEPT_BUTTON_FONT_COLOR_INDEX;
161             backgoundColorIndex = ACCEPT_BUTTON_BACKGROUND_COLOR_INDEX;
162         } else {
163             fontColorIndex = CANCEL_BUTTON_FONT_COLOR_INDEX;
164             backgoundColorIndex = CANCEL_BUTTON_BACKGROUND_COLOR_INDEX;
165         }
166 
167         if (buttonInfos[index].role.has_value() || buttonInfos[index].buttonStyle.has_value() ||
168             buttonInfos[index].fontColor.has_value()) {
169             calendarDialogPattern->SetOptionsButtonUpdateColorFlags(fontColorIndex, false);
170         }
171 
172         if (buttonInfos[index].role.has_value() || buttonInfos[index].buttonStyle.has_value() ||
173             buttonInfos[index].backgroundColor.has_value()) {
174             calendarDialogPattern->SetOptionsButtonUpdateColorFlags(backgoundColorIndex, false);
175         }
176     }
177 }
178 
SetTitleIdealSize(const RefPtr<CalendarTheme> & theme,const RefPtr<LinearLayoutProperty> & layoutProps)179 void CalendarDialogView::SetTitleIdealSize(
180     const RefPtr<CalendarTheme>& theme, const RefPtr<LinearLayoutProperty>& layoutProps)
181 {
182     auto pipeline = PipelineBase::GetCurrentContext();
183     CHECK_NULL_VOID(pipeline);
184     auto fontSizeScale = pipeline->GetFontScale();
185     if (fontSizeScale < theme->GetCalendarPickerLargeScale() || CheckOrientationChange()) {
186         layoutProps->UpdateUserDefinedIdealSize(CalcSize(std::nullopt, CalcLength(theme->GetCalendarTitleRowHeight())));
187     } else if (fontSizeScale >= theme->GetCalendarPickerLargerScale()) {
188         layoutProps->UpdateUserDefinedIdealSize(
189             CalcSize(std::nullopt, CalcLength(theme->GetCalendarTitleLargerRowHeight())));
190     } else {
191         layoutProps->UpdateUserDefinedIdealSize(
192             CalcSize(std::nullopt, CalcLength(theme->GetCalendarTitleLargeRowHeight())));
193     }
194 }
195 
AddButtonAccessAbility(RefPtr<FrameNode> & leftYearArrowNode,RefPtr<FrameNode> & leftDayArrowNode,RefPtr<FrameNode> & rightDayArrowNode,RefPtr<FrameNode> & rightYearArrowNode)196 void AddButtonAccessAbility(RefPtr<FrameNode>& leftYearArrowNode,
197     RefPtr<FrameNode>& leftDayArrowNode, RefPtr<FrameNode>& rightDayArrowNode, RefPtr<FrameNode>& rightYearArrowNode)
198 {
199     CHECK_NULL_VOID(leftYearArrowNode);
200     auto leftYearProperty = leftYearArrowNode->GetAccessibilityProperty<AccessibilityProperty>();
201     CHECK_NULL_VOID(leftYearProperty);
202     leftYearProperty->SetAccessibilityText(Localization::GetInstance()->GetEntryLetters("calendar.pre_year"));
203     CHECK_NULL_VOID(leftDayArrowNode);
204     auto leftDayProperty = leftDayArrowNode->GetAccessibilityProperty<AccessibilityProperty>();
205     CHECK_NULL_VOID(leftDayProperty);
206     leftDayProperty->SetAccessibilityText(Localization::GetInstance()->GetEntryLetters("calendar.pre_month"));
207     CHECK_NULL_VOID(rightDayArrowNode);
208     auto rightDayProperty = rightDayArrowNode->GetAccessibilityProperty<AccessibilityProperty>();
209     CHECK_NULL_VOID(rightDayProperty);
210     rightDayProperty->SetAccessibilityText(Localization::GetInstance()->GetEntryLetters("calendar.next_month"));
211     CHECK_NULL_VOID(rightYearArrowNode);
212     auto rightYearProperty = rightYearArrowNode->GetAccessibilityProperty<AccessibilityProperty>();
213     CHECK_NULL_VOID(rightYearProperty);
214     rightYearProperty->SetAccessibilityText(Localization::GetInstance()->GetEntryLetters("calendar.next_year"));
215 }
216 
CreateTitleNode(const RefPtr<FrameNode> & calendarNode)217 RefPtr<FrameNode> CalendarDialogView::CreateTitleNode(const RefPtr<FrameNode>& calendarNode)
218 {
219     auto titleRow = FrameNode::CreateFrameNode(V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
220         AceType::MakeRefPtr<LinearLayoutPattern>(false));
221     CHECK_NULL_RETURN(titleRow, nullptr);
222     auto layoutProps = titleRow->GetLayoutProperty<LinearLayoutProperty>();
223     CHECK_NULL_RETURN(layoutProps, nullptr);
224     auto pipelineContext = calendarNode->GetContextRefPtr();
225     CHECK_NULL_RETURN(pipelineContext, nullptr);
226     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
227     CHECK_NULL_RETURN(theme, nullptr);
228     layoutProps->UpdateMainAxisAlign(FlexAlign::AUTO);
229     layoutProps->UpdateCrossAxisAlign(FlexAlign::CENTER);
230     layoutProps->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
231     MarginProperty margin;
232     margin.left = CalcLength(theme->GetCalendarTitleRowLeftRightPadding());
233     margin.right = CalcLength(theme->GetCalendarTitleRowLeftRightPadding());
234     layoutProps->UpdateMargin(margin);
235     SetTitleIdealSize(theme, layoutProps);
236 
237     // left year arrow
238     auto leftYearArrowNode =
239         CreateTitleImageNode(calendarNode, InternalResource::ResourceId::IC_PUBLIC_DOUBLE_ARROW_LEFT_SVG);
240     leftYearArrowNode->MountToParent(titleRow);
241 
242     // left day arrow
243     auto leftDayArrowNode = CreateTitleImageNode(calendarNode, InternalResource::ResourceId::IC_PUBLIC_ARROW_LEFT_SVG);
244     leftDayArrowNode->MountToParent(titleRow);
245 
246     // text
247     auto calendarPattern = calendarNode->GetPattern<CalendarPattern>();
248     CHECK_NULL_RETURN(calendarPattern, nullptr);
249     auto textTitleNode =
250         FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, calendarPattern->GetTitleId(), AceType::MakeRefPtr<TextPattern>());
251     CHECK_NULL_RETURN(textTitleNode, nullptr);
252     auto textLayoutProperty = textTitleNode->GetLayoutProperty<TextLayoutProperty>();
253     CHECK_NULL_RETURN(textLayoutProperty, nullptr);
254     textLayoutProperty->UpdateContent("");
255     MarginProperty textMargin;
256     textMargin.left = CalcLength(theme->GetCalendarTitleTextPadding());
257     textMargin.right = CalcLength(theme->GetCalendarTitleTextPadding());
258     textLayoutProperty->UpdateMargin(textMargin);
259     textLayoutProperty->UpdateFontSize(theme->GetCalendarTitleFontSize());
260     textLayoutProperty->UpdateTextColor(theme->GetCalendarTitleFontColor());
261     textLayoutProperty->UpdateFontWeight(FontWeight::MEDIUM);
262     textLayoutProperty->UpdateMaxLines(1);
263     textLayoutProperty->UpdateLayoutWeight(1);
264     textLayoutProperty->UpdateTextAlign(TextAlign::CENTER);
265     textTitleNode->MarkModifyDone();
266     textTitleNode->MountToParent(titleRow);
267 
268     // right day arrow
269     auto rightDayArrowNode =
270         CreateTitleImageNode(calendarNode, InternalResource::ResourceId::IC_PUBLIC_ARROW_RIGHT_SVG);
271     rightDayArrowNode->MountToParent(titleRow);
272 
273     // right year arrow
274     auto rightYearArrowNode =
275         CreateTitleImageNode(calendarNode, InternalResource::ResourceId::IC_PUBLIC_DOUBLE_ARROW_RIGHT_SVG);
276     rightYearArrowNode->MountToParent(titleRow);
277     AddButtonAccessAbility(leftYearArrowNode, leftDayArrowNode, rightDayArrowNode, rightYearArrowNode);
278     return titleRow;
279 }
280 
CreateTitleImageNode(const RefPtr<FrameNode> & calendarNode,const InternalResource::ResourceId & resourceId)281 RefPtr<FrameNode> CalendarDialogView::CreateTitleImageNode(
282     const RefPtr<FrameNode>& calendarNode, const InternalResource::ResourceId& resourceId)
283 {
284     auto pipelineContext = calendarNode->GetContext();
285     CHECK_NULL_RETURN(pipelineContext, nullptr);
286     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
287     CHECK_NULL_RETURN(theme, nullptr);
288     CalcSize idealSize = { CalcLength(theme->GetEntryArrowWidth()), CalcLength(theme->GetEntryArrowWidth()) };
289     MeasureProperty layoutConstraint = { .selfIdealSize = idealSize };
290     BorderRadiusProperty borderRadius;
291     Dimension radius =
292         Dimension((theme->GetCalendarImageWidthHeight().Value()) / 2, (theme->GetCalendarImageWidthHeight()).Unit());
293     borderRadius.SetRadius(radius);
294 
295     // Create button node
296     auto buttonNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
297         ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
298     CHECK_NULL_RETURN(buttonNode, nullptr);
299     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
300     CHECK_NULL_RETURN(buttonLayoutProperty, nullptr);
301     buttonLayoutProperty->UpdateType(ButtonType::CIRCLE);
302     buttonLayoutProperty->UpdateUserDefinedIdealSize(
303         CalcSize(CalcLength(theme->GetCalendarImageWidthHeight()), CalcLength(theme->GetCalendarImageWidthHeight())));
304     auto buttonRenderContext = buttonNode->GetRenderContext();
305     CHECK_NULL_RETURN(buttonRenderContext, nullptr);
306     buttonRenderContext->UpdateBorderRadius(borderRadius);
307     MarginProperty margin;
308     if (resourceId == InternalResource::ResourceId::IC_PUBLIC_DOUBLE_ARROW_LEFT_SVG) {
309         margin.right = CalcLength(theme->GetCalendarTitleImagePadding());
310     } else if (resourceId == InternalResource::ResourceId::IC_PUBLIC_DOUBLE_ARROW_RIGHT_SVG) {
311         margin.left = CalcLength(theme->GetCalendarTitleImagePadding());
312     }
313     buttonLayoutProperty->UpdateMargin(margin);
314 
315     // Create image node
316     auto imageNode = FrameNode::CreateFrameNode(
317         V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
318     CHECK_NULL_RETURN(imageNode, nullptr);
319     auto imageRenderContext = imageNode->GetRenderContext();
320     CHECK_NULL_RETURN(imageRenderContext, nullptr);
321     imageRenderContext->UpdateBorderRadius(borderRadius);
322     auto imageLayoutProperty = imageNode->GetLayoutProperty<ImageLayoutProperty>();
323     CHECK_NULL_RETURN(imageLayoutProperty, nullptr);
324     ImageSourceInfo imageSourceInfo;
325     imageSourceInfo.SetResourceId(resourceId, theme->GetEntryArrowColor());
326     imageLayoutProperty->UpdateImageSourceInfo(imageSourceInfo);
327     imageLayoutProperty->UpdateCalcLayoutProperty(layoutConstraint);
328     imageNode->SetDraggable(false);
329     imageNode->MarkModifyDone();
330     imageNode->MountToParent(buttonNode);
331 
332     buttonNode->MarkModifyDone();
333     return buttonNode;
334 }
335 
SetCalendarIdealSize(const RefPtr<CalendarTheme> & theme,const RefPtr<LayoutProperty> & calendarLayoutProperty)336 void CalendarDialogView::SetCalendarIdealSize(
337     const RefPtr<CalendarTheme>& theme, const RefPtr<LayoutProperty>& calendarLayoutProperty)
338 {
339     auto pipeline = PipelineBase::GetCurrentContext();
340     CHECK_NULL_VOID(pipeline);
341     auto fontSizeScale = pipeline->GetFontScale();
342     if (fontSizeScale < theme->GetCalendarPickerLargeScale() || CheckOrientationChange()) {
343         calendarLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(
344             std::nullopt, CalcLength(theme->GetCalendarContainerHeight() + CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT)));
345     } else if (fontSizeScale >= theme->GetCalendarPickerLargerScale()) {
346         calendarLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(std::nullopt,
347             CalcLength(theme->GetCalendarLargerContainerHeight() + CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT)));
348     } else {
349         calendarLayoutProperty->UpdateUserDefinedIdealSize(CalcSize(std::nullopt,
350             CalcLength(theme->GetCalendarLargeContainerHeight() + CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT)));
351     }
352 }
353 
CreateCalendarNode(const RefPtr<FrameNode> & calendarDialogNode,const CalendarSettingData & settingData,const std::map<std::string,NG::DialogEvent> & dialogEvent)354 RefPtr<FrameNode> CalendarDialogView::CreateCalendarNode(const RefPtr<FrameNode>& calendarDialogNode,
355     const CalendarSettingData& settingData, const std::map<std::string, NG::DialogEvent>& dialogEvent)
356 {
357     int32_t calendarNodeId = ElementRegister::GetInstance()->MakeUniqueId();
358     auto calendarNode = FrameNode::GetOrCreateFrameNode(
359         V2::CALENDAR_ETS_TAG, calendarNodeId, []() { return AceType::MakeRefPtr<CalendarPattern>(); });
360     CHECK_NULL_RETURN(calendarNode, nullptr);
361 
362     InitCalendarProperty(calendarNode);
363     auto textDirection = calendarNode->GetLayoutProperty()->GetNonAutoLayoutDirection();
364     if (settingData.entryNode.Upgrade() != nullptr) {
365         auto entryNode = settingData.entryNode.Upgrade();
366         textDirection = entryNode->GetLayoutProperty()->GetNonAutoLayoutDirection();
367     }
368 
369     auto swiperNode = CreateCalendarSwiperNode();
370     CHECK_NULL_RETURN(swiperNode, nullptr);
371     auto swiperLayoutProperty = swiperNode->GetLayoutProperty<SwiperLayoutProperty>();
372     CHECK_NULL_RETURN(swiperLayoutProperty, nullptr);
373     swiperLayoutProperty->UpdateLayoutDirection(textDirection);
374     swiperNode->MountToParent(calendarNode);
375 
376     InitOnRequestDataEvent(calendarDialogNode, calendarNode);
377     auto calendarPattern = calendarNode->GetPattern<CalendarPattern>();
378     CHECK_NULL_RETURN(calendarPattern, nullptr);
379     PickerDate date = settingData.selectedDate;
380     calendarPattern->SetSelectedDay(date);
381     CalendarMonth currentMonth { .year = date.GetYear(), .month = date.GetMonth() };
382     UpdateCalendarMonthData(calendarDialogNode, calendarNode, currentMonth);
383 
384     CalendarDay calendarDay;
385     PickerDate today = PickerDate::Current();
386     calendarDay.month.year = static_cast<int32_t>(today.GetYear());
387     calendarDay.month.month = static_cast<int32_t>(today.GetMonth());
388     calendarDay.day = static_cast<int32_t>(today.GetDay());
389     calendarPattern->SetCalendarDay(calendarDay);
390 
391     auto changeEvent = dialogEvent.find("changeId");
392     for (int32_t i = 0; i < SWIPER_MONTHS_COUNT; i++) {
393         auto monthFrameNode = CreateCalendarMonthNode(
394             calendarNodeId, settingData, changeEvent == dialogEvent.end() ? nullptr : changeEvent->second);
395         auto monthLayoutProperty = monthFrameNode->GetLayoutProperty();
396         CHECK_NULL_RETURN(monthLayoutProperty, nullptr);
397         if (i == CURRENT_MONTH_INDEX) {
398             auto currentPattern = monthFrameNode->GetPattern<CalendarMonthPattern>();
399             CHECK_NULL_RETURN(currentPattern, nullptr);
400             currentPattern->SetIsFirstEnter(true);
401         }
402         monthLayoutProperty->UpdateLayoutDirection(textDirection);
403         monthFrameNode->MountToParent(swiperNode);
404         monthFrameNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
405     }
406 
407     swiperNode->MarkModifyDone();
408     return calendarNode;
409 }
410 
InitCalendarProperty(const RefPtr<FrameNode> & calendarNode)411 void CalendarDialogView::InitCalendarProperty(const RefPtr<FrameNode>& calendarNode)
412 {
413     auto pipelineContext = calendarNode->GetContext();
414     CHECK_NULL_VOID(pipelineContext);
415     auto calendarLayoutProperty = calendarNode->GetLayoutProperty();
416     CHECK_NULL_VOID(calendarLayoutProperty);
417     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
418     CHECK_NULL_VOID(theme);
419     MarginProperty margin = {
420         .left = CalcLength(theme->GetDistanceBetweenContainterAndDate() - CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT),
421         .right = CalcLength(theme->GetDistanceBetweenContainterAndDate() - CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT),
422         .top = CalcLength(theme->GetDistanceBetweenTitleAndDate()),
423     };
424     calendarLayoutProperty->UpdateMargin(margin);
425     SetCalendarIdealSize(theme, calendarLayoutProperty);
426 }
427 
CreateCalendarSwiperNode()428 RefPtr<FrameNode> CalendarDialogView::CreateCalendarSwiperNode()
429 {
430     auto swiperNode = FrameNode::GetOrCreateFrameNode(V2::SWIPER_ETS_TAG,
431         ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<SwiperPattern>(); });
432     CHECK_NULL_RETURN(swiperNode, nullptr);
433     auto swiperLayoutProperty = swiperNode->GetLayoutProperty<SwiperLayoutProperty>();
434     CHECK_NULL_RETURN(swiperLayoutProperty, nullptr);
435     swiperLayoutProperty->UpdateIndex(CURRENT_MONTH_INDEX);
436     swiperLayoutProperty->UpdateShowIndicator(false);
437     swiperLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT);
438     swiperLayoutProperty->UpdateLoop(true);
439     swiperLayoutProperty->UpdateDisableSwipe(false);
440     return swiperNode;
441 }
442 
CreateCalendarMonthNode(int32_t calendarNodeId,const CalendarSettingData & settingData,const DialogEvent & changeEvent)443 RefPtr<FrameNode> CalendarDialogView::CreateCalendarMonthNode(int32_t calendarNodeId,
444     const CalendarSettingData& settingData, const DialogEvent& changeEvent)
445 {
446     auto monthFrameNode = FrameNode::GetOrCreateFrameNode(V2::CALENDAR_ETS_TAG,
447         ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<CalendarMonthPattern>(); });
448     CHECK_NULL_RETURN(monthFrameNode, nullptr);
449     ViewStackProcessor::GetInstance()->Push(monthFrameNode);
450     SetCalendarPaintProperties(settingData);
451     ViewStackProcessor::GetInstance()->Finish();
452     auto monthPattern = monthFrameNode->GetPattern<CalendarMonthPattern>();
453     CHECK_NULL_RETURN(monthPattern, nullptr);
454     monthPattern->SetCalendarDialogFlag(true);
455     auto calendarEventHub = monthPattern->GetEventHub<CalendarEventHub>();
456     CHECK_NULL_RETURN(calendarEventHub, nullptr);
457     auto selectedChangeEvent = [calendarNodeId, changeEvent, settingData](const std::string& callbackInfo) {
458         OnSelectedChangeEvent(calendarNodeId, callbackInfo, std::move(changeEvent), settingData);
459     };
460     calendarEventHub->SetSelectedChangeEvent(std::move(selectedChangeEvent));
461 
462     auto monthLayoutProperty = monthFrameNode->GetLayoutProperty<LayoutProperty>();
463     CHECK_NULL_RETURN(monthLayoutProperty, nullptr);
464     auto pipelineContext = monthFrameNode->GetContext();
465     CHECK_NULL_RETURN(pipelineContext, nullptr);
466     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
467     CHECK_NULL_RETURN(theme, nullptr);
468     monthLayoutProperty->UpdateUserDefinedIdealSize(
469         CalcSize(CalcLength(1, DimensionUnit::PERCENT),
470         CalcLength(theme->GetCalendarContainerHeight() + CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT)));
471     return monthFrameNode;
472 }
473 
UpdateCalendarMonthData(const RefPtr<FrameNode> & calendarDialogNode,const RefPtr<FrameNode> & calendarNode,const CalendarMonth & currentMonth)474 void CalendarDialogView::UpdateCalendarMonthData(const RefPtr<FrameNode>& calendarDialogNode,
475     const RefPtr<FrameNode>& calendarNode, const CalendarMonth& currentMonth)
476 {
477     CHECK_NULL_VOID(calendarNode);
478     CHECK_NULL_VOID(calendarDialogNode);
479     auto calendarPattern = calendarNode->GetPattern<CalendarPattern>();
480     CHECK_NULL_VOID(calendarPattern);
481     auto calendarDialogPattern = calendarDialogNode->GetPattern<CalendarDialogPattern>();
482     CHECK_NULL_VOID(calendarDialogPattern);
483 
484     CalendarData calendarData;
485     calendarDialogPattern->GetCalendarMonthData(currentMonth.year, currentMonth.month, calendarData.currentData);
486     calendarPattern->SetCurrentMonthData(calendarData.currentData);
487     calendarDialogPattern->GetCalendarMonthData(calendarDialogPattern->GetLastMonth(currentMonth).year,
488         calendarDialogPattern->GetLastMonth(currentMonth).month, calendarData.preData);
489     calendarPattern->SetPreMonthData(calendarData.preData);
490     calendarDialogPattern->GetCalendarMonthData(calendarDialogPattern->GetNextMonth(currentMonth).year,
491         calendarDialogPattern->GetNextMonth(currentMonth).month, calendarData.nextData);
492     calendarPattern->SetNextMonthData(calendarData.nextData);
493 }
494 
SetDialogChange(const RefPtr<FrameNode> & frameNode,DialogEvent && onChange)495 void CalendarDialogView::SetDialogChange(const RefPtr<FrameNode>& frameNode, DialogEvent&& onChange)
496 {
497     CHECK_NULL_VOID(frameNode);
498     auto eventHub = frameNode->GetEventHub<CalendarEventHub>();
499     CHECK_NULL_VOID(eventHub);
500     eventHub->SetDialogChange(std::move(onChange));
501 }
502 
SetDialogAcceptEvent(const RefPtr<FrameNode> & frameNode,DialogEvent && onAccept)503 void CalendarDialogView::SetDialogAcceptEvent(const RefPtr<FrameNode>& frameNode, DialogEvent&& onAccept)
504 {
505     CHECK_NULL_VOID(frameNode);
506     auto eventHub = frameNode->GetEventHub<CalendarEventHub>();
507     CHECK_NULL_VOID(eventHub);
508     eventHub->SetDialogAcceptEvent(std::move(onAccept));
509 }
510 
CreateButtonNode(bool isConfirm,const std::vector<ButtonInfo> & buttonInfos)511 RefPtr<FrameNode> CalendarDialogView::CreateButtonNode(bool isConfirm, const std::vector<ButtonInfo>& buttonInfos)
512 {
513     auto pipeline = PipelineContext::GetCurrentContextSafelyWithCheck();
514     CHECK_NULL_RETURN(pipeline, nullptr);
515     auto dialogTheme = pipeline->GetTheme<DialogTheme>();
516     auto pickerTheme = pipeline->GetTheme<PickerTheme>();
517     auto calendarTheme = pipeline->GetTheme<CalendarTheme>();
518     CHECK_NULL_RETURN(calendarTheme, nullptr);
519     auto buttonNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG,
520         ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<ButtonPattern>(); });
521     CHECK_NULL_RETURN(buttonNode, nullptr);
522     auto textNode = FrameNode::CreateFrameNode(
523         V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
524     CHECK_NULL_RETURN(textNode, nullptr);
525     auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
526     CHECK_NULL_RETURN(textLayoutProperty, nullptr);
527     textLayoutProperty->UpdateContent(
528         Localization::GetInstance()->GetEntryLetters(isConfirm ? "common.ok" : "common.cancel"));
529 
530     auto fontSizeScale = pipeline->GetFontScale();
531     auto fontSize = pickerTheme->GetOptionStyle(false, false).GetFontSize();
532     if (fontSizeScale < calendarTheme->GetCalendarPickerLargeScale() || CheckOrientationChange()) {
533         textLayoutProperty->UpdateFontSize(fontSize);
534     } else {
535         fontSizeScale = fontSizeScale > calendarTheme->GetCalendarPickerLargeScale()
536                             ? calendarTheme->GetCalendarPickerLargeScale()
537                             : fontSizeScale;
538         textLayoutProperty->UpdateFontSize(fontSize * fontSizeScale);
539     }
540 
541     textLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor());
542     textLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight());
543     textNode->MountToParent(buttonNode);
544 
545     UpdateButtonLayoutProperty(buttonNode, isConfirm, buttonInfos, pipeline);
546     auto buttonEventHub = buttonNode->GetEventHub<ButtonEventHub>();
547     CHECK_NULL_RETURN(buttonEventHub, nullptr);
548     buttonEventHub->SetStateEffect(true);
549 
550     auto buttonRenderContext = buttonNode->GetRenderContext();
551     auto defaultBGColor =
552         calendarTheme->GetIsButtonTransparent() ? Color::TRANSPARENT : calendarTheme->GetDialogButtonBackgroundColor();
553     buttonRenderContext->UpdateBackgroundColor(defaultBGColor);
554     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
555     CHECK_NULL_RETURN(buttonLayoutProperty, nullptr);
556     auto index = isConfirm ? ACCEPT_BUTTON_INDEX : CANCEL_BUTTON_INDEX;
557     UpdateButtonStyles(buttonInfos, index, buttonLayoutProperty, buttonRenderContext);
558     UpdateButtonDefaultFocus(buttonInfos, buttonNode, isConfirm);
559     buttonNode->MarkModifyDone();
560     return buttonNode;
561 }
562 
UpdateButtonLayoutProperty(const RefPtr<FrameNode> & buttonNode,bool isConfirm,const std::vector<ButtonInfo> & buttonInfos,const RefPtr<PipelineContext> & pipeline)563 void CalendarDialogView::UpdateButtonLayoutProperty(const RefPtr<FrameNode>& buttonNode, bool isConfirm,
564     const std::vector<ButtonInfo>& buttonInfos, const RefPtr<PipelineContext>& pipeline)
565 {
566     auto dialogTheme = pipeline->GetTheme<DialogTheme>();
567     auto pickerTheme = pipeline->GetTheme<PickerTheme>();
568     auto calendarTheme = pipeline->GetTheme<CalendarTheme>();
569     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
570     CHECK_NULL_VOID(buttonLayoutProperty);
571     auto index = isConfirm ? ACCEPT_BUTTON_INDEX : CANCEL_BUTTON_INDEX;
572     if (index < buttonInfos.size() &&
573         (buttonInfos[index].role.has_value() || buttonInfos[index].buttonStyle.has_value() ||
574             buttonInfos[index].fontSize.has_value() || buttonInfos[index].fontColor.has_value() ||
575             buttonInfos[index].fontWeight.has_value() || buttonInfos[index].fontStyle.has_value() ||
576             buttonInfos[index].fontFamily.has_value())) {
577         buttonLayoutProperty->UpdateLabel(
578             Localization::GetInstance()->GetEntryLetters(isConfirm ? "common.ok" : "common.cancel"));
579     }
580     buttonLayoutProperty->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
581     buttonLayoutProperty->UpdateType(ButtonType::CAPSULE);
582     buttonLayoutProperty->UpdateFlexShrink(1.0);
583     CalcLength width;
584     if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) {
585         width = CalcLength(1.0, DimensionUnit::PERCENT);
586     } else {
587         width = CalcLength(pickerTheme->GetButtonWidth());
588     }
589 
590     auto fontSizeScale = pipeline->GetFontScale();
591     if (fontSizeScale >= calendarTheme->GetCalendarPickerLargerScale() &&
592         (!(GetPreviousOrientation() == SystemProperties::GetDeviceOrientation())
593                 ? Dimension(pipeline->GetRootWidth()).ConvertToVp() >= deviceHeightLimit
594                 : Dimension(pipeline->GetRootHeight()).ConvertToVp() >= deviceHeightLimit)) {
595         buttonLayoutProperty->UpdateUserDefinedIdealSize(
596             CalcSize(width, CalcLength(calendarTheme->GetCalendarActionLargeRowHeight())));
597     } else {
598         buttonLayoutProperty->UpdateUserDefinedIdealSize(
599             CalcSize(width, CalcLength(calendarTheme->GetCalendarActionRowHeight())));
600     }
601 }
602 
UpdateButtonStyles(const std::vector<ButtonInfo> & buttonInfos,size_t index,const RefPtr<ButtonLayoutProperty> & buttonLayoutProperty,const RefPtr<RenderContext> & buttonRenderContext)603 void CalendarDialogView::UpdateButtonStyles(const std::vector<ButtonInfo>& buttonInfos, size_t index,
604     const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext)
605 {
606     if (index >= buttonInfos.size()) {
607         return;
608     }
609     CHECK_NULL_VOID(buttonLayoutProperty);
610     CHECK_NULL_VOID(buttonRenderContext);
611     auto buttonTheme = PipelineBase::GetCurrentContext()->GetTheme<ButtonTheme>();
612     CHECK_NULL_VOID(buttonTheme);
613     if (buttonInfos[index].type.has_value()) {
614         buttonLayoutProperty->UpdateType(buttonInfos[index].type.value());
615     }
616     UpdateButtonStyleAndRole(buttonInfos, index, buttonLayoutProperty, buttonRenderContext, buttonTheme);
617     if (buttonInfos[index].fontSize.has_value()) {
618         buttonLayoutProperty->UpdateFontSize(buttonInfos[index].fontSize.value());
619     }
620     if (buttonInfos[index].fontColor.has_value()) {
621         buttonLayoutProperty->UpdateFontColor(buttonInfos[index].fontColor.value());
622     }
623     if (buttonInfos[index].fontWeight.has_value()) {
624         buttonLayoutProperty->UpdateFontWeight(buttonInfos[index].fontWeight.value());
625     }
626     if (buttonInfos[index].fontStyle.has_value()) {
627         buttonLayoutProperty->UpdateFontStyle(buttonInfos[index].fontStyle.value());
628     }
629     if (buttonInfos[index].fontFamily.has_value()) {
630         buttonLayoutProperty->UpdateFontFamily(buttonInfos[index].fontFamily.value());
631     }
632     if (buttonInfos[index].borderRadius.has_value()) {
633         buttonLayoutProperty->UpdateBorderRadius(buttonInfos[index].borderRadius.value());
634     }
635     if (buttonInfos[index].backgroundColor.has_value()) {
636         buttonRenderContext->UpdateBackgroundColor(buttonInfos[index].backgroundColor.value());
637     }
638 }
639 
UpdateButtonStyleAndRole(const std::vector<ButtonInfo> & buttonInfos,size_t index,const RefPtr<ButtonLayoutProperty> & buttonLayoutProperty,const RefPtr<RenderContext> & buttonRenderContext,const RefPtr<ButtonTheme> & buttonTheme)640 void CalendarDialogView::UpdateButtonStyleAndRole(const std::vector<ButtonInfo>& buttonInfos, size_t index,
641     const RefPtr<ButtonLayoutProperty>& buttonLayoutProperty, const RefPtr<RenderContext>& buttonRenderContext,
642     const RefPtr<ButtonTheme>& buttonTheme)
643 {
644     if (index >= buttonInfos.size()) {
645         return;
646     }
647     CHECK_NULL_VOID(buttonLayoutProperty);
648     CHECK_NULL_VOID(buttonRenderContext);
649     CHECK_NULL_VOID(buttonTheme);
650     if (buttonInfos[index].role.has_value()) {
651         buttonLayoutProperty->UpdateButtonRole(buttonInfos[index].role.value());
652         ButtonStyleMode buttonStyleMode;
653         if (buttonInfos[index].buttonStyle.has_value()) {
654             buttonStyleMode = buttonInfos[index].buttonStyle.value();
655         } else {
656             buttonStyleMode = buttonLayoutProperty->GetButtonStyle().value_or(ButtonStyleMode::EMPHASIZE);
657         }
658         auto bgColor = buttonTheme->GetBgColor(buttonStyleMode, buttonInfos[index].role.value());
659         auto textColor = buttonTheme->GetTextColor(buttonStyleMode, buttonInfos[index].role.value());
660         buttonRenderContext->UpdateBackgroundColor(bgColor);
661         buttonLayoutProperty->UpdateFontColor(textColor);
662     }
663     if (buttonInfos[index].buttonStyle.has_value()) {
664         buttonLayoutProperty->UpdateButtonStyle(buttonInfos[index].buttonStyle.value());
665         ButtonRole buttonRole = buttonLayoutProperty->GetButtonRole().value_or(ButtonRole::NORMAL);
666         auto bgColor = buttonTheme->GetBgColor(buttonInfos[index].buttonStyle.value(), buttonRole);
667         auto textColor = buttonTheme->GetTextColor(buttonInfos[index].buttonStyle.value(), buttonRole);
668         buttonRenderContext->UpdateBackgroundColor(bgColor);
669         buttonLayoutProperty->UpdateFontColor(textColor);
670     }
671 }
672 
CreateConfirmNode(const RefPtr<FrameNode> & calendarNode,DialogEvent & acceptEvent,const std::vector<ButtonInfo> & buttonInfos)673 RefPtr<FrameNode> CalendarDialogView::CreateConfirmNode(
674     const RefPtr<FrameNode>& calendarNode, DialogEvent& acceptEvent, const std::vector<ButtonInfo>& buttonInfos)
675 {
676     CHECK_NULL_RETURN(calendarNode, nullptr);
677     auto buttonConfirmNode = CreateButtonNode(true, buttonInfos);
678 
679     auto eventConfirmHub = buttonConfirmNode->GetOrCreateGestureEventHub();
680     CHECK_NULL_RETURN(eventConfirmHub, nullptr);
681     SetDialogAcceptEvent(calendarNode, std::move(acceptEvent));
682     auto clickCallback = [weak = WeakPtr<FrameNode>(calendarNode)](const GestureEvent& /* info */) {
683         auto calendarNode = weak.Upgrade();
684         CHECK_NULL_VOID(calendarNode);
685         auto calendarPattern = calendarNode->GetPattern<CalendarPattern>();
686         CHECK_NULL_VOID(calendarPattern);
687         auto str = calendarPattern->GetSelectDate();
688         auto calendarEventHub = calendarNode->GetEventHub<CalendarEventHub>();
689         CHECK_NULL_VOID(calendarEventHub);
690         calendarEventHub->FireDialogAcceptEvent(str);
691     };
692     eventConfirmHub->AddClickEvent(AceType::MakeRefPtr<NG::ClickEvent>(std::move(clickCallback)));
693 
694     return buttonConfirmNode;
695 }
696 
CreateCancelNode(const NG::DialogGestureEvent & cancelEvent,const std::vector<ButtonInfo> & buttonInfos)697 RefPtr<FrameNode> CalendarDialogView::CreateCancelNode(
698     const NG::DialogGestureEvent& cancelEvent, const std::vector<ButtonInfo>& buttonInfos)
699 {
700     auto buttonCancelNode = CreateButtonNode(false, buttonInfos);
701 
702     auto eventCancelHub = buttonCancelNode->GetOrCreateGestureEventHub();
703     CHECK_NULL_RETURN(eventCancelHub, nullptr);
704     eventCancelHub->AddClickEvent(AceType::MakeRefPtr<NG::ClickEvent>(std::move(cancelEvent)));
705 
706     return buttonCancelNode;
707 }
708 
CreateDividerNode()709 RefPtr<FrameNode> CalendarDialogView::CreateDividerNode()
710 {
711     auto pipeline = PipelineContext::GetCurrentContextSafelyWithCheck();
712     CHECK_NULL_RETURN(pipeline, nullptr);
713     auto dialogTheme = pipeline->GetTheme<DialogTheme>();
714     RefPtr<CalendarTheme> theme = pipeline->GetTheme<CalendarTheme>();
715     auto dividerNode = FrameNode::GetOrCreateFrameNode(V2::DIVIDER_ETS_TAG,
716         ElementRegister::GetInstance()->MakeUniqueId(), []() { return AceType::MakeRefPtr<DividerPattern>(); });
717     auto dividerRenderContext = dividerNode->GetRenderContext();
718     CHECK_NULL_RETURN(dividerRenderContext, nullptr);
719     dividerRenderContext->UpdateBackgroundColor(Color::TRANSPARENT);
720 
721     auto dividerLayoutProperty = dividerNode->GetLayoutProperty<DividerLayoutProperty>();
722     CHECK_NULL_RETURN(dividerLayoutProperty, nullptr);
723     dividerLayoutProperty->UpdateVertical(true);
724     auto dividerRenderProperty = dividerNode->GetPaintProperty<DividerRenderProperty>();
725     CHECK_NULL_RETURN(dividerRenderProperty, nullptr);
726     dividerRenderProperty->UpdateDividerColor(
727         theme->GetIsDividerTransparent() ? Color::TRANSPARENT : theme->GetDialogDividerColor());
728 
729     dividerNode->GetLayoutProperty()->UpdateUserDefinedIdealSize(
730         CalcSize(CalcLength(dialogTheme->GetDividerWidth()), CalcLength(theme->GetEntryArrowWidth())));
731 
732     dividerNode->MarkModifyDone();
733 
734     if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) {
735         auto dividerWrapper = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG,
736             ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<LinearLayoutPattern>(false));
737         CHECK_NULL_RETURN(dividerWrapper, nullptr);
738         auto layoutProps = dividerWrapper->GetLayoutProperty<LinearLayoutProperty>();
739         CHECK_NULL_RETURN(layoutProps, nullptr);
740         layoutProps->UpdateMainAxisAlign(FlexAlign::SPACE_AROUND);
741         layoutProps->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
742         layoutProps->UpdateUserDefinedIdealSize(CalcSize(
743             CalcLength(dialogTheme->GetActionsPadding().Bottom()), CalcLength(theme->GetCalendarActionRowHeight())));
744         dividerNode->MountToParent(dividerWrapper);
745         return dividerWrapper;
746     }
747     return dividerNode;
748 }
749 
CreateOptionsNode(const RefPtr<FrameNode> & dialogNode,const RefPtr<FrameNode> & dateNode,const std::map<std::string,NG::DialogEvent> & dialogEvent,const std::map<std::string,NG::DialogGestureEvent> & dialogCancelEvent,const std::vector<ButtonInfo> & buttonInfos)750 RefPtr<FrameNode> CalendarDialogView::CreateOptionsNode(
751     const RefPtr<FrameNode>& dialogNode, const RefPtr<FrameNode>& dateNode,
752     const std::map<std::string, NG::DialogEvent>& dialogEvent,
753     const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent, const std::vector<ButtonInfo>& buttonInfos)
754 {
755     auto contentRow = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
756         AceType::MakeRefPtr<LinearLayoutPattern>(false));
757     CHECK_NULL_RETURN(contentRow, nullptr);
758     auto pipelineContext = contentRow->GetContextRefPtr();
759     CHECK_NULL_RETURN(pipelineContext, nullptr);
760     UpdateOptionLayoutProps(contentRow, pipelineContext);
761 
762     auto cancelIter = dialogCancelEvent.find("cancelId");
763     DialogGestureEvent cancelEvent = nullptr;
764     if (cancelIter != dialogCancelEvent.end()) {
765         cancelEvent = cancelIter->second;
766     }
767     auto buttonCancelNode = CreateCancelNode(cancelEvent, buttonInfos);
768     auto acceptIter = dialogEvent.find("acceptId");
769     DialogEvent acceptEvent = (acceptIter != dialogEvent.end()) ? acceptIter->second : nullptr;
770     auto buttonConfirmNode = CreateConfirmNode(dateNode, acceptEvent, buttonInfos);
771 
772     buttonCancelNode->MountToParent(contentRow);
773     buttonConfirmNode->MountToParent(contentRow);
774     UpdateDefaultFocusByButtonInfo(contentRow, buttonConfirmNode, buttonCancelNode);
775 
776     auto event = [weakDialogNode = WeakPtr<FrameNode>(dialogNode),
777                  weakPipelineContext = WeakPtr<PipelineContext>(pipelineContext)](const GestureEvent& /* info */) {
778         auto dialogNode = weakDialogNode.Upgrade();
779         CHECK_NULL_VOID(dialogNode);
780         auto pipelineContext = weakPipelineContext.Upgrade();
781         CHECK_NULL_VOID(pipelineContext);
782         auto overlayManager = pipelineContext->GetOverlayManager();
783         CHECK_NULL_VOID(overlayManager);
784         overlayManager->CloseDialog(dialogNode);
785     };
786     for (const auto& child : contentRow->GetChildren()) {
787         auto firstChild = AceType::DynamicCast<FrameNode>(child);
788         auto gesturHub = firstChild->GetOrCreateGestureEventHub();
789         auto onClick = AceType::MakeRefPtr<NG::ClickEvent>(event);
790         gesturHub->AddClickEvent(onClick);
791     }
792     contentRow->AddChild(CreateDividerNode(), 1);
793     return contentRow;
794 }
795 
UpdateOptionLayoutProps(const RefPtr<FrameNode> & contentRow,const RefPtr<PipelineContext> & pipelineContext)796 void CalendarDialogView::UpdateOptionLayoutProps(
797     const RefPtr<FrameNode>& contentRow, const RefPtr<PipelineContext>& pipelineContext)
798 {
799     auto layoutProps = contentRow->GetLayoutProperty<LinearLayoutProperty>();
800     CHECK_NULL_VOID(layoutProps);
801     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
802     CHECK_NULL_VOID(theme);
803     layoutProps->UpdateMainAxisAlign(FlexAlign::SPACE_BETWEEN);
804     layoutProps->UpdateMeasureType(MeasureType::MATCH_PARENT_MAIN_AXIS);
805     MarginProperty margin;
806     if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) {
807         margin.top = CalcLength(theme->GetCalendarActionRowTopPadding() - CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT);
808     } else {
809         margin.top = CalcLength(theme->GetCalendarActionRowTopPadding() + CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT);
810     }
811     margin.left = CalcLength(theme->GetCalendarActionRowBottomLeftRightPadding());
812     margin.right = CalcLength(theme->GetCalendarActionRowBottomLeftRightPadding());
813     margin.bottom = CalcLength(theme->GetCalendarTitleRowTopPadding() + CALENDAR_DISTANCE_ADJUST_FOCUSED_EVENT);
814     layoutProps->UpdateMargin(margin);
815     layoutProps->UpdateUserDefinedIdealSize(CalcSize(std::nullopt, CalcLength(theme->GetCalendarActionRowHeight())));
816 }
817 
SetCalendarPaintProperties(const CalendarSettingData & settingData)818 void CalendarDialogView::SetCalendarPaintProperties(const CalendarSettingData& settingData)
819 {
820     auto pipelineContext = PipelineContext::GetCurrentContextSafelyWithCheck();
821     CHECK_NULL_VOID(pipelineContext);
822     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
823     CHECK_NULL_VOID(theme);
824 
825     auto fontSizeScale = pipelineContext->GetFontScale();
826     Dimension defaultDayRadius;
827     auto fontSize = theme->GetCalendarDayFontSize();
828     if (fontSizeScale < theme->GetCalendarPickerLargeScale() || CheckOrientationChange()) {
829         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayHeight, theme->GetCalendarPickerDayWidthOrHeight());
830         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayWidth, theme->GetCalendarPickerDayWidthOrHeight());
831         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, fontSize);
832         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekHeight, theme->GetCalendarPickerDayWidthOrHeight());
833         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekWidth, theme->GetCalendarPickerDayWidthOrHeight());
834         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, fontSize);
835         defaultDayRadius = theme->GetCalendarDayRadius();
836     } else {
837         fontSizeScale = fontSizeScale > theme->GetCalendarPickerLargerScale() ? theme->GetCalendarPickerLargerScale()
838                                                                               : fontSizeScale;
839         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayHeight, theme->GetCalendarPickerDayLargeWidthOrHeight());
840         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayWidth, theme->GetCalendarPickerDayLargeWidthOrHeight());
841         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, fontSize * fontSizeScale);
842         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekHeight, theme->GetCalendarPickerDayLargeWidthOrHeight());
843         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekWidth, theme->GetCalendarPickerDayLargeWidthOrHeight());
844         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, fontSize * fontSizeScale);
845         defaultDayRadius = theme->GetCalendarPickerDayLargeWidthOrHeight() / 2;
846     }
847 
848     if (AceApplicationInfo::GetInstance().GetLanguage() != "zh") {
849         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, theme->GetCalendarSmallDayFontSize());
850     }
851 
852     if (settingData.dayRadius.has_value() && NonNegative(settingData.dayRadius.value().ConvertToPx()) &&
853         LessOrEqual(settingData.dayRadius.value().ConvertToPx(), defaultDayRadius.ConvertToPx())) {
854         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayRadius, settingData.dayRadius.value());
855     } else {
856         ACE_UPDATE_PAINT_PROPERTY(CalendarPaintProperty, DayRadius, defaultDayRadius);
857     }
858 }
859 
InitOnRequestDataEvent(const RefPtr<FrameNode> & calendarDialogNode,const RefPtr<FrameNode> & calendarNode)860 void CalendarDialogView::InitOnRequestDataEvent(
861     const RefPtr<FrameNode>& calendarDialogNode, const RefPtr<FrameNode>& calendarNode)
862 {
863     auto callback = [calendarDialogNodeWeak = WeakPtr<FrameNode>(calendarDialogNode),
864                     calendarNodeWeak = WeakPtr<FrameNode>(calendarNode)](const std::string& info) {
865         auto calendarNode = calendarNodeWeak.Upgrade();
866         CHECK_NULL_VOID(calendarNode);
867         auto calendarDialogNode = calendarDialogNodeWeak.Upgrade();
868         CHECK_NULL_VOID(calendarDialogNode);
869         auto jsonInfo = JsonUtil::ParseJsonString(info);
870         CalendarMonth currentMonth { .year = jsonInfo->GetInt("year"), .month = jsonInfo->GetInt("month") };
871         UpdateCalendarMonthData(calendarDialogNode, calendarNode, currentMonth);
872 
873         calendarNode->MarkModifyDone();
874         calendarNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
875     };
876     auto eventHub = calendarNode->GetEventHub<CalendarEventHub>();
877     CHECK_NULL_VOID(eventHub);
878     eventHub->SetOnRequestDataEvent(std::move(callback));
879 }
880 
OnSelectedChangeEvent(int32_t calendarNodeId,const std::string & callbackInfo,const DialogEvent & onChange,const CalendarSettingData & settingData)881 void CalendarDialogView::OnSelectedChangeEvent(int32_t calendarNodeId, const std::string& callbackInfo,
882     const DialogEvent& onChange, const CalendarSettingData& settingData)
883 {
884     auto calendarNode = FrameNode::GetOrCreateFrameNode(
885         V2::CALENDAR_ETS_TAG, calendarNodeId, []() { return AceType::MakeRefPtr<CalendarPattern>(); });
886     CHECK_NULL_VOID(calendarNode);
887     auto calendarPattern = calendarNode->GetPattern<CalendarPattern>();
888     CHECK_NULL_VOID(calendarPattern);
889     auto currentMonthData = calendarPattern->GetCurrentMonthData();
890     auto jsonInfo = JsonUtil::ParseJsonString(callbackInfo);
891     CalendarMonth selectedMonth { .year = jsonInfo->GetInt("year"), .month = jsonInfo->GetInt("month") };
892     if (currentMonthData.year != selectedMonth.year || currentMonthData.month != selectedMonth.month) {
893         return;
894     }
895 
896     if (onChange) {
897         onChange(callbackInfo);
898     }
899     PickerDate selectedDay(selectedMonth.year, selectedMonth.month, jsonInfo->GetInt("day"));
900     calendarPattern->SetSelectedDay(selectedDay);
901     calendarNode->MarkModifyDone();
902 
903     auto entryNode = settingData.entryNode.Upgrade();
904     CHECK_NULL_VOID(entryNode);
905     auto eventHub = entryNode->GetEventHub<CalendarPickerEventHub>();
906     CHECK_NULL_VOID(eventHub);
907     eventHub->UpdateOnChangeEvent(callbackInfo);
908 }
909 
UpdateBackgroundStyle(const RefPtr<RenderContext> & renderContext,const DialogProperties & dialogProperties)910 void CalendarDialogView::UpdateBackgroundStyle(
911     const RefPtr<RenderContext>& renderContext, const DialogProperties& dialogProperties)
912 {
913     if (Container::LessThanAPIVersion(PlatformVersion::VERSION_TWELVE)) {
914         renderContext->UpdateBackShadow(ShadowConfig::DefaultShadowS);
915     }
916 
917     if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN) && renderContext->IsUniRenderEnabled()) {
918         BlurStyleOption styleOption;
919         styleOption.blurStyle = static_cast<BlurStyle>(
920             dialogProperties.backgroundBlurStyle.value_or(static_cast<int>(BlurStyle::COMPONENT_ULTRA_THICK)));
921         renderContext->UpdateBackBlurStyle(styleOption);
922         renderContext->UpdateBackgroundColor(dialogProperties.backgroundColor.value_or(Color::TRANSPARENT));
923     }
924 }
925 
UpdateButtonDefaultFocus(const std::vector<ButtonInfo> & buttonInfos,const RefPtr<FrameNode> & buttonNode,bool isConfirm)926 void CalendarDialogView::UpdateButtonDefaultFocus(const std::vector<ButtonInfo>& buttonInfos,
927     const RefPtr<FrameNode>& buttonNode, bool isConfirm)
928 {
929     bool setDefaultFocus = false;
930     if (buttonInfos.size() > CANCEL_BUTTON_INDEX) {
931         if (buttonInfos[ACCEPT_BUTTON_INDEX].isPrimary && buttonInfos[CANCEL_BUTTON_INDEX].isPrimary) {
932             return;
933         }
934         auto index = isConfirm ? ACCEPT_BUTTON_INDEX : CANCEL_BUTTON_INDEX;
935         if (buttonInfos[index].isPrimary) {
936             setDefaultFocus = true;
937         }
938     } else if (buttonInfos.size() == CANCEL_BUTTON_INDEX) {
939         bool isAcceptButtonPrimary = (buttonInfos[0].isAcceptButton && isConfirm && buttonInfos[0].isPrimary);
940         bool isCancelButtonPrimary = (!buttonInfos[0].isAcceptButton && !isConfirm && buttonInfos[0].isPrimary);
941         if (isAcceptButtonPrimary || isCancelButtonPrimary) {
942             setDefaultFocus = true;
943         }
944     }
945     if (setDefaultFocus && buttonNode) {
946         auto focusHub = buttonNode->GetOrCreateFocusHub();
947         if (focusHub) {
948             focusHub->SetIsDefaultFocus(true);
949         }
950     }
951 }
952 
UpdateDialogDefaultFocus(const RefPtr<FrameNode> & contentRow,const RefPtr<FrameNode> & contentColumn)953 void CalendarDialogView::UpdateDialogDefaultFocus(const RefPtr<FrameNode>& contentRow,
954     const RefPtr<FrameNode>& contentColumn)
955 {
956     auto contentRowFocusHub = contentRow->GetOrCreateFocusHub();
957     CHECK_NULL_VOID(contentRowFocusHub);
958     if (contentRowFocusHub->IsDefaultFocus()) {
959         auto contentColumnFocusHub = contentColumn->GetOrCreateFocusHub();
960         CHECK_NULL_VOID(contentColumnFocusHub);
961         contentColumnFocusHub->SetIsDefaultFocus(true);
962     }
963 }
964 
UpdateDefaultFocusByButtonInfo(const RefPtr<FrameNode> & optionsNode,const RefPtr<FrameNode> & accept,const RefPtr<FrameNode> & cancel)965 void CalendarDialogView::UpdateDefaultFocusByButtonInfo(const RefPtr<FrameNode>& optionsNode,
966     const RefPtr<FrameNode>& accept, const RefPtr<FrameNode>& cancel)
967 {
968     auto acceptFocusHub = accept->GetOrCreateFocusHub();
969     CHECK_NULL_VOID(acceptFocusHub);
970     auto cancelFocusHub = cancel->GetOrCreateFocusHub();
971     CHECK_NULL_VOID(cancelFocusHub);
972     if (acceptFocusHub->IsDefaultFocus() || cancelFocusHub->IsDefaultFocus()) {
973         auto optionsNodeFocusHub = optionsNode->GetOrCreateFocusHub();
974         CHECK_NULL_VOID(optionsNodeFocusHub);
975         optionsNodeFocusHub->SetIsDefaultFocus(true);
976     }
977 }
978 
UpdateIdealSize(const RefPtr<CalendarTheme> & calendarTheme,const RefPtr<LinearLayoutProperty> & layoutProps,const RefPtr<LayoutProperty> & calendarLayoutProperty)979 void CalendarDialogView::UpdateIdealSize(const RefPtr<CalendarTheme>& calendarTheme,
980     const RefPtr<LinearLayoutProperty>& layoutProps, const RefPtr<LayoutProperty>& calendarLayoutProperty)
981 {
982     SetTitleIdealSize(calendarTheme, layoutProps);
983     SetCalendarIdealSize(calendarTheme, calendarLayoutProperty);
984 }
985 
UpdatePaintProperties(const RefPtr<FrameNode> & monthFrameNode,const CalendarSettingData & settingData)986 void CalendarDialogView::UpdatePaintProperties(
987     const RefPtr<FrameNode>& monthFrameNode, const CalendarSettingData& settingData)
988 {
989     auto pipelineContext = monthFrameNode->GetContext();
990     CHECK_NULL_VOID(pipelineContext);
991     RefPtr<CalendarTheme> theme = pipelineContext->GetTheme<CalendarTheme>();
992     CHECK_NULL_VOID(theme);
993 
994     auto fontSizeScale = pipelineContext->GetFontScale();
995     Dimension defaultDayRadius;
996     auto fontSize = theme->GetCalendarDayFontSize();
997     if (fontSizeScale < theme->GetCalendarPickerLargeScale() || CheckOrientationChange()) {
998         ACE_UPDATE_NODE_PAINT_PROPERTY(
999             CalendarPaintProperty, DayHeight, theme->GetCalendarPickerDayWidthOrHeight(), monthFrameNode);
1000         ACE_UPDATE_NODE_PAINT_PROPERTY(
1001             CalendarPaintProperty, DayWidth, theme->GetCalendarPickerDayWidthOrHeight(), monthFrameNode);
1002         ACE_UPDATE_NODE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, fontSize, monthFrameNode);
1003         ACE_UPDATE_NODE_PAINT_PROPERTY(
1004             CalendarPaintProperty, WeekHeight, theme->GetCalendarPickerDayWidthOrHeight(), monthFrameNode);
1005         ACE_UPDATE_NODE_PAINT_PROPERTY(
1006             CalendarPaintProperty, WeekWidth, theme->GetCalendarPickerDayWidthOrHeight(), monthFrameNode);
1007         ACE_UPDATE_NODE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, fontSize, monthFrameNode);
1008         defaultDayRadius = theme->GetCalendarDayRadius();
1009     } else {
1010         fontSizeScale = fontSizeScale > theme->GetCalendarPickerLargerScale() ? theme->GetCalendarPickerLargerScale()
1011                                                                               : fontSizeScale;
1012         ACE_UPDATE_NODE_PAINT_PROPERTY(
1013             CalendarPaintProperty, DayHeight, theme->GetCalendarPickerDayLargeWidthOrHeight(), monthFrameNode);
1014         ACE_UPDATE_NODE_PAINT_PROPERTY(
1015             CalendarPaintProperty, DayWidth, theme->GetCalendarPickerDayLargeWidthOrHeight(), monthFrameNode);
1016         ACE_UPDATE_NODE_PAINT_PROPERTY(CalendarPaintProperty, DayFontSize, fontSize * fontSizeScale, monthFrameNode);
1017         ACE_UPDATE_NODE_PAINT_PROPERTY(
1018             CalendarPaintProperty, WeekHeight, theme->GetCalendarPickerDayLargeWidthOrHeight(), monthFrameNode);
1019         ACE_UPDATE_NODE_PAINT_PROPERTY(
1020             CalendarPaintProperty, WeekWidth, theme->GetCalendarPickerDayLargeWidthOrHeight(), monthFrameNode);
1021         ACE_UPDATE_NODE_PAINT_PROPERTY(CalendarPaintProperty, WeekFontSize, fontSize * fontSizeScale, monthFrameNode);
1022         defaultDayRadius = theme->GetCalendarPickerDayLargeWidthOrHeight() / 2;
1023     }
1024 
1025     if (AceApplicationInfo::GetInstance().GetLanguage() != "zh") {
1026         ACE_UPDATE_NODE_PAINT_PROPERTY(
1027             CalendarPaintProperty, WeekFontSize, theme->GetCalendarSmallDayFontSize(), monthFrameNode);
1028     }
1029 
1030     if (settingData.dayRadius.has_value() && NonNegative(settingData.dayRadius.value().ConvertToPx()) &&
1031         LessOrEqual(settingData.dayRadius.value().ConvertToPx(), defaultDayRadius.ConvertToPx())) {
1032         ACE_UPDATE_NODE_PAINT_PROPERTY(CalendarPaintProperty, DayRadius, settingData.dayRadius.value(), monthFrameNode);
1033     } else {
1034         ACE_UPDATE_NODE_PAINT_PROPERTY(CalendarPaintProperty, DayRadius, defaultDayRadius, monthFrameNode);
1035     }
1036 }
1037 
UpdateButtons(const RefPtr<FrameNode> & buttonNode,size_t buttonIndex,std::vector<ButtonInfo> & buttonInfos)1038 void CalendarDialogView::UpdateButtons(
1039     const RefPtr<FrameNode>& buttonNode, size_t buttonIndex, std::vector<ButtonInfo>& buttonInfos)
1040 {
1041     auto pipelineContext = buttonNode->GetContextRefPtr();
1042     CHECK_NULL_VOID(pipelineContext);
1043     auto calendarTheme = pipelineContext->GetTheme<CalendarTheme>();
1044     CHECK_NULL_VOID(calendarTheme);
1045     auto pickerTheme = pipelineContext->GetTheme<PickerTheme>();
1046     CHECK_NULL_VOID(pickerTheme);
1047     auto textNode = AceType::DynamicCast<FrameNode>(buttonNode->GetFirstChild());
1048     CHECK_NULL_VOID(textNode);
1049     auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
1050     CHECK_NULL_VOID(textLayoutProperty);
1051     auto fontSizeScale = pipelineContext->GetFontScale();
1052     auto fontSize = pickerTheme->GetOptionStyle(false, false).GetFontSize();
1053     if (fontSizeScale < calendarTheme->GetCalendarPickerLargeScale() || CheckOrientationChange()) {
1054         textLayoutProperty->UpdateFontSize(fontSize);
1055     } else {
1056         fontSizeScale = fontSizeScale > calendarTheme->GetCalendarPickerLargeScale()
1057                             ? calendarTheme->GetCalendarPickerLargeScale()
1058                             : fontSizeScale;
1059         textLayoutProperty->UpdateFontSize(fontSize * fontSizeScale);
1060     }
1061 
1062     CalendarDialogView::UpdateButtonLayoutProperty(buttonNode, buttonIndex, buttonInfos, pipelineContext);
1063     auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
1064     CHECK_NULL_VOID(buttonLayoutProperty);
1065     CalendarDialogView::UpdateButtonStyles(
1066         buttonInfos, buttonIndex, buttonLayoutProperty, buttonNode->GetRenderContext());
1067     buttonNode->MarkModifyDone();
1068 }
1069 } // namespace OHOS::Ace::NG
1070