• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H
18 
19 #include <optional>
20 
21 #include "core/components/common/layout/constants.h"
22 #include "core/components/picker/picker_data.h"
23 #include "core/components/picker/picker_theme.h"
24 #include "core/components_ng/base/frame_node.h"
25 #include "core/components_ng/event/event_hub.h"
26 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
27 #include "core/components_ng/pattern/pattern.h"
28 #include "core/components_ng/pattern/picker/datepicker_accessibility_property.h"
29 #include "core/components_ng/pattern/picker/datepicker_column_pattern.h"
30 #include "core/components_ng/pattern/picker/datepicker_event_hub.h"
31 #include "core/components_ng/pattern/picker/datepicker_layout_property.h"
32 #include "core/components_ng/pattern/picker/datepicker_row_layout_property.h"
33 #include "core/components_ng/pattern/text/text_pattern.h"
34 #include "core/components_ng/pattern/picker/datepicker_dialog_view.h"
35 
36 namespace OHOS::Ace::NG {
37 class InspectorFilter;
38 namespace {
39 const Dimension FOCUS_PAINT_WIDTH = 2.0_vp;
40 }
41 
42 class DatePickerPattern : public LinearLayoutPattern {
43     DECLARE_ACE_TYPE(DatePickerPattern, LinearLayoutPattern);
44 
45 public:
DatePickerPattern()46     DatePickerPattern() : LinearLayoutPattern(false) {};
47 
48     ~DatePickerPattern() override = default;
49 
IsAtomicNode()50     bool IsAtomicNode() const override
51     {
52         return true;
53     }
54 
CreateEventHub()55     RefPtr<EventHub> CreateEventHub() override
56     {
57         return MakeRefPtr<DatePickerEventHub>();
58     }
59 
CreateLayoutAlgorithm()60     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
61     {
62         return MakeRefPtr<LinearLayoutAlgorithm>();
63     }
64 
CreateLayoutProperty()65     RefPtr<LayoutProperty> CreateLayoutProperty() override
66     {
67         return MakeRefPtr<DataPickerRowLayoutProperty>();
68     }
69 
CreateNodePaintMethod()70     RefPtr<NodePaintMethod> CreateNodePaintMethod() override
71     {
72         auto paintMethod = MakeRefPtr<DatePickerPaintMethod>(WeakClaim(this));
73         paintMethod->SetEnabled(enabled_);
74         paintMethod->SetBackgroundColor(backgroundColor_);
75         return paintMethod;
76     }
77 
CreateAccessibilityProperty()78     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
79     {
80         return MakeRefPtr<DatePickerAccessibilityProperty>();
81     }
82 
SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode)83     void SetConfirmNode(WeakPtr<FrameNode> buttonConfirmNode)
84     {
85         weakButtonConfirm_ = buttonConfirmNode;
86     }
87 
SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)88     void SetCancelNode(WeakPtr<FrameNode> buttonCancelNode)
89     {
90         weakButtonCancel_ = buttonCancelNode;
91     }
92 
SetLunarSwitchTextNode(WeakPtr<FrameNode> lunarSwitchTextNode)93     void SetLunarSwitchTextNode(WeakPtr<FrameNode> lunarSwitchTextNode)
94     {
95         weakLunarSwitchText_ = lunarSwitchTextNode;
96     }
97 
OnFontConfigurationUpdate()98     void OnFontConfigurationUpdate() override
99     {
100         if (closeDialogEvent_) {
101             closeDialogEvent_();
102         }
103     }
104 
105     void OnLanguageConfigurationUpdate() override;
106 
107     void OnColorConfigurationUpdate() override;
108 
109     void SetChangeCallback(ColumnChangeCallback&& value);
110 
111     void HandleColumnChange(const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, bool needNotify);
112 
113     void SolarColumnsBuilding(const PickerDate& current);
114 
115     void LunarColumnsBuilding(const LunarDate& current);
116 
117     void SolarMonthDaysColumnsBuilding(const PickerDate& current);
118 
119     void LunarMonthDaysColumnBuilding(const LunarDate& current);
120 
121     void HandleYearChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
122 
123     void HandleMonthChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
124 
125     void HandleLunarMonthChange(bool isAdd, uint32_t index);
126 
127     void HandleLunarYearChange(bool isAdd, uint32_t index);
128 
129     void HandleSolarYearChange(bool isAdd, uint32_t index);
130 
131     LunarDate GetCurrentLunarDate(uint32_t lunarYear) const;
132 
133     void OrderCurrentLunarDate(
134         RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay) const;
135 
136     void HandleSolarMonthChange(bool isAdd, uint32_t index);
137 
138     void HandleDayChange(bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
139 
140     void HandleReduceLunarDayChange(uint32_t index);
141 
142     void HandleLunarDayChange(bool isAdd, uint32_t index);
143 
144     void HandleAddLunarDayChange(uint32_t index);
145 
146     void HandleSolarDayChange(bool isAdd, uint32_t index);
147 
148     void HandleSolarMonthDaysChange(bool isAdd, uint32_t index);
149 
150     void HandleLunarMonthDaysChange(bool isAdd, uint32_t index);
151 
152     void HandleAddLunarMonthDaysChange(uint32_t index);
153 
154     void HandleReduceLunarMonthDaysChange(uint32_t index);
155 
156     LunarDate GetCurrentLunarDateByMonthDaysColumn(uint32_t lunarYear) const;
157 
158     PickerDate GetCurrentDate() const;
159 
160     void SetEventCallback(EventCallback&& value);
161 
162     void FireChangeEvent(bool refresh);
163 
164     void FlushColumn();
165 
166     void FlushMonthDaysColumn();
167 
168     void AdjustLunarDate(LunarDate& date);
169 
170     int LunarDateCompare(const LunarDate& left, const LunarDate& right) const;
171 
172     std::unordered_map<std::string, RefPtr<FrameNode>> GetAllChildNode();
173 
174     void OrderAllChildNode(RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay);
175 
GetColumn(const int32_t & tag)176     RefPtr<FrameNode> GetColumn(const int32_t& tag) const
177     {
178         auto iter = std::find_if(datePickerColumns_.begin(), datePickerColumns_.end(), [&tag](const auto& c) {
179                 auto column = c.Upgrade();
180                 return column && column->GetId() == tag;
181             });
182         return (iter == datePickerColumns_.end()) ? nullptr : (*iter).Upgrade();
183     }
184 
SetColumn(const RefPtr<FrameNode> & value)185     void SetColumn(const RefPtr<FrameNode>& value)
186     {
187         datePickerColumns_.emplace_back(value);
188     }
189 
ClearColumn()190     void ClearColumn()
191     {
192         datePickerColumns_.clear();
193     }
194 
SetShowLunar(bool value)195     void SetShowLunar(bool value)
196     {
197         isForceUpdate_ = value != lunar_;
198         lunar_ = value;
199     }
200 
IsShowLunar()201     bool IsShowLunar() const
202     {
203         return lunar_;
204     }
205 
SetShowMonthDaysFlag(bool value)206     void SetShowMonthDaysFlag(bool value)
207     {
208         showMonthDays_ = value;
209     }
210 
ShowMonthDays()211     bool ShowMonthDays() const
212     {
213         return showMonthDays_;
214     }
215 
SetShowTimeFlag(bool value)216     void SetShowTimeFlag(bool value)
217     {
218         showTime_ = value;
219     }
220 
SetShowLunarSwitch(bool value)221     void SetShowLunarSwitch(bool value)
222     {
223         showLunarSwitch_ = value;
224     }
225 
GetShowLunarSwitch()226     bool GetShowLunarSwitch()
227     {
228         return showLunarSwitch_;
229     }
230 
GetDialogAcceptEvent()231     const EventMarker& GetDialogAcceptEvent() const
232     {
233         return OnDialogAccept_;
234     }
SetDialogAcceptEvent(const EventMarker & value)235     void SetDialogAcceptEvent(const EventMarker& value)
236     {
237         OnDialogAccept_ = value;
238     }
239 
GetDialogCancelEvent()240     const EventMarker& GetDialogCancelEvent() const
241     {
242         return OnDialogCancel_;
243     }
SetDialogCancelEvent(const EventMarker & value)244     void SetDialogCancelEvent(const EventMarker& value)
245     {
246         OnDialogCancel_ = value;
247     }
248 
GetDialogChangeEvent()249     const EventMarker& GetDialogChangeEvent() const
250     {
251         return OnDialogChange_;
252     }
SetDialogChangeEvent(const EventMarker & value)253     void SetDialogChangeEvent(const EventMarker& value)
254     {
255         OnDialogChange_ = value;
256     }
257 
SetResizePickerItemHeight(double resizePickerItemHeight)258     void SetResizePickerItemHeight(double resizePickerItemHeight)
259     {
260         resizePickerItemHeight_ = resizePickerItemHeight;
261     }
262 
GetResizePickerItemHeight()263     double GetResizePickerItemHeight() const
264     {
265         return resizePickerItemHeight_;
266     }
267 
SetResizeFlag(bool resizeFlag)268     void SetResizeFlag(bool resizeFlag)
269     {
270         resizeFlag_ = resizeFlag;
271     }
272 
GetResizeFlag()273     bool GetResizeFlag() const
274     {
275         return resizeFlag_;
276     }
277 
SetIsShowInDialog(bool isShowInDialog)278     void SetIsShowInDialog(bool isShowInDialog)
279     {
280         isShowInDialog_ = isShowInDialog;
281     }
282 
GetIsShowInDialog()283     bool GetIsShowInDialog() const
284     {
285         return isShowInDialog_;
286     }
287 
GetOptionCount(RefPtr<FrameNode> & frameNode)288     uint32_t GetOptionCount(RefPtr<FrameNode>& frameNode)
289     {
290         return options_[frameNode].size();
291     }
292 
GetOptionValue(RefPtr<FrameNode> & frameNode,uint32_t index)293     PickerDateF GetOptionValue(RefPtr<FrameNode>& frameNode, uint32_t index)
294     {
295         if (index >= GetOptionCount(frameNode)) {
296             LOGE("index out of range.");
297             return {};
298         }
299         return options_[frameNode][index];
300     }
301 
GetAllOptions(RefPtr<FrameNode> & frameNode)302     const std::vector<PickerDateF>& GetAllOptions(RefPtr<FrameNode>& frameNode)
303     {
304         return options_[frameNode];
305     }
306 
GetOptions()307     const std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>>& GetOptions() const
308     {
309         return options_;
310     }
311 
GetShowCount()312     uint32_t GetShowCount() const
313     {
314         return showCount_;
315     }
316 
SetShowCount(uint32_t showCount)317     void SetShowCount(uint32_t showCount)
318     {
319         showCount_ = showCount;
320     }
321 
SetDateOrder(std::string dateOrder)322     void SetDateOrder(std::string dateOrder)
323     {
324         dateOrder_ = dateOrder;
325     }
326 
GetYearFormatString(uint32_t year)327     static std::string GetYearFormatString(uint32_t year)
328     {
329         return PickerStringFormatter::GetYear(year);
330     }
331 
GetMonthFormatString(uint32_t month,bool isLunar,bool isLeap)332     static std::string GetMonthFormatString(uint32_t month, bool isLunar, bool isLeap)
333     {
334         if (isLunar) {
335             return PickerStringFormatter::GetLunarMonth(month, isLeap);
336         }
337         return PickerStringFormatter::GetSolarMonth(month);
338     }
339 
GetDayFormatString(uint32_t day,bool isLunar)340     static std::string GetDayFormatString(uint32_t day, bool isLunar)
341     {
342         if (isLunar) {
343             return PickerStringFormatter::GetLunarDay(day);
344         }
345         return PickerStringFormatter::GetSolarDay(day);
346     }
347 
348     uint32_t GetLunarMaxDay(uint32_t year, uint32_t month, bool isLeap) const;
349 
350     bool GetLunarLeapMonth(uint32_t year, uint32_t& outLeapMonth) const;
351 
352     LunarDate SolarToLunar(const PickerDate& date) const;
353 
354     PickerDate LunarToSolar(const LunarDate& date) const;
355 
356     void UpdateCurrentOffset(float offset);
357 
358     void OnDataLinking(
359         const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
360 
361     void HandleMonthDaysChange(
362         const RefPtr<FrameNode>& tag, bool isAdd, uint32_t index, std::vector<RefPtr<FrameNode>>& resultTags);
363 
364     std::string GetSelectedObject(bool isColumnChange, int status = -1) const;
365 
GetSelectDate()366     const LunarDate& GetSelectDate()
367     {
368         return selectedLunar_;
369     }
370 
SetSelectDate(const PickerDate & value)371     void SetSelectDate(const PickerDate& value)
372     {
373         selectedDate_ = value;
374         isFiredDateChange_ = firedDateStr_.has_value() && firedDateStr_.value() == GetSelectedObject(false);
375         firedDateStr_.reset();
376         if (selectedDate_.GetYear() <= 0) {
377             LOGW("selectedDate error");
378             selectedDate_ = PickerDate::Current();
379         }
380         AdjustSolarDate(selectedDate_, startDateSolar_, endDateSolar_);
381         selectedLunar_ = SolarToLunar(selectedDate_);
382     }
383 
GetSelectedDate()384     const PickerDate& GetSelectedDate()
385     {
386         return selectedDate_;
387     }
388 
SetStartDate(const PickerDate & value)389     void SetStartDate(const PickerDate& value)
390     {
391         startDateSolar_ = value;
392         AdjustSolarDate(startDateSolar_, limitStartDate_, limitEndDate_);
393         startDateLunar_ = SolarToLunar(startDateSolar_);
394     }
395 
GetStartDateLunar()396     const LunarDate& GetStartDateLunar()
397     {
398         return startDateLunar_;
399     }
400 
GetStartDateSolar()401     const PickerDate& GetStartDateSolar()
402     {
403         return startDateSolar_;
404     }
405 
SetEndDate(const PickerDate & value)406     void SetEndDate(const PickerDate& value)
407     {
408         endDateSolar_ = value;
409         AdjustSolarDate(endDateSolar_, limitStartDate_, limitEndDate_);
410         endDateLunar_ = SolarToLunar(endDateSolar_);
411     }
412 
GetEndDateLunar()413     const LunarDate& GetEndDateLunar()
414     {
415         return endDateLunar_;
416     }
417 
GetEndDateSolar()418     const PickerDate& GetEndDateSolar()
419     {
420         return endDateSolar_;
421     }
422 
AdjustSolarDate(PickerDate & date,const PickerDate & start,const PickerDate & end)423     void AdjustSolarDate(PickerDate& date, const PickerDate& start, const PickerDate& end) const
424     {
425         if (SolarDateCompare(date, start) < 0) {
426             date = start;
427             return;
428         }
429         if (SolarDateCompare(date, end) > 0) {
430             date = end;
431         }
432     }
433 
AdjustSolarDate(PickerDate & date)434     void AdjustSolarDate(PickerDate& date) const
435     {
436         AdjustSolarDate(date, startDateSolar_, endDateSolar_);
437     }
438 
SolarDateCompare(const PickerDate & left,const PickerDate & right)439     static int SolarDateCompare(const PickerDate& left, const PickerDate& right)
440     {
441         static const int leftEqualRight = 0; // means left = right
442         static const int leftGreatRight = 1; // means left > right
443         static const int leftLessRight = -1; // means left < right
444         if (left.GetYear() > right.GetYear()) {
445             return leftGreatRight;
446         }
447         if (left.GetYear() < right.GetYear()) {
448             return leftLessRight;
449         }
450         if (left.GetMonth() > right.GetMonth()) {
451             return leftGreatRight;
452         }
453         if (left.GetMonth() < right.GetMonth()) {
454             return leftLessRight;
455         }
456         if (left.GetDay() > right.GetDay()) {
457             return leftGreatRight;
458         }
459         if (left.GetDay() < right.GetDay()) {
460             return leftLessRight;
461         }
462         return leftEqualRight;
463     }
464 
HasYearNode()465     bool HasYearNode() const
466     {
467         return yearId_.has_value();
468     }
469 
GetYearId()470     int32_t GetYearId()
471     {
472         if (!yearId_.has_value()) {
473             yearId_ = ElementRegister::GetInstance()->MakeUniqueId();
474         }
475         return yearId_.value();
476     }
477 
HasMonthNode()478     bool HasMonthNode() const
479     {
480         return monthId_.has_value();
481     }
482 
GetMonthId()483     int32_t GetMonthId()
484     {
485         if (!monthId_.has_value()) {
486             monthId_ = ElementRegister::GetInstance()->MakeUniqueId();
487         }
488         return monthId_.value();
489     }
490 
HasDayNode()491     bool HasDayNode() const
492     {
493         return dayId_.has_value();
494     }
495 
GetDayId()496     int32_t GetDayId()
497     {
498         if (!dayId_.has_value()) {
499             dayId_ = ElementRegister::GetInstance()->MakeUniqueId();
500         }
501         return dayId_.value();
502     }
503 
HasMonthDaysNode()504     bool HasMonthDaysNode() const
505     {
506         return monthDaysId_.has_value();
507     }
508 
GetMonthDaysId()509     int32_t GetMonthDaysId()
510     {
511         if (!monthDaysId_.has_value()) {
512             monthDaysId_ = ElementRegister::GetInstance()->MakeUniqueId();
513         }
514         return monthDaysId_.value();
515     }
516 
HasTitleNode()517     bool HasTitleNode() const
518     {
519         return titleId_.has_value();
520     }
521 
SetTitleId(const int32_t id)522     bool SetTitleId(const int32_t id)
523     {
524         if (HasTitleNode()) {
525             return false;
526         }
527         titleId_ = id;
528         return true;
529     }
530 
GetTitleId()531     int32_t GetTitleId()
532     {
533         if (!titleId_.has_value()) {
534             titleId_ = ElementRegister::GetInstance()->MakeUniqueId();
535         }
536         return titleId_.value();
537     }
538 
HasButtonTitleNode()539     bool HasButtonTitleNode() const
540     {
541         return ButtonTitleId_.has_value();
542     }
543 
GetButtonTitleId()544     int32_t GetButtonTitleId()
545     {
546         if (!ButtonTitleId_.has_value()) {
547             ButtonTitleId_ = ElementRegister::GetInstance()->MakeUniqueId();
548         }
549         return ButtonTitleId_.value();
550     }
551 
HasDividerNode()552     bool HasDividerNode() const
553     {
554         return DividerId_.has_value();
555     }
556 
GetDividerId()557     int32_t GetDividerId()
558     {
559         if (!DividerId_.has_value()) {
560             DividerId_ = ElementRegister::GetInstance()->MakeUniqueId();
561         }
562         return DividerId_.value();
563     }
564 
SetBackgroundColor(const Color & color)565     void SetBackgroundColor(const Color& color)
566     {
567         backgroundColor_ = color;
568     }
569 
570     static const std::string& GetYear(uint32_t year);
571 
572     static const std::string& GetSolarMonth(uint32_t month);
573 
574     static const std::string& GetSolarDay(uint32_t day);
575 
576     static const std::string& GetLunarMonth(uint32_t month, bool isLeap);
577 
578     static const std::string& GetLunarDay(uint32_t day);
579 
GetFocusPattern()580     FocusPattern GetFocusPattern() const override
581     {
582         auto pipeline = PipelineBase::GetCurrentContext();
583         CHECK_NULL_RETURN(pipeline, FocusPattern());
584         auto pickerTheme = pipeline->GetTheme<PickerTheme>();
585         CHECK_NULL_RETURN(pickerTheme, FocusPattern());
586         auto focusColor = pickerTheme->GetFocusColor();
587         FocusPaintParam focusPaintParams;
588         focusPaintParams.SetPaintColor(focusColor);
589         focusPaintParams.SetPaintWidth(FOCUS_PAINT_WIDTH);
590         return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION, focusPaintParams };
591     }
592 
593     void ShowTitle(int32_t titleId);
594     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override;
SetContentRowNode(RefPtr<FrameNode> & contentRowNode)595     void SetContentRowNode(RefPtr<FrameNode>& contentRowNode)
596     {
597         contentRowNode_ = contentRowNode;
598     }
SetbuttonTitleNode(RefPtr<FrameNode> & buttonTitleNode)599     void SetbuttonTitleNode(RefPtr<FrameNode>& buttonTitleNode)
600     {
601         buttonTitleNode_ = buttonTitleNode;
602     }
603 
SetPickerTag(bool isPicker)604     void SetPickerTag(bool isPicker)
605     {
606         isPicker_ = isPicker;
607     }
608 
609     void SetFocusDisable();
610     void SetFocusEnable();
611     static const std::string GetFormatString(PickerDateF data);
612 
HasUserDefinedDisappearFontFamily(bool isUserDefined)613     void HasUserDefinedDisappearFontFamily(bool isUserDefined)
614     {
615         hasUserDefinedDisappearFontFamily_ = isUserDefined;
616     }
617 
GetHasUserDefinedDisappearFontFamily()618     bool GetHasUserDefinedDisappearFontFamily()
619     {
620         return hasUserDefinedDisappearFontFamily_;
621     }
622 
HasUserDefinedNormalFontFamily(bool isUserDefined)623     void HasUserDefinedNormalFontFamily(bool isUserDefined)
624     {
625         hasUserDefinedNormalFontFamily_ = isUserDefined;
626     }
627 
GetHasUserDefinedNormalFontFamily()628     bool GetHasUserDefinedNormalFontFamily()
629     {
630         return hasUserDefinedNormalFontFamily_;
631     }
632 
HasUserDefinedSelectedFontFamily(bool isUserDefined)633     void HasUserDefinedSelectedFontFamily(bool isUserDefined)
634     {
635         hasUserDefinedSelectedFontFamily_ = isUserDefined;
636     }
637 
GetHasUserDefinedSelectedFontFamily()638     bool GetHasUserDefinedSelectedFontFamily()
639     {
640         return hasUserDefinedSelectedFontFamily_;
641     }
642 
updateFontConfigurationEvent(const std::function<void ()> & closeDialogEvent)643     void updateFontConfigurationEvent(const std::function<void()>& closeDialogEvent)
644     {
645         closeDialogEvent_ = closeDialogEvent;
646     }
647 
GetTextProperties()648     const PickerTextProperties& GetTextProperties() const
649     {
650         return textProperties_;
651     }
652 
SetTextProperties(const PickerTextProperties & properties)653     void SetTextProperties(const PickerTextProperties& properties)
654     {
655         textProperties_ = properties;
656         if (properties.disappearTextStyle_.fontSize.has_value() && properties.disappearTextStyle_.fontSize->IsValid()) {
657             isUserSetGradientFont_ = true;
658             gradientHeight_ = properties.disappearTextStyle_.fontSize.value();
659         }
660 
661         if (properties.normalTextStyle_.fontSize.has_value() && properties.normalTextStyle_.fontSize->IsValid()) {
662             isUserSetGradientFont_ = true;
663             gradientHeight_ = std::max(properties.normalTextStyle_.fontSize.value(), gradientHeight_);
664         }
665 
666         if (properties.selectedTextStyle_.fontSize.has_value() && properties.selectedTextStyle_.fontSize->IsValid()) {
667             isUserSetDividerSpacingFont_ = true;
668             dividerSpacing_ = properties.selectedTextStyle_.fontSize.value();
669         }
670     }
671 
GetIsUserSetDividerSpacingFont()672     bool GetIsUserSetDividerSpacingFont()
673     {
674         return isUserSetDividerSpacingFont_;
675     }
676 
GetIsUserSetGradientFont()677     bool GetIsUserSetGradientFont()
678     {
679         return isUserSetGradientFont_;
680     }
681 
GetDividerSpacing()682     Dimension GetDividerSpacing()
683     {
684         return dividerSpacing_;
685     }
686 
GetGradientHeight()687     Dimension GetGradientHeight()
688     {
689         return gradientHeight_;
690     }
691 
SetPaintDividerSpacing(float & value)692     void SetPaintDividerSpacing(float& value)
693     {
694         paintDividerSpacing_ = value;
695     }
696 
GetPaintDividerSpacing()697     float GetPaintDividerSpacing()
698     {
699         return paintDividerSpacing_;
700     }
701 
SetUserDefinedOpacity(double opacity)702     void SetUserDefinedOpacity(double opacity)
703     {
704         curOpacity_ = opacity;
705     }
706 
707 private:
708     void OnModifyDone() override;
709     void OnAttachToFrameNode() override;
710     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
711     static void Init();
712     void InitDisabled();
713     void GetInnerFocusPaintRect(RoundRect& paintRect);
714     void PaintFocusState();
715     void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
716     bool OnKeyEvent(const KeyEvent& event);
717     bool HandleDirectionKey(KeyCode code);
718     PickerDate GetCurrentDateByMonthDaysColumn() const;
719     PickerDate GetCurrentDateByYearMonthDayColumn() const;
720     void OrderCurrentDateByYearMonthDayColumn(
721         RefPtr<FrameNode>& stackYear, RefPtr<FrameNode>& stackMonth, RefPtr<FrameNode>& stackDay) const;
722     void FillSolarYearOptions(const PickerDate& current, RefPtr<FrameNode>& yearColumn);
723     void UpdateTitleTextColor(const RefPtr<FrameNode>& buttonTitleNode, const RefPtr<PickerTheme>& pickerTheme);
724     void FillLunarMonthDaysOptions(const LunarDate& current, RefPtr<FrameNode>& monthDaysColumn);
725     void AdjustSolarStartEndDate();
726     void AdjustLunarStartEndDate();
727     void FlushChildNodes();
728 
729     RefPtr<ClickEvent> clickEventListener_;
730     bool enabled_ = true;
731     int32_t focusKeyID_ = 0;
732     std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>> options_;
733     uint32_t showCount_ = 0;
734     std::string dateOrder_ = "";
735     std::vector<WeakPtr<FrameNode>> datePickerColumns_;
736     bool lunar_ = false;
737     bool showMonthDays_ = false;
738     bool showTime_ = false;
739     bool showLunarSwitch_ = false;
740     Color backgroundColor_ = Color::WHITE;
741     std::optional<int32_t> yearId_;
742     std::optional<int32_t> monthId_;
743     std::optional<int32_t> dayId_;
744     std::optional<int32_t> monthDaysId_;
745     std::optional<int32_t> dateNodeId_;
746     std::optional<int32_t> titleId_;
747     std::optional<int32_t> ButtonTitleId_;
748     std::optional<int32_t> DividerId_;
749     double resizePickerItemHeight_ = 0.0;
750     bool resizeFlag_ = false;
751     bool isShowInDialog_ = false;
752     EventMarker OnDialogAccept_;
753     EventMarker OnDialogCancel_;
754     EventMarker OnDialogChange_;
755     WeakPtr<FrameNode> weakButtonConfirm_;
756     WeakPtr<FrameNode> weakButtonCancel_;
757     WeakPtr<FrameNode> weakLunarSwitchText_;
758     PickerDate startDateSolar_ = PickerDate(1970, 1, 1); // default start date is 1970-1-1 from FA document.
759     LunarDate startDateLunar_;
760     PickerDate endDateSolar_ = PickerDate(2100, 12, 31); // default end date is 2100-12-31 from FA document.
761     LunarDate endDateLunar_;
762     PickerDate selectedDate_ = PickerDate::Current();
763     LunarDate selectedLunar_;
764     PickerDate startDefaultDateSolar_ = PickerDate(1970, 1, 1); // default start date is 1970-1-1 from FA document.
765     PickerDate endDefaultDateSolar_ = PickerDate(2100, 12, 31); // default end date is 2100-12-31 from FA document.
766     const PickerDate limitStartDate_ = PickerDate(1900, 1, 31);
767     const PickerDate limitEndDate_ = PickerDate(2100, 12, 31);
768     static bool inited_;
769     static const std::string empty_;
770     static const PickerDateF emptyPickerDate_;
771     static std::unordered_map<uint32_t, std::string> years_;       // year from 1900 to 2100,count is 201
772     static std::unordered_map<uint32_t, std::string> solarMonths_; // solar month from 1 to 12,count is 12
773     static std::unordered_map<uint32_t, std::string> solarDays_;   // solar day from 1 to 31, count is 31
774     static std::unordered_map<uint32_t, std::string> lunarMonths_; // lunar month from 1 to 24, count is 24
775     static std::unordered_map<uint32_t, std::string> lunarDays_;   // lunar day from 1 to 30, count is 30
776     static std::vector<std::string> tagOrder_;    // year month day tag order
777     static std::vector<std::string> localizedMonths_;
778     WeakPtr<FrameNode> contentRowNode_;
779     WeakPtr<FrameNode> buttonTitleNode_;
780     bool isPicker_ = false;
781     bool isFiredDateChange_ = false;
782     bool isForceUpdate_ = false;
783     std::optional<std::string> firedDateStr_;
784 
785     bool hasUserDefinedDisappearFontFamily_ = false;
786     bool hasUserDefinedNormalFontFamily_ = false;
787     bool hasUserDefinedSelectedFontFamily_ = false;
788     std::function<void()> closeDialogEvent_;
789     bool isUserSetDividerSpacingFont_ = false;
790     bool isUserSetGradientFont_ = false;
791     Dimension gradientHeight_;
792     Dimension dividerSpacing_;
793     float paintDividerSpacing_ = 1.0f;
794     PickerTextProperties textProperties_;
795     double curOpacity_ = 1.0;
796 
797     ACE_DISALLOW_COPY_AND_MOVE(DatePickerPattern);
798 };
799 } // namespace OHOS::Ace::NG
800 
801 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_PATTERN_H
802