• 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_COLUMN_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_COLUMN_PATTERN_H
18 
19 #include <cstdint>
20 #include <utility>
21 
22 #include "adapter/ohos/entrance/picker/picker_haptic_factory.h"
23 #include "base/i18n/localization.h"
24 #include "core/components/picker/picker_theme.h"
25 #include "core/components_ng/base/frame_node.h"
26 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
27 #include "core/components_ng/pattern/picker/datepicker_column_accessibility_property.h"
28 #include "core/components_ng/pattern/picker/datepicker_column_layout_algorithm.h"
29 #include "core/components_ng/pattern/picker/datepicker_event_hub.h"
30 #include "core/components_ng/pattern/picker/datepicker_layout_property.h"
31 #include "core/components_ng/pattern/picker/datepicker_paint_method.h"
32 #include "core/components_ng/pattern/picker/datepicker_row_layout_property.h"
33 #include "core/components_ng/pattern/picker_utils/picker_column_pattern.h"
34 #include "core/components_ng/pattern/picker_utils/picker_column_pattern_utils.h"
35 #include "core/components_ng/pattern/picker_utils/picker_layout_property.h"
36 #include "core/components_ng/pattern/picker_utils/toss_animation_controller.h"
37 #include "core/components_ng/pattern/text/text_layout_property.h"
38 #include "core/pipeline_ng/ui_task_scheduler.h"
39 
40 namespace OHOS::Ace::NG {
41 
42 class DatePickerColumnPattern : public PickerColumnPattern {
43     DECLARE_ACE_TYPE(DatePickerColumnPattern, PickerColumnPattern);
44 
45 public:
DatePickerColumnPattern()46     DatePickerColumnPattern() : PickerColumnPattern(true) {};
47     virtual ~DatePickerColumnPattern() = default;
48 
CreateLayoutAlgorithm()49     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
50     {
51         auto layoutAlgorithm = MakeRefPtr<DatePickerColumnLayoutAlgorithm>();
52         if (algorithmOffset_.size() == 0) {
53             ResetAlgorithmOffset();
54         }
55         layoutAlgorithm->SetCurrentOffset(algorithmOffset_);
56         return layoutAlgorithm;
57     }
58 
CreateLayoutProperty()59     RefPtr<LayoutProperty> CreateLayoutProperty() override
60     {
61         return MakeRefPtr<DataPickerLayoutProperty>();
62     }
63 
CreateAccessibilityProperty()64     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
65     {
66         return MakeRefPtr<DatePickerColumnAccessibilityProperty>();
67     }
68 
69     void FlushCurrentOptions(bool isDown = false, bool isUpateTextContentOnly = false,
70         bool isUpdateAnimationProperties = false, bool isTossPlaying = false) override;
71 
72     void UpdateColumnChildPosition(double offsetY) override;
73     bool CanMove(bool isDown) const override;
74     bool IsTossNeedToStop() override;
75     bool GetCanLoopFromLayoutProperty() const override;
76 
GetOptions()77     const std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>>& GetOptions() const
78     {
79         return options_;
80     }
81 
SetOptions(const std::map<WeakPtr<FrameNode>,std::vector<PickerDateF>> & value)82     void SetOptions(const std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>>& value)
83     {
84         options_ = value;
85     }
86 
SetShowCount(const uint32_t showCount)87     void SetShowCount(const uint32_t showCount)
88     {
89         showCount_ = showCount;
90     }
91 
GetButtonBgColor()92     const Color& GetButtonBgColor() const override
93     {
94         return buttonBgColor_;
95     }
96 
GetButtonPressColor()97     const Color& GetButtonPressColor() const override
98     {
99         return pressColor_;
100     }
101 
102     void UpdateColumnButtonFocusState(bool haveFocus, bool needMarkDirty);
103     void InitHapticController(const RefPtr<FrameNode>& host) override;
104 
105     std::string GetCurrentOption() const override;
106 
107 private:
108     void OnModifyDone() override;
109     void SetDividerHeight(uint32_t showOptionCount);
110     void InitSelectorButtonProperties(const RefPtr<PickerTheme>& pickerTheme);
111     void UpdateSelectorButtonProps(bool haveFocus, bool needMarkDirty);
112     const Color& GetButtonHoverColor() const override;
113     void UpdateTextAreaPadding(const RefPtr<PickerTheme>& pickerTheme,
114         const RefPtr<TextLayoutProperty>& textLayoutProperty);
115     int32_t CalcScrollIndex(int32_t totalOptionCount, int32_t currentIndex, bool canLoop, int32_t step);
116     void UpdateSelectedTextColor(const RefPtr<PickerTheme>& pickerTheme) override;
117     void UpdateAnimationColor(const RefPtr<PickerTheme>& pickerTheme);
118     void UpdatePickerTextProperties(uint32_t index, uint32_t showOptionCount,
119         const RefPtr<TextLayoutProperty>& textLayoutProperty,
120         const RefPtr<DataPickerRowLayoutProperty>& dataPickerRowLayoutProperty);
121     void UpdateDisappearTextProperties(const RefPtr<PickerTheme>& pickerTheme,
122         const RefPtr<TextLayoutProperty>& textLayoutProperty,
123         const RefPtr<PickerLayoutProperty>& pickerLayoutProperty) override;
124     void UpdateCandidateTextProperties(const RefPtr<PickerTheme>& pickerTheme,
125         const RefPtr<TextLayoutProperty>& textLayoutProperty,
126         const RefPtr<PickerLayoutProperty>& pickerLayoutProperty) override;
127     void UpdateSelectedTextProperties(const RefPtr<PickerTheme>& pickerTheme,
128         const RefPtr<TextLayoutProperty>& textLayoutProperty,
129         const RefPtr<PickerLayoutProperty>& pickerLayoutProperty) override;
130     void TextPropertiesLinearAnimation(const RefPtr<TextLayoutProperty>& textLayoutProperty, uint32_t index,
131         uint32_t showCount, bool isDown, double scale) override;
132     void InitTextFontFamily() override;
133     uint32_t GetOptionCount() const override;
134     bool GetOptionItemCount(uint32_t& itemCounts) override;
135     bool IsLanscape(uint32_t itemCount) override;
136 
137     std::map<WeakPtr<FrameNode>, std::vector<PickerDateF>> options_;
138     int32_t currentChildIndex_ = 0;
139     float gradientHeight_ = 0.0f;
140     float dividerHeight_ = 0.0f;
141     float dividerSpacingWidth_ = 0.0f;
142     float dividerSpacing_ = 0.0f;
143     FontWeight SelectedWeight_ = FontWeight::MEDIUM;
144     FontWeight CandidateWeight_ = FontWeight::REGULAR;
145     Color pressColor_;
146     Color hoverColor_;
147     Color buttonBgColor_ = Color::TRANSPARENT;
148     Color buttonDefaultBgColor_ = Color::TRANSPARENT;
149     Color buttonFocusBgColor_ = Color::TRANSPARENT;
150     Color buttonDefaultBorderColor_ = Color::TRANSPARENT;
151     Color buttonFocusBorderColor_ = Color::TRANSPARENT;
152     Color selectorTextFocusColor_ = Color::WHITE;
153     Dimension buttonDefaultBorderWidth_ = 0.0_vp;
154     Dimension buttonFocusBorderWidth_ = 0.0_vp;
155     bool isFirstTimeUpdateButtonProps_ = true;
156     bool hasAppCustomFont_ = false;
157     bool hasUserDefinedDisappearFontFamily_ = false;
158     bool hasUserDefinedNormalFontFamily_ = false;
159     bool hasUserDefinedSelectedFontFamily_ = false;
160     ACE_DISALLOW_COPY_AND_MOVE(DatePickerColumnPattern);
161     friend class PickerColumnPatternCircleUtils<DatePickerColumnPattern>;
162 };
163 } // namespace OHOS::Ace::NG
164 
165 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_DATE_PICKER_DATE_PICKER_COLUMN_PATTERN_H
166