• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "core/components_ng/pattern/text_picker/textpicker_model_ng.h"
17 
18 #include <securec.h>
19 
20 #include "base/geometry/dimension.h"
21 #include "base/geometry/ng/size_t.h"
22 #include "base/utils/utils.h"
23 #include "core/components_ng/base/frame_node.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/image/image_pattern.h"
27 #include "core/components_ng/pattern/picker/picker_type_define.h"
28 #include "core/components_ng/pattern/stack/stack_pattern.h"
29 #include "core/components_ng/pattern/text/text_pattern.h"
30 #include "core/components_ng/pattern/text_picker/textpicker_column_pattern.h"
31 #include "core/components_ng/pattern/text_picker/textpicker_event_hub.h"
32 #include "core/components_ng/pattern/text_picker/textpicker_layout_property.h"
33 #include "core/components_ng/pattern/text_picker/textpicker_pattern.h"
34 #include "core/components_v2/inspector/inspector_constants.h"
35 #include "core/pipeline_ng/pipeline_context.h"
36 
37 namespace OHOS::Ace::NG {
38 namespace {
39 constexpr float PICKER_MAXFONTSCALE = 1.0f;
40 const int32_t BUFFER_NODE_NUMBER = 2;
41 
SetDialogProperties(DialogProperties & properties,TextPickerDialog & textPickerDialog,const RefPtr<DialogTheme> & theme)42 void SetDialogProperties(DialogProperties& properties, TextPickerDialog& textPickerDialog,
43                          const RefPtr<DialogTheme>& theme)
44 {
45     if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
46         properties.alignment = theme->GetAlignment();
47     }
48     if (textPickerDialog.alignment.has_value()) {
49         properties.alignment = textPickerDialog.alignment.value();
50     }
51 
52     if (textPickerDialog.backgroundColor.has_value()) {
53         properties.backgroundColor = textPickerDialog.backgroundColor.value();
54     }
55     if (textPickerDialog.backgroundBlurStyle.has_value()) {
56         properties.backgroundBlurStyle = textPickerDialog.backgroundBlurStyle.value();
57     }
58     if (textPickerDialog.shadow.has_value()) {
59         properties.shadow = textPickerDialog.shadow.value();
60     }
61     properties.customStyle = false;
62     if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
63         properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
64     }
65     if (textPickerDialog.offset.has_value()) {
66         properties.offset = textPickerDialog.offset.value();
67     }
68 
69     properties.maskRect = textPickerDialog.maskRect;
70 }
71 }
72 
Create(RefPtr<PickerTheme> pickerTheme,uint32_t columnKind)73 void TextPickerModelNG::Create(RefPtr<PickerTheme> pickerTheme, uint32_t columnKind)
74 {
75     auto* stack = ViewStackProcessor::GetInstance();
76     auto nodeId = stack->ClaimNodeId();
77     ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::TEXT_PICKER_ETS_TAG, nodeId);
78     auto textPickerNode = FrameNode::GetOrCreateFrameNode(
79         V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
80     auto textPickerPattern = textPickerNode->GetPattern<TextPickerPattern>();
81     CHECK_NULL_VOID(textPickerPattern);
82     textPickerPattern->SetColumnsKind(columnKind);
83     auto pipeline = PipelineBase::GetCurrentContext();
84     CHECK_NULL_VOID(pipeline);
85     auto dialogTheme = pipeline->GetTheme<DialogTheme>();
86     CHECK_NULL_VOID(dialogTheme);
87     textPickerPattern->SetBackgroundColor(dialogTheme->GetBackgroundColor());
88     CHECK_NULL_VOID(pickerTheme);
89     uint32_t showCount = pickerTheme->GetShowOptionCount() + BUFFER_NODE_NUMBER;
90 
91     if (textPickerNode->GetChildren().empty()) {
92         auto columnNode = CreateColumnNode(columnKind, showCount);
93         auto stackNode = CreateStackNode();
94         auto buttonNode = CreateButtonNode();
95         auto columnBlendNode = CreateColumnNode();
96         buttonNode->MountToParent(stackNode);
97         columnNode->MountToParent(columnBlendNode);
98         columnBlendNode->MountToParent(stackNode);
99         columnNode->MarkModifyDone();
100         columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
101         auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
102         layoutProperty->UpdateAlignment(Alignment::CENTER);
103         stackNode->MountToParent(textPickerNode);
104     }
105     stack->Push(textPickerNode);
106     options_.clear();
107 }
108 
SetDefaultAttributes(const RefPtr<PickerTheme> & pickerTheme)109 void TextPickerModelNG::SetDefaultAttributes(const RefPtr<PickerTheme>& pickerTheme)
110 {
111     CHECK_NULL_VOID(pickerTheme);
112     auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
113     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize, selectedStyle.GetFontSize());
114     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedColor, selectedStyle.GetTextColor());
115     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedWeight, selectedStyle.GetFontWeight());
116     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontFamily, selectedStyle.GetFontFamilies());
117     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontStyle, selectedStyle.GetFontStyle());
118 
119     auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
120     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
121         ConvertFontScaleValue(disappearStyle.GetFontSize()));
122     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearColor, disappearStyle.GetTextColor());
123     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearWeight, disappearStyle.GetFontWeight());
124     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontFamily, disappearStyle.GetFontFamilies());
125     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontStyle, disappearStyle.GetFontStyle());
126 
127     auto normalStyle = pickerTheme->GetOptionStyle(false, false);
128     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
129         ConvertFontScaleValue(normalStyle.GetFontSize()));
130     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Color, normalStyle.GetTextColor());
131     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Weight, normalStyle.GetFontWeight());
132     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontFamily, normalStyle.GetFontFamilies());
133     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontStyle, normalStyle.GetFontStyle());
134 
135     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, true);
136 }
137 
CreateColumnNode(uint32_t columnKind,uint32_t showCount)138 RefPtr<FrameNode> TextPickerModelNG::CreateColumnNode(uint32_t columnKind, uint32_t showCount)
139 {
140     auto columnNode =
141         FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
142         []() { return AceType::MakeRefPtr<TextPickerColumnPattern>(); });
143     if (columnKind == ICON) {
144         for (uint32_t index = 0; index < showCount; index++) {
145             auto row = FrameNode::CreateFrameNode(
146                 V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
147                 AceType::MakeRefPtr<LinearLayoutPattern>(false));
148             CHECK_NULL_RETURN(row, nullptr);
149             auto layoutProps = row->GetLayoutProperty<LinearLayoutProperty>();
150             CHECK_NULL_RETURN(layoutProps, nullptr);
151             layoutProps->UpdateMainAxisAlign(FlexAlign::CENTER);
152             layoutProps->UpdateCrossAxisAlign(FlexAlign::CENTER);
153 
154             auto imageNode = FrameNode::CreateFrameNode(
155                 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
156                 AceType::MakeRefPtr<ImagePattern>());
157             CHECK_NULL_RETURN(imageNode, nullptr);
158             imageNode->MountToParent(row);
159             row->MountToParent(columnNode);
160         }
161     } else if (columnKind == TEXT) {
162         for (uint32_t index = 0; index < showCount; index++) {
163             auto textNode = FrameNode::CreateFrameNode(
164                 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
165                 AceType::MakeRefPtr<TextPattern>());
166             CHECK_NULL_RETURN(textNode, nullptr);
167             textNode->MountToParent(columnNode);
168         }
169     } else if (columnKind == MIXTURE) {
170         for (uint32_t index = 0; index < showCount; index++) {
171             auto row = FrameNode::CreateFrameNode(
172                 V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
173                 AceType::MakeRefPtr<LinearLayoutPattern>(false));
174             CHECK_NULL_RETURN(row, nullptr);
175 
176             auto imageNode = FrameNode::CreateFrameNode(
177                 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
178                 AceType::MakeRefPtr<ImagePattern>());
179             CHECK_NULL_RETURN(imageNode, nullptr);
180             imageNode->MountToParent(row);
181 
182             auto textNode = FrameNode::CreateFrameNode(
183                 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
184                 AceType::MakeRefPtr<TextPattern>());
185             CHECK_NULL_RETURN(textNode, nullptr);
186             textNode->MountToParent(row);
187             row->MountToParent(columnNode);
188         }
189     }
190     return columnNode;
191 }
192 
CreateStackNode()193 RefPtr<FrameNode> TextPickerModelNG::CreateStackNode()
194 {
195     auto stackId = ElementRegister::GetInstance()->MakeUniqueId();
196     return FrameNode::GetOrCreateFrameNode(
197         V2::STACK_ETS_TAG, stackId, []() { return AceType::MakeRefPtr<StackPattern>(); });
198 }
199 
CreateColumnNode()200 RefPtr<FrameNode> TextPickerModelNG::CreateColumnNode()
201 {
202     auto columnId = ElementRegister::GetInstance()->MakeUniqueId();
203     return FrameNode::GetOrCreateFrameNode(
204         V2::COLUMN_ETS_TAG, columnId, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
205 }
206 
CreateButtonNode()207 RefPtr<FrameNode> TextPickerModelNG::CreateButtonNode()
208 {
209     auto buttonId = ElementRegister::GetInstance()->MakeUniqueId();
210     return FrameNode::GetOrCreateFrameNode(
211         V2::BUTTON_ETS_TAG, buttonId, []() { return AceType::MakeRefPtr<ButtonPattern>(); });
212 }
213 
CreateFrameNode(int32_t nodeId)214 RefPtr<FrameNode> TextPickerModelNG::CreateFrameNode(int32_t nodeId)
215 {
216     auto textPickerNode = FrameNode::GetOrCreateFrameNode(
217         V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
218     auto textPickerPattern = textPickerNode->GetPattern<TextPickerPattern>();
219     textPickerPattern->SetColumnsKind(TEXT);
220     auto pipeline = PipelineBase::GetCurrentContextSafely();
221     CHECK_NULL_RETURN(pipeline, textPickerNode);
222     auto pickerTheme = pipeline->GetTheme<PickerTheme>();
223     CHECK_NULL_RETURN(pickerTheme, textPickerNode);
224     showCount_ = BUFFER_NODE_NUMBER + pickerTheme->GetShowOptionCount();
225     rangeValue_.clear();
226     SetDefaultAttributes(textPickerNode, pickerTheme);
227     return textPickerNode;
228 }
229 
SetSelected(uint32_t value)230 void TextPickerModelNG::SetSelected(uint32_t value)
231 {
232     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
233     CHECK_NULL_VOID(frameNode);
234     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
235     textPickerPattern->SetSelected(value);
236     std::vector<uint32_t> values;
237     values.emplace_back(value);
238     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selected, value);
239     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values);
240 }
241 
SetRange(const std::vector<NG::RangeContent> & value)242 void TextPickerModelNG::SetRange(const std::vector<NG::RangeContent>& value)
243 {
244     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
245     CHECK_NULL_VOID(frameNode);
246     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
247     textPickerPattern->SetRange(value);
248     for (auto& range : value) {
249         rangeValue_.emplace_back(std::move(range));
250     }
251 }
252 
SetDefaultPickerItemHeight(const Dimension & value)253 void TextPickerModelNG::SetDefaultPickerItemHeight(const Dimension& value)
254 {
255     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultPickerItemHeight, value);
256 }
257 
SetGradientHeight(const Dimension & value)258 void TextPickerModelNG::SetGradientHeight(const Dimension& value)
259 {
260     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
261     CHECK_NULL_VOID(frameNode);
262     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
263     CHECK_NULL_VOID(textPickerPattern);
264     textPickerPattern->SetGradientHeight(value);
265     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, GradientHeight, value);
266 }
267 
SetCanLoop(const bool value)268 void TextPickerModelNG::SetCanLoop(const bool value)
269 {
270     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
271     CHECK_NULL_VOID(frameNode);
272     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
273     CHECK_NULL_VOID(textPickerPattern);
274     textPickerPattern->SetCanLoop(value);
275     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, value);
276 }
277 
SetBackgroundColor(const Color & color)278 void TextPickerModelNG::SetBackgroundColor(const Color& color)
279 {
280     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
281     CHECK_NULL_VOID(frameNode);
282     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
283     CHECK_NULL_VOID(textPickerPattern);
284     textPickerPattern->SetBackgroundColor(color);
285 }
286 
SetDisappearTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)287 void TextPickerModelNG::SetDisappearTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
288 {
289     CHECK_NULL_VOID(pickerTheme);
290     auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
291     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
292         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
293             ConvertFontScaleValue(value.fontSize.value()));
294     } else {
295         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
296             ConvertFontScaleValue(disappearStyle.GetFontSize()));
297     }
298     ACE_UPDATE_LAYOUT_PROPERTY(
299         TextPickerLayoutProperty, DisappearColor, value.textColor.value_or(disappearStyle.GetTextColor()));
300     ACE_UPDATE_LAYOUT_PROPERTY(
301         TextPickerLayoutProperty, DisappearWeight, value.fontWeight.value_or(disappearStyle.GetFontWeight()));
302     ACE_UPDATE_LAYOUT_PROPERTY(
303         TextPickerLayoutProperty, DisappearFontFamily, value.fontFamily.value_or(disappearStyle.GetFontFamilies()));
304     ACE_UPDATE_LAYOUT_PROPERTY(
305         TextPickerLayoutProperty, DisappearFontStyle, value.fontStyle.value_or(disappearStyle.GetFontStyle()));
306 }
307 
SetNormalTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)308 void TextPickerModelNG::SetNormalTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
309 {
310     CHECK_NULL_VOID(pickerTheme);
311     auto normalStyle = pickerTheme->GetOptionStyle(false, false);
312     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
313         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
314             ConvertFontScaleValue(value.fontSize.value()));
315     } else {
316         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
317             ConvertFontScaleValue(normalStyle.GetFontSize()));
318     }
319     ACE_UPDATE_LAYOUT_PROPERTY(
320         TextPickerLayoutProperty, Color, value.textColor.value_or(normalStyle.GetTextColor()));
321     ACE_UPDATE_LAYOUT_PROPERTY(
322         TextPickerLayoutProperty, Weight, value.fontWeight.value_or(normalStyle.GetFontWeight()));
323     ACE_UPDATE_LAYOUT_PROPERTY(
324         TextPickerLayoutProperty, FontFamily, value.fontFamily.value_or(normalStyle.GetFontFamilies()));
325     ACE_UPDATE_LAYOUT_PROPERTY(
326         TextPickerLayoutProperty, FontStyle, value.fontStyle.value_or(normalStyle.GetFontStyle()));
327 }
328 
SetSelectedTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)329 void TextPickerModelNG::SetSelectedTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
330 {
331     CHECK_NULL_VOID(pickerTheme);
332     auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
333     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
334         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
335             ConvertFontScaleValue(value.fontSize.value()));
336     } else {
337         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
338             ConvertFontScaleValue(selectedStyle.GetFontSize()));
339     }
340     ACE_UPDATE_LAYOUT_PROPERTY(
341         TextPickerLayoutProperty, SelectedColor, value.textColor.value_or(selectedStyle.GetTextColor()));
342     ACE_UPDATE_LAYOUT_PROPERTY(
343         TextPickerLayoutProperty, SelectedWeight, value.fontWeight.value_or(selectedStyle.GetFontWeight()));
344     ACE_UPDATE_LAYOUT_PROPERTY(
345         TextPickerLayoutProperty, SelectedFontFamily, value.fontFamily.value_or(selectedStyle.GetFontFamilies()));
346     ACE_UPDATE_LAYOUT_PROPERTY(
347         TextPickerLayoutProperty, SelectedFontStyle, value.fontStyle.value_or(selectedStyle.GetFontStyle()));
348 }
349 
HasUserDefinedDisappearFontFamily(bool isUserDefined)350 void TextPickerModelNG::HasUserDefinedDisappearFontFamily(bool isUserDefined)
351 {
352     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
353     CHECK_NULL_VOID(frameNode);
354     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
355     CHECK_NULL_VOID(textPickerPattern);
356     textPickerPattern->HasUserDefinedDisappearFontFamily(isUserDefined);
357 }
358 
HasUserDefinedNormalFontFamily(bool isUserDefined)359 void TextPickerModelNG::HasUserDefinedNormalFontFamily(bool isUserDefined)
360 {
361     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
362     CHECK_NULL_VOID(frameNode);
363     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
364     CHECK_NULL_VOID(textPickerPattern);
365     textPickerPattern->HasUserDefinedNormalFontFamily(isUserDefined);
366 }
367 
HasUserDefinedSelectedFontFamily(bool isUserDefined)368 void TextPickerModelNG::HasUserDefinedSelectedFontFamily(bool isUserDefined)
369 {
370     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
371     CHECK_NULL_VOID(frameNode);
372     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
373     CHECK_NULL_VOID(textPickerPattern);
374     textPickerPattern->HasUserDefinedSelectedFontFamily(isUserDefined);
375 }
376 
SetOnCascadeChange(TextCascadeChangeEvent && onChange)377 void TextPickerModelNG::SetOnCascadeChange(TextCascadeChangeEvent&& onChange)
378 {
379     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
380     CHECK_NULL_VOID(frameNode);
381     auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
382     CHECK_NULL_VOID(eventHub);
383     eventHub->SetOnChange(std::move(onChange));
384 }
385 
SetValue(const std::string & value)386 void TextPickerModelNG::SetValue(const std::string& value)
387 {
388     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Value, value);
389 }
390 
MultiInit(const RefPtr<PickerTheme> pickerTheme)391 void TextPickerModelNG::MultiInit(const RefPtr<PickerTheme> pickerTheme)
392 {
393     auto* stack = ViewStackProcessor::GetInstance();
394     auto nodeId = stack->ClaimNodeId();
395     auto textPickerNode = FrameNode::GetOrCreateFrameNode(
396         V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
397     auto textPickerPattern = textPickerNode->GetPattern<TextPickerPattern>();
398 
399     CHECK_NULL_VOID(pickerTheme);
400     showCount_ = pickerTheme->GetShowOptionCount() + BUFFER_NODE_NUMBER;
401     stack->Push(textPickerNode);
402     rangeValue_.clear();
403 }
404 
SetIsCascade(bool isCascade)405 void TextPickerModelNG::SetIsCascade(bool isCascade)
406 {
407     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
408     CHECK_NULL_VOID(frameNode);
409     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
410     CHECK_NULL_VOID(textPickerPattern);
411     isCascade_ = isCascade;
412     textPickerPattern->SetIsCascade(isCascade_);
413 }
414 
SetHasSelectAttr(bool value)415 void TextPickerModelNG::SetHasSelectAttr(bool value)
416 {
417     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
418     CHECK_NULL_VOID(frameNode);
419     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
420     CHECK_NULL_VOID(textPickerPattern);
421     textPickerPattern->SetHasSelectAttr(value);
422 }
423 
SetUnCascadeColumns(const std::vector<NG::TextCascadePickerOptions> & options)424 void TextPickerModelNG::SetUnCascadeColumns(const std::vector<NG::TextCascadePickerOptions>& options)
425 {
426     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
427     CHECK_NULL_VOID(frameNode);
428     if (frameNode->GetChildren().empty()) {
429         for (uint32_t i = 0; i < options.size(); i++) {
430             auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
431             auto stackNode = CreateStackNode();
432             auto buttonNode = CreateButtonNode();
433             auto columnBlendNode = CreateColumnNode();
434             buttonNode->MountToParent(stackNode);
435             columnNode->MountToParent(columnBlendNode);
436             columnBlendNode->MountToParent(stackNode);
437             columnNode->MarkModifyDone();
438             columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
439             auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
440             layoutProperty->UpdateAlignment(Alignment::CENTER);
441             stackNode->MountToParent(AceType::Claim(frameNode));
442         }
443     }
444 
445     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
446     CHECK_NULL_VOID(textPickerPattern);
447     textPickerPattern->SetCascadeOptions(options, options);
448 }
449 
SetCascadeColumns(const std::vector<NG::TextCascadePickerOptions> & options)450 void TextPickerModelNG::SetCascadeColumns(const std::vector<NG::TextCascadePickerOptions>& options)
451 {
452     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
453     CHECK_NULL_VOID(frameNode);
454     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
455     CHECK_NULL_VOID(textPickerPattern);
456     std::vector<NG::TextCascadePickerOptions> reOptions;
457     // Caculate max depth
458     size_t columnCount = options.empty()? 0 : 1;
459     for (size_t i = 0; i < options.size(); i++) {
460         size_t tmp  = textPickerPattern->ProcessCascadeOptionDepth(options[i]);
461         if (tmp > columnCount) {
462             columnCount = tmp;
463         }
464     }
465 
466     // Create Node
467     if (frameNode->GetChildren().empty()) {
468         for (size_t i = 0; i < columnCount; i++) {
469             auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
470             auto stackNode = CreateStackNode();
471             auto buttonNode = CreateButtonNode();
472             auto columnBlendNode = CreateColumnNode();
473             buttonNode->MountToParent(stackNode);
474             columnNode->MountToParent(columnBlendNode);
475             columnBlendNode->MountToParent(stackNode);
476             columnNode->MarkModifyDone();
477             columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
478             auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
479             layoutProperty->UpdateAlignment(Alignment::CENTER);
480             stackNode->MountToParent(AceType::Claim<NG::FrameNode>(frameNode));
481         }
482     }
483 
484     textPickerPattern->ProcessCascadeOptions(options, reOptions, 0);
485     if (reOptions.size() < columnCount) {
486         auto differ = columnCount - reOptions.size();
487         for (uint32_t i = 0; i < differ; i++) {
488             NG::TextCascadePickerOptions differOption;
489             memset_s(&differOption, sizeof(differOption), 0, sizeof(differOption));
490             reOptions.emplace_back(differOption);
491         }
492     }
493     textPickerPattern->SetCascadeOptions(options, reOptions);
494 }
495 
SetColumns(const std::vector<NG::TextCascadePickerOptions> & options)496 void TextPickerModelNG::SetColumns(const std::vector<NG::TextCascadePickerOptions>& options)
497 {
498     options_.clear();
499     for (auto& option : options) {
500         options_.emplace_back(std::move(option));
501     }
502     if (!isCascade_) {
503         SetUnCascadeColumns(options);
504     } else {
505         SetCascadeColumns(options);
506     }
507 }
508 
IsSingle()509 bool TextPickerModelNG::IsSingle()
510 {
511     return rangeValue_.size() > 0;
512 }
513 
IsSingle(FrameNode * frameNode)514 bool TextPickerModelNG::IsSingle(FrameNode* frameNode)
515 {
516     CHECK_NULL_RETURN(frameNode, false);
517     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
518     CHECK_NULL_RETURN(textPickerPattern, false);
519     return textPickerPattern->GetRange().size() > 0;
520 }
521 
GetSingleRange(std::vector<NG::RangeContent> & rangeValue)522 bool TextPickerModelNG::GetSingleRange(std::vector<NG::RangeContent>& rangeValue)
523 {
524     rangeValue.clear();
525     for (auto& item : rangeValue_) {
526         rangeValue.emplace_back(std::move(item));
527     }
528     return true;
529 }
530 
GetSingleRange(FrameNode * frameNode,std::vector<NG::RangeContent> & rangeValue)531 bool TextPickerModelNG::GetSingleRange(FrameNode* frameNode, std::vector<NG::RangeContent>& rangeValue)
532 {
533     rangeValue.clear();
534     CHECK_NULL_RETURN(frameNode, false);
535     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
536     CHECK_NULL_RETURN(textPickerPattern, false);
537     for (auto& item : textPickerPattern->GetRange()) {
538         rangeValue.emplace_back(std::move(item));
539     }
540     return true;
541 }
542 
IsCascade(FrameNode * frameNode)543 bool TextPickerModelNG::IsCascade(FrameNode* frameNode)
544 {
545     CHECK_NULL_RETURN(frameNode, false);
546     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
547     CHECK_NULL_RETURN(textPickerPattern, false);
548     return textPickerPattern->GetIsCascade();
549 }
550 
GetMultiOptions(std::vector<NG::TextCascadePickerOptions> & options)551 bool TextPickerModelNG::GetMultiOptions(std::vector<NG::TextCascadePickerOptions>& options)
552 {
553     options.clear();
554     for (auto& item : options_) {
555         options.emplace_back(std::move(item));
556     }
557     return true;
558 }
559 
GetMultiOptions(FrameNode * frameNode,std::vector<NG::TextCascadePickerOptions> & options)560 bool TextPickerModelNG::GetMultiOptions(FrameNode* frameNode, std::vector<NG::TextCascadePickerOptions>& options)
561 {
562     options.clear();
563     CHECK_NULL_RETURN(frameNode, false);
564     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
565     CHECK_NULL_RETURN(textPickerPattern, false);
566     for (auto& item : textPickerPattern->GetMultiOptions()) {
567         options.emplace_back(std::move(item));
568     }
569     return true;
570 }
571 
GetMaxCount(FrameNode * frameNode)572 uint32_t TextPickerModelNG::GetMaxCount(FrameNode* frameNode)
573 {
574     return 1;
575 }
576 
SetValues(const std::vector<std::string> & values)577 void TextPickerModelNG::SetValues(const std::vector<std::string>& values)
578 {
579     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
580     CHECK_NULL_VOID(frameNode);
581     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
582     CHECK_NULL_VOID(textPickerPattern);
583     textPickerPattern->SetValues(values);
584     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Values, values);
585 }
586 
SetSelecteds(const std::vector<uint32_t> & values)587 void TextPickerModelNG::SetSelecteds(const std::vector<uint32_t>& values)
588 {
589     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
590     CHECK_NULL_VOID(frameNode);
591     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
592     CHECK_NULL_VOID(textPickerPattern);
593     textPickerPattern->SetSelecteds(values);
594     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selecteds, values);
595     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values);
596 }
597 
SetOnValueChangeEvent(TextCascadeValueChangeEvent && onValueChangeEvent)598 void TextPickerModelNG::SetOnValueChangeEvent(TextCascadeValueChangeEvent&& onValueChangeEvent)
599 {
600     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
601     CHECK_NULL_VOID(frameNode);
602     auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
603     CHECK_NULL_VOID(eventHub);
604     eventHub->SetOnValueChangeEvent(std::move(onValueChangeEvent));
605 }
606 
SetOnSelectedChangeEvent(TextCascadeSelectedChangeEvent && onSelectedChangeEvent)607 void TextPickerModelNG::SetOnSelectedChangeEvent(TextCascadeSelectedChangeEvent&& onSelectedChangeEvent)
608 {
609     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
610     CHECK_NULL_VOID(frameNode);
611     auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
612     CHECK_NULL_VOID(eventHub);
613     eventHub->SetOnSelectedChangeEvent(std::move(onSelectedChangeEvent));
614 }
615 
CreateObject()616 RefPtr<AceType> TextPickerDialogModelNG::CreateObject()
617 {
618     return nullptr;
619 }
620 
SetTextPickerDialogShow(RefPtr<AceType> & PickerText,NG::TextPickerSettingData & settingData,std::function<void ()> && onCancel,std::function<void (const std::string &)> && onAccept,std::function<void (const std::string &)> && onChange,TextPickerDialog & textPickerDialog,TextPickerDialogEvent & textPickerDialogEvent,const std::vector<ButtonInfo> & buttonInfos)621 void TextPickerDialogModelNG::SetTextPickerDialogShow(RefPtr<AceType>& PickerText,
622     NG::TextPickerSettingData& settingData, std::function<void()>&& onCancel,
623     std::function<void(const std::string&)>&& onAccept, std::function<void(const std::string&)>&& onChange,
624     TextPickerDialog& textPickerDialog, TextPickerDialogEvent& textPickerDialogEvent,
625     const std::vector<ButtonInfo>& buttonInfos)
626 {
627     auto container = Container::Current();
628     if (!container) {
629         return;
630     }
631     auto pipelineContext = AccessibilityManager::DynamicCast<NG::PipelineContext>(container->GetPipelineContext());
632     if (!pipelineContext) {
633         return;
634     }
635     auto executor = pipelineContext->GetTaskExecutor();
636     if (!executor) {
637         return;
638     }
639     auto pipeline = PipelineBase::GetCurrentContext();
640     CHECK_NULL_VOID(pipeline);
641     auto theme = pipeline->GetTheme<DialogTheme>();
642     CHECK_NULL_VOID(theme);
643 
644     std::map<std::string, NG::DialogTextEvent> dialogEvent;
645     std::map<std::string, NG::DialogCancelEvent> dialogLifeCycleEvent;
646     std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent;
647     dialogEvent["acceptId"] = onAccept;
648     dialogEvent["changeId"] = onChange;
649     auto func = [onCancel](const GestureEvent& /* info */) {
650         if (onCancel) {
651             onCancel();
652         }
653     };
654     dialogCancelEvent["cancelId"] = func;
655     dialogLifeCycleEvent["didAppearId"] = textPickerDialogEvent.onDidAppear;
656     dialogLifeCycleEvent["didDisappearId"] = textPickerDialogEvent.onDidDisappear;
657     dialogLifeCycleEvent["willAppearId"] = textPickerDialogEvent.onWillAppear;
658     dialogLifeCycleEvent["willDisappearId"] = textPickerDialogEvent.onWillDisappear;
659     DialogProperties properties;
660     SetDialogProperties(properties, textPickerDialog, theme);
661 
662     auto context = AccessibilityManager::DynamicCast<NG::PipelineContext>(pipelineContext);
663     auto overlayManager = context ? context->GetOverlayManager() : nullptr;
664     executor->PostTask(
665         [properties, settingData, dialogEvent, dialogCancelEvent, dialogLifeCycleEvent, buttonInfos,
666             weak = WeakPtr<NG::OverlayManager>(overlayManager)] {
667             auto overlayManager = weak.Upgrade();
668             CHECK_NULL_VOID(overlayManager);
669             overlayManager->ShowTextDialog(
670                 properties, settingData, dialogEvent, dialogCancelEvent, dialogLifeCycleEvent, buttonInfos);
671         },
672         TaskExecutor::TaskType::UI, "ArkUITextPickerShowTextDialog");
673 }
674 
SetCanLoop(FrameNode * frameNode,const bool value)675 void TextPickerModelNG::SetCanLoop(FrameNode* frameNode, const bool value)
676 {
677     CHECK_NULL_VOID(frameNode);
678     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
679     CHECK_NULL_VOID(textPickerPattern);
680     textPickerPattern->SetCanLoop(value);
681     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, value, frameNode);
682 }
683 
GetCanLoop(FrameNode * frameNode)684 int32_t TextPickerModelNG::GetCanLoop(FrameNode* frameNode)
685 {
686     CHECK_NULL_RETURN(frameNode, 1);
687     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
688     CHECK_NULL_RETURN(textPickerPattern, 1);
689     return textPickerPattern->GetCanLoop();
690 }
691 
SetSelecteds(FrameNode * frameNode,const std::vector<uint32_t> & values)692 void TextPickerModelNG::SetSelecteds(FrameNode* frameNode, const std::vector<uint32_t>& values)
693 {
694     CHECK_NULL_VOID(frameNode);
695     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
696     CHECK_NULL_VOID(textPickerPattern);
697     textPickerPattern->SetSelecteds(values);
698     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selecteds, values, frameNode);
699     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values, frameNode);
700 }
SetSelected(FrameNode * frameNode,uint32_t value)701 void TextPickerModelNG::SetSelected(FrameNode* frameNode, uint32_t value)
702 {
703     CHECK_NULL_VOID(frameNode);
704     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
705     textPickerPattern->SetSelected(value);
706     std::vector<uint32_t> values;
707     values.emplace_back(value);
708     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selected, value, frameNode);
709     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values, frameNode);
710 }
SetHasSelectAttr(FrameNode * frameNode,bool value)711 void TextPickerModelNG::SetHasSelectAttr(FrameNode* frameNode, bool value)
712 {
713     CHECK_NULL_VOID(frameNode);
714     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
715     CHECK_NULL_VOID(textPickerPattern);
716     textPickerPattern->SetHasSelectAttr(value);
717 }
SetNormalTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)718 void TextPickerModelNG::SetNormalTextStyle(
719     FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
720 {
721     CHECK_NULL_VOID(frameNode);
722     CHECK_NULL_VOID(pickerTheme);
723     auto normalStyle = pickerTheme->GetOptionStyle(false, false);
724     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
725         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
726             ConvertFontScaleValue(value.fontSize.value()), frameNode);
727     } else {
728         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
729             ConvertFontScaleValue(normalStyle.GetFontSize()), frameNode);
730     }
731     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
732         TextPickerLayoutProperty, Color, value.textColor.value_or(normalStyle.GetTextColor()), frameNode);
733     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
734         TextPickerLayoutProperty, Weight, value.fontWeight.value_or(normalStyle.GetFontWeight()), frameNode);
735     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
736         TextPickerLayoutProperty, FontFamily, value.fontFamily.value_or(normalStyle.GetFontFamilies()), frameNode);
737     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
738         TextPickerLayoutProperty, FontStyle, value.fontStyle.value_or(normalStyle.GetFontStyle()), frameNode);
739 }
740 
SetSelectedTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)741 void TextPickerModelNG::SetSelectedTextStyle(
742     FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
743 {
744     CHECK_NULL_VOID(frameNode);
745     CHECK_NULL_VOID(pickerTheme);
746     auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
747     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
748         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
749             TextPickerLayoutProperty, SelectedFontSize,
750             ConvertFontScaleValue(value.fontSize.value()), frameNode);
751     } else {
752         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
753             TextPickerLayoutProperty, SelectedFontSize,
754             ConvertFontScaleValue(selectedStyle.GetFontSize()), frameNode);
755     }
756     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
757         TextPickerLayoutProperty, SelectedColor,
758         value.textColor.value_or(selectedStyle.GetTextColor()), frameNode);
759     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
760         TextPickerLayoutProperty, SelectedWeight,
761         value.fontWeight.value_or(selectedStyle.GetFontWeight()), frameNode);
762     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
763         TextPickerLayoutProperty, SelectedFontFamily,
764         value.fontFamily.value_or(selectedStyle.GetFontFamilies()), frameNode);
765     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
766         TextPickerLayoutProperty, SelectedFontStyle, value.fontStyle.value_or(selectedStyle.GetFontStyle()), frameNode);
767 }
768 
SetDisappearTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)769 void TextPickerModelNG::SetDisappearTextStyle(
770     FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
771 {
772     CHECK_NULL_VOID(frameNode);
773     CHECK_NULL_VOID(pickerTheme);
774     auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
775     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
776         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
777             TextPickerLayoutProperty, DisappearFontSize,
778             ConvertFontScaleValue(value.fontSize.value()), frameNode);
779     } else {
780         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
781             TextPickerLayoutProperty, DisappearFontSize,
782             ConvertFontScaleValue(disappearStyle.GetFontSize()), frameNode);
783     }
784     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
785         TextPickerLayoutProperty, DisappearColor, value.textColor.value_or(disappearStyle.GetTextColor()), frameNode);
786     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
787         TextPickerLayoutProperty, DisappearWeight,
788         value.fontWeight.value_or(disappearStyle.GetFontWeight()), frameNode);
789     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
790         TextPickerLayoutProperty, DisappearFontFamily,
791         value.fontFamily.value_or(disappearStyle.GetFontFamilies()), frameNode);
792     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
793         TextPickerLayoutProperty, DisappearFontStyle,
794         value.fontStyle.value_or(disappearStyle.GetFontStyle()), frameNode);
795 }
796 
SetDefaultPickerItemHeight(FrameNode * frameNode,const Dimension & value)797 void TextPickerModelNG::SetDefaultPickerItemHeight(FrameNode* frameNode, const Dimension& value)
798 {
799     CHECK_NULL_VOID(frameNode);
800     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultPickerItemHeight, value, frameNode);
801 }
802 
GetDefaultPickerItemHeight(FrameNode * frameNode)803 Dimension TextPickerModelNG::GetDefaultPickerItemHeight(FrameNode* frameNode)
804 {
805     Dimension value = Dimension(0.0f);
806     CHECK_NULL_RETURN(frameNode, value);
807     auto layoutProperty = frameNode->GetLayoutProperty<TextPickerLayoutProperty>();
808     CHECK_NULL_RETURN(layoutProperty, value);
809     return layoutProperty->HasDefaultPickerItemHeight() ? layoutProperty->GetDefaultPickerItemHeightValue() : value;
810 }
811 
SetBackgroundColor(FrameNode * frameNode,const Color & color)812 void TextPickerModelNG::SetBackgroundColor(FrameNode* frameNode, const Color& color)
813 {
814     CHECK_NULL_VOID(frameNode);
815     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
816     CHECK_NULL_VOID(textPickerPattern);
817     textPickerPattern->SetBackgroundColor(color);
818 }
819 
getDisappearTextStyle(FrameNode * frameNode)820 PickerTextStyle TextPickerModelNG::getDisappearTextStyle(FrameNode* frameNode)
821 {
822     PickerTextStyle pickerTextStyle;
823     CHECK_NULL_RETURN(frameNode, pickerTextStyle);
824     auto context = frameNode->GetContext();
825     CHECK_NULL_RETURN(context, pickerTextStyle);
826     auto theme = context->GetTheme<PickerTheme>();
827     CHECK_NULL_RETURN(theme, pickerTextStyle);
828     auto style = theme->GetDisappearOptionStyle();
829     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
830         TextPickerLayoutProperty, DisappearFontSize, pickerTextStyle.fontSize, frameNode,
831         ConvertFontScaleValue(style.GetFontSize()));
832     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
833         TextPickerLayoutProperty, DisappearColor, pickerTextStyle.textColor, frameNode, style.GetTextColor());
834     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
835         TextPickerLayoutProperty, DisappearWeight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
836     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, DisappearFontFamily,
837         pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
838     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, DisappearFontStyle,
839         pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
840     return pickerTextStyle;
841 }
842 
getNormalTextStyle(FrameNode * frameNode)843 PickerTextStyle TextPickerModelNG::getNormalTextStyle(FrameNode* frameNode)
844 {
845     PickerTextStyle pickerTextStyle;
846     CHECK_NULL_RETURN(frameNode, pickerTextStyle);
847     auto context = frameNode->GetContext();
848     CHECK_NULL_RETURN(context, pickerTextStyle);
849     auto theme = context->GetTheme<PickerTheme>();
850     CHECK_NULL_RETURN(theme, pickerTextStyle);
851     auto style = theme->GetOptionStyle(false, false);
852     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
853         TextPickerLayoutProperty, FontSize, pickerTextStyle.fontSize, frameNode,
854         ConvertFontScaleValue(style.GetFontSize()));
855     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
856         TextPickerLayoutProperty, Color, pickerTextStyle.textColor, frameNode, style.GetTextColor());
857     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
858         TextPickerLayoutProperty, Weight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
859     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, FontFamily,
860         pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
861     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, FontStyle,
862         pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
863     return pickerTextStyle;
864 }
865 
getSelectedTextStyle(FrameNode * frameNode)866 PickerTextStyle TextPickerModelNG::getSelectedTextStyle(FrameNode* frameNode)
867 {
868     PickerTextStyle pickerTextStyle;
869     CHECK_NULL_RETURN(frameNode, pickerTextStyle);
870     auto context = frameNode->GetContext();
871     CHECK_NULL_RETURN(context, pickerTextStyle);
872     auto theme = context->GetTheme<PickerTheme>();
873     CHECK_NULL_RETURN(theme, pickerTextStyle);
874     auto style = theme->GetOptionStyle(true, false);
875     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
876         TextPickerLayoutProperty, SelectedFontSize, pickerTextStyle.fontSize, frameNode,
877         ConvertFontScaleValue(style.GetFontSize()));
878     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
879         TextPickerLayoutProperty, SelectedColor, pickerTextStyle.textColor, frameNode, style.GetTextColor());
880     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
881         TextPickerLayoutProperty, SelectedWeight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
882     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, SelectedFontFamily,
883         pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
884     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, SelectedFontStyle,
885         pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
886     return pickerTextStyle;
887 }
888 
getTextPickerSelectedIndex(FrameNode * frameNode)889 int32_t TextPickerModelNG::getTextPickerSelectedIndex(FrameNode* frameNode)
890 {
891     CHECK_NULL_RETURN(frameNode, 0);
892     return frameNode->GetLayoutProperty<TextPickerLayoutProperty>()->GetSelectedValue(0);
893 }
894 
SetRange(FrameNode * frameNode,const std::vector<NG::RangeContent> & value)895 void TextPickerModelNG::SetRange(FrameNode* frameNode, const std::vector<NG::RangeContent>& value)
896 {
897     CHECK_NULL_VOID(frameNode);
898     if (frameNode->GetChildren().empty()) {
899         auto columnNode = CreateColumnNode(TEXT, showCount_);
900         auto stackNode = CreateStackNode();
901         auto buttonNode = CreateButtonNode();
902         auto columnBlendNode = CreateColumnNode();
903         buttonNode->MountToParent(stackNode);
904         columnNode->MountToParent(columnBlendNode);
905         columnBlendNode->MountToParent(stackNode);
906         columnNode->MarkModifyDone();
907         columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
908         auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
909         layoutProperty->UpdateAlignment(Alignment::CENTER);
910         stackNode->MountToParent(AceType::Claim(frameNode));
911     }
912     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
913     textPickerPattern->SetRange(value);
914     rangeValue_.clear();
915     for (auto& range : value) {
916         rangeValue_.emplace_back(std::move(range));
917     }
918 }
919 
SetColumns(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)920 void TextPickerModelNG::SetColumns(FrameNode* frameNode, const std::vector<NG::TextCascadePickerOptions>& options)
921 {
922     options_.clear();
923     for (auto& option : options) {
924         options_.emplace_back(std::move(option));
925     }
926     if (!isCascade_) {
927         SetUnCascadeColumnsNode(frameNode, options);
928     } else {
929         SetCascadeColumnsNode(frameNode, options);
930     }
931 }
932 
SetUnCascadeColumnsNode(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)933 void TextPickerModelNG::SetUnCascadeColumnsNode(FrameNode* frameNode,
934     const std::vector<NG::TextCascadePickerOptions>& options)
935 {
936     CHECK_NULL_VOID(frameNode);
937     if (frameNode->GetChildren().empty()) {
938         for (uint32_t i = 0; i < options.size(); i++) {
939             auto columnNode = CreateColumnNode(TEXT, showCount_);
940             auto stackNode = CreateStackNode();
941             auto buttonNode = CreateButtonNode();
942             auto columnBlendNode = CreateColumnNode();
943             buttonNode->MountToParent(stackNode);
944             columnNode->MountToParent(columnBlendNode);
945             columnBlendNode->MountToParent(stackNode);
946             columnNode->MarkModifyDone();
947             columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
948             auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
949             layoutProperty->UpdateAlignment(Alignment::CENTER);
950             stackNode->MountToParent(AceType::Claim(frameNode));
951         }
952     }
953 
954     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
955     CHECK_NULL_VOID(textPickerPattern);
956     textPickerPattern->SetCascadeOptions(options, options);
957 }
958 
SetCascadeColumnsNode(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)959 void TextPickerModelNG::SetCascadeColumnsNode(FrameNode* frameNode,
960     const std::vector<NG::TextCascadePickerOptions>& options)
961 {
962     CHECK_NULL_VOID(frameNode);
963     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
964     CHECK_NULL_VOID(textPickerPattern);
965     std::vector<NG::TextCascadePickerOptions> reOptions;
966     // Caculate max depth
967     size_t columnCount = options.empty()? 0 : 1;
968     for (size_t i = 0; i < options.size(); i++) {
969         size_t tmp  = textPickerPattern->ProcessCascadeOptionDepth(options[i]);
970         if (tmp > columnCount) {
971             columnCount = tmp;
972         }
973     }
974 
975     // Create Node
976     if (frameNode->GetChildren().empty()) {
977         for (size_t i = 0; i < columnCount; i++) {
978             auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
979             auto stackNode = CreateStackNode();
980             auto buttonNode = CreateButtonNode();
981             auto columnBlendNode = CreateColumnNode();
982             buttonNode->MountToParent(stackNode);
983             columnNode->MountToParent(columnBlendNode);
984             columnBlendNode->MountToParent(stackNode);
985             columnNode->MarkModifyDone();
986             columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
987             auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
988             layoutProperty->UpdateAlignment(Alignment::CENTER);
989             stackNode->MountToParent(AceType::Claim(frameNode));
990         }
991     }
992 
993     textPickerPattern->ProcessCascadeOptions(options, reOptions, 0);
994     if (reOptions.size() < columnCount) {
995         auto differ = columnCount - reOptions.size();
996         for (uint32_t i = 0; i < differ; i++) {
997             NG::TextCascadePickerOptions differOption;
998             memset_s(&differOption, sizeof(differOption), 0, sizeof(differOption));
999             reOptions.emplace_back(differOption);
1000         }
1001     }
1002     textPickerPattern->SetCascadeOptions(options, reOptions);
1003 }
1004 
SetValue(FrameNode * frameNode,const std::string & value)1005 void TextPickerModelNG::SetValue(FrameNode* frameNode, const std::string& value)
1006 {
1007     CHECK_NULL_VOID(frameNode);
1008     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Value, value, frameNode);
1009     auto valueIterator = std::find_if(rangeValue_.begin(), rangeValue_.end(),
1010         [&value](const NG::RangeContent& range) { return range.text_ == value; });
1011     if (valueIterator != rangeValue_.end()) {
1012         TextPickerModelNG::SetSelected(frameNode, std::distance(rangeValue_.begin(), valueIterator));
1013     }
1014 }
1015 
SetValues(FrameNode * frameNode,const std::vector<std::string> & values)1016 void TextPickerModelNG::SetValues(FrameNode* frameNode, const std::vector<std::string>& values)
1017 {
1018     CHECK_NULL_VOID(frameNode);
1019     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1020     CHECK_NULL_VOID(textPickerPattern);
1021     std::vector<std::string> selectedValues;
1022     std::vector<uint32_t> valuesIndex;
1023     for (uint32_t i = 0; i < options_.size(); i++) {
1024         if (values.size() > 0 && values.size() < i + 1) {
1025             if (options_[i].rangeResult.size() > 0) {
1026                 selectedValues.emplace_back(options_[i].rangeResult[0]);
1027             } else {
1028                 selectedValues.emplace_back("");
1029             }
1030             valuesIndex.emplace_back(0);
1031         } else {
1032             auto valueIterator = std::find(options_[i].rangeResult.begin(), options_[i].rangeResult.end(), values[i]);
1033             if (valueIterator == options_[i].rangeResult.end()) {
1034                 selectedValues[i] = options_[i].rangeResult.front();
1035                 valuesIndex.emplace_back(0);
1036             } else {
1037                 selectedValues.emplace_back(values[i]);
1038                 valuesIndex.emplace_back(std::distance(options_[i].rangeResult.begin(), valueIterator));
1039             }
1040         }
1041     }
1042     TextPickerModelNG::SetSelecteds(frameNode, valuesIndex);
1043     textPickerPattern->SetValues(selectedValues);
1044     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Values, selectedValues, frameNode);
1045 }
1046 
SetDefaultAttributes(RefPtr<FrameNode> & frameNode,const RefPtr<PickerTheme> & pickerTheme)1047 void TextPickerModelNG::SetDefaultAttributes(RefPtr<FrameNode>& frameNode, const RefPtr<PickerTheme>& pickerTheme)
1048 {
1049     auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
1050     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
1051         ConvertFontScaleValue(selectedStyle.GetFontSize()), frameNode);
1052     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedColor, selectedStyle.GetTextColor(), frameNode);
1053     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedWeight, selectedStyle.GetFontWeight(), frameNode);
1054     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1055         TextPickerLayoutProperty, SelectedFontFamily, selectedStyle.GetFontFamilies(), frameNode);
1056     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1057         TextPickerLayoutProperty, SelectedFontStyle, selectedStyle.GetFontStyle(), frameNode);
1058 
1059     auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
1060     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1061         TextPickerLayoutProperty, DisappearFontSize,
1062         ConvertFontScaleValue(disappearStyle.GetFontSize()), frameNode);
1063     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1064         TextPickerLayoutProperty, DisappearColor, disappearStyle.GetTextColor(), frameNode);
1065     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1066         TextPickerLayoutProperty, DisappearWeight, disappearStyle.GetFontWeight(), frameNode);
1067     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1068         TextPickerLayoutProperty, DisappearFontFamily, disappearStyle.GetFontFamilies(), frameNode);
1069     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1070         TextPickerLayoutProperty, DisappearFontStyle, disappearStyle.GetFontStyle(), frameNode);
1071 
1072     auto normalStyle = pickerTheme->GetOptionStyle(false, false);
1073     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
1074         ConvertFontScaleValue(normalStyle.GetFontSize()), frameNode);
1075     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Color, normalStyle.GetTextColor(), frameNode);
1076     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Weight, normalStyle.GetFontWeight(), frameNode);
1077     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontFamily, normalStyle.GetFontFamilies(), frameNode);
1078     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontStyle, normalStyle.GetFontStyle(), frameNode);
1079 
1080     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, true, frameNode);
1081 }
1082 
getTextPickerValue(FrameNode * frameNode)1083 std::string TextPickerModelNG::getTextPickerValue(FrameNode* frameNode)
1084 {
1085     CHECK_NULL_RETURN(frameNode, "");
1086     return frameNode->GetLayoutProperty<TextPickerLayoutProperty>()->GetValueValue("");
1087 }
1088 
getTextPickerRange(FrameNode * frameNode)1089 std::string TextPickerModelNG::getTextPickerRange(FrameNode* frameNode)
1090 {
1091     CHECK_NULL_RETURN(frameNode, "");
1092     std::string result;
1093     if (isSingleRange_) {
1094         for (auto range : rangeValue_) {
1095             result.append(range.text_ + ";");
1096         }
1097         if (result.length() > 0) {
1098             result = result.substr(0, result.length() > 0 ? result.length() - 1 : 0);
1099         }
1100     } else {
1101         for (auto option : options_) {
1102             for (auto range : option.rangeResult) {
1103                 result.append(range + ",");
1104             }
1105             result = result.substr(0, result.length() > 0 ? result.length() - 1 : 0);
1106             result.append(";");
1107         }
1108         if (result.length() > 0) {
1109             result = result.substr(0, result.length() - 1);
1110         }
1111     }
1112     return result;
1113 }
1114 
SetDivider(const ItemDivider & divider)1115 void TextPickerModelNG::SetDivider(const ItemDivider& divider)
1116 {
1117     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1118     CHECK_NULL_VOID(frameNode);
1119     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1120     CHECK_NULL_VOID(textPickerPattern);
1121     textPickerPattern->SetDivider(divider);
1122     textPickerPattern->SetCustomDividerFlag(true);
1123     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Divider, divider);
1124 }
1125 
SetDivider(FrameNode * frameNode,const ItemDivider & divider)1126 void TextPickerModelNG::SetDivider(FrameNode* frameNode, const ItemDivider& divider)
1127 {
1128     CHECK_NULL_VOID(frameNode);
1129     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1130     CHECK_NULL_VOID(textPickerPattern);
1131     textPickerPattern->SetDivider(divider);
1132     textPickerPattern->SetCustomDividerFlag(true);
1133     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Divider, divider, frameNode);
1134 }
1135 
SetGradientHeight(FrameNode * frameNode,const Dimension & value)1136 void TextPickerModelNG::SetGradientHeight(FrameNode* frameNode, const Dimension& value)
1137 {
1138     CHECK_NULL_VOID(frameNode);
1139     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1140     CHECK_NULL_VOID(textPickerPattern);
1141     textPickerPattern->SetGradientHeight(value);
1142     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, GradientHeight, value, frameNode);
1143 }
1144 
SetOnCascadeChange(FrameNode * frameNode,TextCascadeChangeEvent && onChange)1145 void TextPickerModelNG::SetOnCascadeChange(FrameNode* frameNode, TextCascadeChangeEvent&& onChange)
1146 {
1147     CHECK_NULL_VOID(frameNode);
1148     auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
1149     CHECK_NULL_VOID(eventHub);
1150     eventHub->SetOnChange(std::move(onChange));
1151 }
1152 
GetSelectedSize(FrameNode * frameNode)1153 int32_t TextPickerModelNG::GetSelectedSize(FrameNode* frameNode)
1154 {
1155     CHECK_NULL_RETURN(frameNode, 0);
1156     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1157     CHECK_NULL_RETURN(textPickerPattern, 0);
1158     return textPickerPattern->GetSelecteds().size();
1159 }
1160 
getTextPickerValues(FrameNode * frameNode)1161 std::string TextPickerModelNG::getTextPickerValues(FrameNode* frameNode)
1162 {
1163     CHECK_NULL_RETURN(frameNode, "");
1164     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1165     CHECK_NULL_RETURN(textPickerPattern, "");
1166     auto values = textPickerPattern->GetValues();
1167     std::string result;
1168     for (auto& valueRet : values) {
1169         result.append(valueRet + ';');
1170     }
1171     const size_t length = result.length();
1172     result = result.substr(0, length > 0 ? length - 1 : 0);
1173     return result;
1174 }
1175 
getTextPickerSelecteds(FrameNode * frameNode)1176 std::vector<uint32_t> TextPickerModelNG::getTextPickerSelecteds(FrameNode* frameNode)
1177 {
1178     std::vector<uint32_t> defaultValue = { 0 };
1179     CHECK_NULL_RETURN(frameNode, defaultValue);
1180     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1181     CHECK_NULL_RETURN(textPickerPattern, defaultValue);
1182     return textPickerPattern->GetSelecteds();
1183 }
1184 
SetTextPickerRangeType(FrameNode * frameNode,int32_t rangeType)1185 void TextPickerModelNG::SetTextPickerRangeType(FrameNode* frameNode, int32_t rangeType)
1186 {
1187     CHECK_NULL_VOID(frameNode);
1188     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1189     CHECK_NULL_VOID(textPickerPattern);
1190     textPickerPattern->SetRangeType(rangeType);
1191 }
1192 
GetTextPickerRangeType(FrameNode * frameNode)1193 int32_t TextPickerModelNG::GetTextPickerRangeType(FrameNode* frameNode)
1194 {
1195     CHECK_NULL_RETURN(frameNode, 0);
1196     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1197     CHECK_NULL_RETURN(textPickerPattern, 0);
1198     return textPickerPattern->GetRangeType();
1199 }
1200 
ConvertFontScaleValue(const Dimension & fontSizeValue)1201 const Dimension TextPickerModelNG::ConvertFontScaleValue(const Dimension& fontSizeValue)
1202 {
1203     auto pipeline = PipelineContext::GetCurrentContext();
1204     CHECK_NULL_RETURN(pipeline, fontSizeValue);
1205 
1206     float fontScaleValue = pipeline->GetFontScale();
1207     if (fontScaleValue == 0) {
1208         return fontSizeValue;
1209     }
1210 
1211     if (GreatOrEqualCustomPrecision(fontScaleValue, PICKER_MAXFONTSCALE)) {
1212         if (fontSizeValue.Unit() != DimensionUnit::VP) {
1213             return Dimension(fontSizeValue / fontScaleValue);
1214         }
1215     }
1216     return fontSizeValue;
1217 }
1218 
HasUserDefinedOpacity()1219 void TextPickerModelNG::HasUserDefinedOpacity()
1220 {
1221     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1222     CHECK_NULL_VOID(frameNode);
1223     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1224     CHECK_NULL_VOID(textPickerPattern);
1225     auto renderContext = frameNode->GetRenderContext();
1226     CHECK_NULL_VOID(renderContext);
1227     textPickerPattern->SetUserDefinedOpacity(renderContext->GetOpacityValue(1.0));
1228 }
1229 
1230 } // namespace OHOS::Ace::NG
1231