• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "core/interfaces/native/node/radio_modifier.h"
16 
17 #include "core/components/checkable/checkable_theme.h"
18 #include "core/components_ng/base/view_abstract.h"
19 #include "core/components_ng/pattern/radio/radio_model_ng.h"
20 #include "core/pipeline_ng/pipeline_context.h"
21 
22 namespace OHOS::Ace::NG {
23 namespace {
24 constexpr bool DEFAULT_CHECKED = false;
25 const int32_t ERROR_INT_CODE = -1;
26 thread_local std::string g_radioStrValue;
27 
SetRadioChecked(ArkUINodeHandle node,ArkUI_Bool isCheck)28 void SetRadioChecked(ArkUINodeHandle node, ArkUI_Bool isCheck)
29 {
30     auto* frameNode = reinterpret_cast<FrameNode*>(node);
31     CHECK_NULL_VOID(frameNode);
32     RadioModelNG::SetChecked(frameNode, isCheck);
33 }
34 
ResetRadioChecked(ArkUINodeHandle node)35 void ResetRadioChecked(ArkUINodeHandle node)
36 {
37     auto* frameNode = reinterpret_cast<FrameNode*>(node);
38     CHECK_NULL_VOID(frameNode);
39     RadioModelNG::SetChecked(frameNode, DEFAULT_CHECKED);
40 }
41 
SetRadioColorSetByUser(ArkUINodeHandle node,ArkUI_Bool isCheckedBackgroundColorSetByUser,ArkUI_Bool isUncheckedBorderColorSetByUser,ArkUI_Bool isIndicatorColorSetByUser)42 void SetRadioColorSetByUser(ArkUINodeHandle node, ArkUI_Bool isCheckedBackgroundColorSetByUser,
43     ArkUI_Bool isUncheckedBorderColorSetByUser, ArkUI_Bool isIndicatorColorSetByUser)
44 {
45     auto* frameNode = reinterpret_cast<FrameNode*>(node);
46     CHECK_NULL_VOID(frameNode);
47     RadioModelNG::SetCheckedBackgroundColorSetByUser(frameNode, isCheckedBackgroundColorSetByUser);
48     RadioModelNG::SetUncheckedBorderColorSetByUser(frameNode, isUncheckedBorderColorSetByUser);
49     RadioModelNG::SetIndicatorColorSetByUser(frameNode, isIndicatorColorSetByUser);
50 }
51 
SetRadioStyle(ArkUINodeHandle node,ArkUI_Uint32 checkedBackgroundColor,ArkUI_Uint32 uncheckedBorderColor,ArkUI_Uint32 indicatorColor)52 void SetRadioStyle(ArkUINodeHandle node, ArkUI_Uint32 checkedBackgroundColor, ArkUI_Uint32 uncheckedBorderColor,
53     ArkUI_Uint32 indicatorColor)
54 {
55     auto* frameNode = reinterpret_cast<FrameNode*>(node);
56     CHECK_NULL_VOID(frameNode);
57 
58     RadioModelNG::SetCheckedBackgroundColor(frameNode, Color(checkedBackgroundColor));
59     RadioModelNG::SetUncheckedBorderColor(frameNode, Color(uncheckedBorderColor));
60     RadioModelNG::SetIndicatorColor(frameNode, Color(indicatorColor));
61 }
62 
SetRadioStylePtr(ArkUINodeHandle node,ArkUI_Uint32 checkedBackgroundColor,ArkUI_Uint32 uncheckedBorderColor,ArkUI_Uint32 indicatorColor,const ArkUIRadioColorStruct & resObjStru)63 void SetRadioStylePtr(ArkUINodeHandle node, ArkUI_Uint32 checkedBackgroundColor, ArkUI_Uint32 uncheckedBorderColor,
64     ArkUI_Uint32 indicatorColor, const ArkUIRadioColorStruct& resObjStru)
65 {
66     CHECK_NULL_VOID(node);
67     SetRadioStyle(node, checkedBackgroundColor, uncheckedBorderColor, indicatorColor);
68     if (SystemProperties::ConfigChangePerform()) {
69         auto* frameNode = reinterpret_cast<FrameNode*>(node);
70         CHECK_NULL_VOID(frameNode);
71         if (resObjStru.checkedBackgroundColor) {
72             auto* backgroundColor = reinterpret_cast<ResourceObject*>(resObjStru.checkedBackgroundColor);
73             auto backgroundColorResObj = AceType::Claim(backgroundColor);
74             RadioModelNG::CreateWithColorResourceObj(frameNode, backgroundColorResObj,
75                 RadioColorType::CHECKED_BACKGROUND_COLOR);
76         } else {
77             RadioModelNG::CreateWithColorResourceObj(frameNode, nullptr, RadioColorType::CHECKED_BACKGROUND_COLOR);
78         }
79 
80         if (resObjStru.uncheckedBorderColor) {
81             auto* unBorderColor = reinterpret_cast<ResourceObject*>(resObjStru.uncheckedBorderColor);
82             auto unBorderrResObj = AceType::Claim(unBorderColor);
83             RadioModelNG::CreateWithColorResourceObj(frameNode, unBorderrResObj,
84                 RadioColorType::UNCHECKED_BORDER_COLOR);
85         } else {
86             RadioModelNG::CreateWithColorResourceObj(frameNode, nullptr, RadioColorType::UNCHECKED_BORDER_COLOR);
87         }
88 
89         if (resObjStru.indicatorColor) {
90             auto* indicatorColor = reinterpret_cast<ResourceObject*>(resObjStru.indicatorColor);
91             auto indicatorResObj = AceType::Claim(indicatorColor);
92             RadioModelNG::CreateWithColorResourceObj(frameNode, indicatorResObj, RadioColorType::INDICATOR_COLOR);
93         } else {
94             RadioModelNG::CreateWithColorResourceObj(frameNode, nullptr, RadioColorType::INDICATOR_COLOR);
95         }
96     }
97 }
98 
ResetRadioStyle(ArkUINodeHandle node)99 void ResetRadioStyle(ArkUINodeHandle node)
100 {
101     auto* frameNode = reinterpret_cast<FrameNode*>(node);
102     CHECK_NULL_VOID(frameNode);
103 
104     auto context = frameNode->GetContext();
105     CHECK_NULL_VOID(context);
106     auto themeManager = context->GetThemeManager();
107     CHECK_NULL_VOID(themeManager);
108     auto theme = themeManager->GetTheme<RadioTheme>();
109     CHECK_NULL_VOID(theme);
110 
111     RadioModelNG::SetCheckedBackgroundColor(frameNode, theme->GetActiveColor());
112     RadioModelNG::SetUncheckedBorderColor(frameNode, theme->GetInactiveColor());
113     RadioModelNG::SetIndicatorColor(frameNode, theme->GetPointColor());
114     RadioModelNG::SetCheckedBackgroundColorSetByUser(frameNode, false);
115     RadioModelNG::SetUncheckedBorderColorSetByUser(frameNode, false);
116     RadioModelNG::SetIndicatorColorSetByUser(frameNode, false);
117     if (SystemProperties::ConfigChangePerform()) {
118         RadioModelNG::CreateWithColorResourceObj(frameNode, nullptr, RadioColorType::CHECKED_BACKGROUND_COLOR);
119         RadioModelNG::CreateWithColorResourceObj(frameNode, nullptr, RadioColorType::UNCHECKED_BORDER_COLOR);
120         RadioModelNG::CreateWithColorResourceObj(frameNode, nullptr, RadioColorType::INDICATOR_COLOR);
121     }
122 }
123 
SetRadioWidth(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 unit,ArkUI_CharPtr calcValue)124 void SetRadioWidth(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit, ArkUI_CharPtr calcValue)
125 {
126     auto* frameNode = reinterpret_cast<FrameNode*>(node);
127     CHECK_NULL_VOID(frameNode);
128     auto unitEnum = static_cast<OHOS::Ace::DimensionUnit>(unit);
129     if (unitEnum == DimensionUnit::CALC) {
130         ViewAbstract::SetWidth(frameNode, CalcLength(CalcLength(std::string(calcValue))));
131     } else {
132         ViewAbstract::SetWidth(frameNode, CalcLength(value, unitEnum));
133     }
134 }
135 
ResetRadioWidth(ArkUINodeHandle node)136 void ResetRadioWidth(ArkUINodeHandle node)
137 {
138     auto* frameNode = reinterpret_cast<FrameNode*>(node);
139     CHECK_NULL_VOID(frameNode);
140     ViewAbstract::ClearWidthOrHeight(frameNode, true);
141 }
142 
SetRadioHeight(ArkUINodeHandle node,ArkUI_Float32 value,ArkUI_Int32 unit,ArkUI_CharPtr calcValue)143 void SetRadioHeight(ArkUINodeHandle node, ArkUI_Float32 value, ArkUI_Int32 unit, ArkUI_CharPtr calcValue)
144 {
145     auto* frameNode = reinterpret_cast<FrameNode*>(node);
146     CHECK_NULL_VOID(frameNode);
147     auto unitEnum = static_cast<OHOS::Ace::DimensionUnit>(unit);
148     if (unitEnum == DimensionUnit::CALC) {
149         ViewAbstract::SetHeight(frameNode, CalcLength(CalcLength(std::string(calcValue))));
150     } else {
151         ViewAbstract::SetHeight(frameNode, CalcLength(value, unitEnum));
152     }
153 }
154 
ResetRadioHeight(ArkUINodeHandle node)155 void ResetRadioHeight(ArkUINodeHandle node)
156 {
157     auto* frameNode = reinterpret_cast<FrameNode*>(node);
158     CHECK_NULL_VOID(frameNode);
159     ViewAbstract::ClearWidthOrHeight(frameNode, false);
160 }
161 
SetRadioSize(ArkUINodeHandle node,ArkUI_Float32 widthValue,ArkUI_Int32 widthUnit,ArkUI_Float32 heightValue,ArkUI_Int32 heightUnit)162 void SetRadioSize(ArkUINodeHandle node, ArkUI_Float32 widthValue, ArkUI_Int32 widthUnit, ArkUI_Float32 heightValue,
163     ArkUI_Int32 heightUnit)
164 {
165     auto* frameNode = reinterpret_cast<FrameNode*>(node);
166     CHECK_NULL_VOID(frameNode);
167     RadioModelNG::SetWidth(frameNode, Dimension(widthValue, static_cast<OHOS::Ace::DimensionUnit>(widthUnit)));
168     RadioModelNG::SetHeight(frameNode, Dimension(heightValue, static_cast<OHOS::Ace::DimensionUnit>(heightUnit)));
169 }
170 
ResetRadioSize(ArkUINodeHandle node)171 void ResetRadioSize(ArkUINodeHandle node)
172 {
173     auto* frameNode = reinterpret_cast<FrameNode*>(node);
174     CHECK_NULL_VOID(frameNode);
175     auto pipeline = PipelineBase::GetCurrentContext();
176     CHECK_NULL_VOID(pipeline);
177     auto radioTheme = pipeline->GetTheme<RadioTheme>();
178     CHECK_NULL_VOID(radioTheme);
179     auto defaultWidth = radioTheme->GetDefaultWidth();
180     auto horizontalPadding = radioTheme->GetHotZoneHorizontalPadding();
181     auto width = defaultWidth - horizontalPadding * 2; //2 is Calculate the parameters of the formula
182 
183     auto defaultHeight = radioTheme->GetDefaultHeight();
184     auto verticalPadding = radioTheme->GetHotZoneVerticalPadding();
185     auto height = defaultHeight - verticalPadding * 2; //2 is Calculate the parameters of the formula
186     RadioModelNG::SetWidth(frameNode, width);
187     RadioModelNG::SetHeight(frameNode, height);
188 }
189 
SetRadioHoverEffect(ArkUINodeHandle node,ArkUI_Int32 hoverEffectValue)190 void SetRadioHoverEffect(ArkUINodeHandle node, ArkUI_Int32 hoverEffectValue)
191 {
192     auto* frameNode = reinterpret_cast<FrameNode*>(node);
193     CHECK_NULL_VOID(frameNode);
194     OHOS::Ace::HoverEffectType hoverEffect = OHOS::Ace::HoverEffectType::AUTO;
195     hoverEffect = static_cast<OHOS::Ace::HoverEffectType>(hoverEffectValue);
196     RadioModelNG::SetHoverEffect(frameNode, hoverEffect);
197 }
198 
ResetRadioHoverEffect(ArkUINodeHandle node)199 void ResetRadioHoverEffect(ArkUINodeHandle node)
200 {
201     auto* frameNode = reinterpret_cast<FrameNode*>(node);
202     CHECK_NULL_VOID(frameNode);
203     RadioModelNG::SetHoverEffect(frameNode, OHOS::Ace::HoverEffectType::AUTO);
204 }
205 
SetRadioPadding(ArkUINodeHandle node,const struct ArkUISizeType * top,const struct ArkUISizeType * right,const struct ArkUISizeType * bottom,const struct ArkUISizeType * left)206 void SetRadioPadding(ArkUINodeHandle node, const struct ArkUISizeType* top, const struct ArkUISizeType* right,
207     const struct ArkUISizeType* bottom, const struct ArkUISizeType* left)
208 {
209     auto* frameNode = reinterpret_cast<FrameNode*>(node);
210     CHECK_NULL_VOID(frameNode);
211     CalcLength topDimen;
212     CalcLength rightDimen;
213     CalcLength bottomDimen;
214     CalcLength leftDimen;
215     if (top->string != nullptr) {
216         topDimen = CalcLength(top->string);
217     } else {
218         topDimen = CalcLength(top->value, static_cast<DimensionUnit>(top->unit));
219     }
220     if (right->string != nullptr) {
221         rightDimen = CalcLength(right->string);
222     } else {
223         rightDimen = CalcLength(right->value, static_cast<DimensionUnit>(right->unit));
224     }
225     if (bottom->string != nullptr) {
226         bottomDimen = CalcLength(bottom->string);
227     } else {
228         bottomDimen = CalcLength(bottom->value, static_cast<DimensionUnit>(bottom->unit));
229     }
230     if (left->string != nullptr) {
231         leftDimen = CalcLength(left->string);
232     } else {
233         leftDimen = CalcLength(left->value, static_cast<DimensionUnit>(left->unit));
234     }
235     NG::PaddingProperty paddings;
236     paddings.top = std::optional<CalcLength>(topDimen);
237     paddings.bottom = std::optional<CalcLength>(bottomDimen);
238     paddings.left = std::optional<CalcLength>(leftDimen);
239     paddings.right = std::optional<CalcLength>(rightDimen);
240     RadioModelNG::SetPadding(frameNode, paddings);
241 }
242 
ResetRadioPadding(ArkUINodeHandle node)243 void ResetRadioPadding(ArkUINodeHandle node)
244 {
245     auto* frameNode = reinterpret_cast<FrameNode*>(node);
246     CHECK_NULL_VOID(frameNode);
247     NG::PaddingProperty paddings;
248     paddings.top = std::optional<CalcLength>(CalcLength(0.0, DimensionUnit::VP));
249     paddings.bottom = std::optional<CalcLength>(CalcLength(0.0, DimensionUnit::VP));
250     paddings.left = std::optional<CalcLength>(CalcLength(0.0, DimensionUnit::VP));
251     paddings.right = std::optional<CalcLength>(CalcLength(0.0, DimensionUnit::VP));
252     RadioModelNG::SetPadding(frameNode, paddings);
253 }
254 
SetRadioResponseRegion(ArkUINodeHandle node,const ArkUI_Float32 * values,const ArkUI_Int32 * units,ArkUI_Uint32 length)255 void SetRadioResponseRegion(
256     ArkUINodeHandle node, const ArkUI_Float32* values, const ArkUI_Int32* units, ArkUI_Uint32 length)
257 {
258     auto* frameNode = reinterpret_cast<FrameNode*>(node);
259     CHECK_NULL_VOID(frameNode);
260     std::vector<DimensionRect> region;
261     for (uint32_t i = 0; i < length / 4; i++) { //4 is 4 different parameters
262         CalcDimension xDimen =
263             CalcDimension(values[i * 4 + 0], static_cast<DimensionUnit>(units[i * 4 + 0])); //4:parameters
264         CalcDimension yDimen =
265             CalcDimension(values[i * 4 + 1], static_cast<DimensionUnit>(units[i * 4 + 1])); //4:parameters
266         CalcDimension widthDimen =
267             CalcDimension(values[i * 4 + 2], static_cast<DimensionUnit>(units[i * 4 + 2])); //4:parameters, 2:width
268         CalcDimension heightDimen =
269             CalcDimension(values[i * 4 + 3], static_cast<DimensionUnit>(units[i * 4 + 3])); //4:parameters, 3:height
270         DimensionOffset offsetDimen(xDimen, yDimen);
271         DimensionRect dimenRect(widthDimen, heightDimen, offsetDimen);
272         region.emplace_back(dimenRect);
273     }
274     RadioModelNG::SetResponseRegion(frameNode, region);
275 }
276 
ResetRadioResponseRegion(ArkUINodeHandle node)277 void ResetRadioResponseRegion(ArkUINodeHandle node)
278 {
279     auto* frameNode = reinterpret_cast<FrameNode*>(node);
280     CHECK_NULL_VOID(frameNode);
281     std::vector<DimensionRect> region;
282     CalcDimension xDimen = CalcDimension(0.0, DimensionUnit::VP);
283     CalcDimension yDimen = CalcDimension(0.0, DimensionUnit::VP);
284     CalcDimension widthDimen = CalcDimension(1, DimensionUnit::PERCENT);
285     CalcDimension heightDimen = CalcDimension(1, DimensionUnit::PERCENT);
286     DimensionOffset offsetDimen(xDimen, yDimen);
287     DimensionRect dimenRect(widthDimen, heightDimen, offsetDimen);
288     region.emplace_back(dimenRect);
289     RadioModelNG::SetResponseRegion(frameNode, region);
290 }
291 
GetRadioChecked(ArkUINodeHandle node)292 ArkUI_Bool GetRadioChecked(ArkUINodeHandle node)
293 {
294     auto* frameNode = reinterpret_cast<FrameNode*>(node);
295     CHECK_NULL_RETURN(frameNode, ERROR_INT_CODE);
296     return static_cast<ArkUI_Bool>(RadioModelNG::GetChecked(frameNode));
297 }
298 
GetRadioStyle(ArkUINodeHandle node,ArkUIRadioStyleOption * options)299 void GetRadioStyle(ArkUINodeHandle node, ArkUIRadioStyleOption* options)
300 {
301     auto* frameNode = reinterpret_cast<FrameNode*>(node);
302     CHECK_NULL_VOID(frameNode);
303     options->checkedBackgroundColor = RadioModelNG::GetCheckedBackgroundColor(frameNode).GetValue();
304     options->uncheckedBorderColor = RadioModelNG::GetUncheckedBorderColor(frameNode).GetValue();
305     options->indicatorColor = RadioModelNG::GetIndicatorColor(frameNode).GetValue();
306 }
307 
SetRadioValue(ArkUINodeHandle node,ArkUI_CharPtr value)308 void SetRadioValue(ArkUINodeHandle node, ArkUI_CharPtr value)
309 {
310     auto* frameNode = reinterpret_cast<FrameNode*>(node);
311     CHECK_NULL_VOID(frameNode);
312     RadioModelNG::SetRadioValue(frameNode, std::string(value));
313 }
314 
ResetRadioValue(ArkUINodeHandle node)315 void ResetRadioValue(ArkUINodeHandle node)
316 {
317     auto* frameNode = reinterpret_cast<FrameNode*>(node);
318     CHECK_NULL_VOID(frameNode);
319     RadioModelNG::SetRadioValue(frameNode, "");
320 }
321 
GetSetRadioValue(ArkUINodeHandle node)322 ArkUI_CharPtr GetSetRadioValue(ArkUINodeHandle node)
323 {
324     auto* frameNode = reinterpret_cast<FrameNode*>(node);
325     CHECK_NULL_RETURN(frameNode, nullptr);
326     g_radioStrValue = RadioModelNG::GetRadioValue(frameNode);
327     return g_radioStrValue.c_str();
328 }
329 
SetRadioGroup(ArkUINodeHandle node,ArkUI_CharPtr value)330 void SetRadioGroup(ArkUINodeHandle node, ArkUI_CharPtr value)
331 {
332     auto* frameNode = reinterpret_cast<FrameNode*>(node);
333     CHECK_NULL_VOID(frameNode);
334     RadioModelNG::SetRadioGroup(frameNode, std::string(value));
335 }
336 
ResetRadioGroup(ArkUINodeHandle node)337 void ResetRadioGroup(ArkUINodeHandle node)
338 {
339     auto* frameNode = reinterpret_cast<FrameNode*>(node);
340     CHECK_NULL_VOID(frameNode);
341     RadioModelNG::SetRadioGroup(frameNode, "");
342 }
343 
GetRadioGroup(ArkUINodeHandle node)344 ArkUI_CharPtr GetRadioGroup(ArkUINodeHandle node)
345 {
346     auto* frameNode = reinterpret_cast<FrameNode*>(node);
347     CHECK_NULL_RETURN(frameNode, nullptr);
348     g_radioStrValue = RadioModelNG::GetRadioGroup(frameNode);
349     return g_radioStrValue.c_str();
350 }
351 
SetRadioOptions(ArkUINodeHandle node,ArkUI_CharPtr value,ArkUI_CharPtr group,ArkUI_Uint32 indicatorType)352 void SetRadioOptions(ArkUINodeHandle node, ArkUI_CharPtr value, ArkUI_CharPtr group, ArkUI_Uint32 indicatorType)
353 {
354     if (value == nullptr || group == nullptr) {
355         return;
356     }
357     auto* frameNode = reinterpret_cast<FrameNode*>(node);
358     CHECK_NULL_VOID(frameNode);
359     if (static_cast<RadioIndicatorType>(indicatorType) != RadioIndicatorType::TICK &&
360         static_cast<RadioIndicatorType>(indicatorType) != RadioIndicatorType::DOT &&
361         static_cast<RadioIndicatorType>(indicatorType) != RadioIndicatorType::CUSTOM) {
362             indicatorType = static_cast<ArkUI_Uint32>(RadioIndicatorType::TICK);
363     }
364     RadioModelNG::SetRadioOptions(frameNode, std::string(value), std::string(group), indicatorType);
365 }
366 
SetRadioOnChange(ArkUINodeHandle node,void * callback)367 void SetRadioOnChange(ArkUINodeHandle node, void* callback)
368 {
369     auto* frameNode = reinterpret_cast<FrameNode*>(node);
370     CHECK_NULL_VOID(frameNode);
371     if (callback) {
372         auto onChange = reinterpret_cast<std::function<void(bool)>*>(callback);
373         RadioModelNG::SetOnChange(frameNode, std::move(*onChange));
374     } else {
375         RadioModelNG::SetOnChange(frameNode, nullptr);
376     }
377 }
378 
ResetRadioOnChange(ArkUINodeHandle node)379 void ResetRadioOnChange(ArkUINodeHandle node)
380 {
381     auto* frameNode = reinterpret_cast<FrameNode*>(node);
382     CHECK_NULL_VOID(frameNode);
383     RadioModelNG::SetOnChange(frameNode, nullptr);
384 }
385 
SetIsUserSetMargin(ArkUINodeHandle node)386 void SetIsUserSetMargin(ArkUINodeHandle node)
387 {
388     auto* frameNode = reinterpret_cast<FrameNode*>(node);
389     CHECK_NULL_VOID(frameNode);
390     RadioModelNG::SetIsUserSetMargin(frameNode, true);
391 }
392 } // namespace
393 
394 namespace NodeModifier {
GetRadioModifier()395 const ArkUIRadioModifier* GetRadioModifier()
396 {
397     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
398     static const ArkUIRadioModifier modifier = {
399         .setRadioChecked = SetRadioChecked,
400         .resetRadioChecked = ResetRadioChecked,
401         .setRadioStyle = SetRadioStyle,
402         .resetRadioStyle = ResetRadioStyle,
403         .setRadioWidth = SetRadioWidth,
404         .resetRadioWidth = ResetRadioWidth,
405         .setRadioHeight = SetRadioHeight,
406         .resetRadioHeight = ResetRadioHeight,
407         .setRadioSize = SetRadioSize,
408         .resetRadioSize = ResetRadioSize,
409         .setRadioHoverEffect = SetRadioHoverEffect,
410         .resetRadioHoverEffect = ResetRadioHoverEffect,
411         .setRadioPadding = SetRadioPadding,
412         .resetRadioPadding = ResetRadioPadding,
413         .setRadioResponseRegion = SetRadioResponseRegion,
414         .resetRadioResponseRegion = ResetRadioResponseRegion,
415         .getRadioChecked = GetRadioChecked,
416         .getRadioStyle = GetRadioStyle,
417         .setRadioValue = SetRadioValue,
418         .resetRadioValue = ResetRadioValue,
419         .getRadioValue = GetSetRadioValue,
420         .setRadioGroup = SetRadioGroup,
421         .resetRadioGroup = ResetRadioGroup,
422         .getRadioGroup = GetRadioGroup,
423         .setRadioOptions = SetRadioOptions,
424         .setRadioOnChange = SetRadioOnChange,
425         .resetRadioOnChange = ResetRadioOnChange,
426         .setRadioStylePtr = SetRadioStylePtr,
427         .setIsUserSetMargin = SetIsUserSetMargin,
428         .setRadioColorSetByUser = SetRadioColorSetByUser,
429     };
430     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
431 
432     return &modifier;
433 }
434 
GetCJUIRadioModifier()435 const CJUIRadioModifier* GetCJUIRadioModifier()
436 {
437     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
438     static const CJUIRadioModifier modifier = {
439         .setRadioChecked = SetRadioChecked,
440         .resetRadioChecked = ResetRadioChecked,
441         .setRadioStyle = SetRadioStyle,
442         .resetRadioStyle = ResetRadioStyle,
443         .setRadioWidth = SetRadioWidth,
444         .resetRadioWidth = ResetRadioWidth,
445         .setRadioHeight = SetRadioHeight,
446         .resetRadioHeight = ResetRadioHeight,
447         .setRadioSize = SetRadioSize,
448         .resetRadioSize = ResetRadioSize,
449         .setRadioHoverEffect = SetRadioHoverEffect,
450         .resetRadioHoverEffect = ResetRadioHoverEffect,
451         .setRadioPadding = SetRadioPadding,
452         .resetRadioPadding = ResetRadioPadding,
453         .setRadioResponseRegion = SetRadioResponseRegion,
454         .resetRadioResponseRegion = ResetRadioResponseRegion,
455         .getRadioChecked = GetRadioChecked,
456         .getRadioStyle = GetRadioStyle,
457         .setRadioValue = SetRadioValue,
458         .resetRadioValue = ResetRadioValue,
459         .getRadioValue = GetSetRadioValue,
460         .setRadioGroup = SetRadioGroup,
461         .resetRadioGroup = ResetRadioGroup,
462         .getRadioGroup = GetRadioGroup,
463     };
464     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
465 
466     return &modifier;
467 }
468 
SetOnRadioChange(ArkUINodeHandle node,void * extraParam)469 void SetOnRadioChange(ArkUINodeHandle node, void* extraParam)
470 {
471     auto* frameNode = reinterpret_cast<FrameNode*>(node);
472     CHECK_NULL_VOID(frameNode);
473     auto onChange = [node, extraParam](const bool value) {
474         ArkUINodeEvent event;
475         event.kind = COMPONENT_ASYNC_EVENT;
476         event.extraParam = reinterpret_cast<intptr_t>(extraParam);
477         event.componentAsyncEvent.subKind = ON_RADIO_CHANGE;
478         event.componentAsyncEvent.data[0].i32 = static_cast<int>(value);
479         SendArkUISyncEvent(&event);
480     };
481     RadioModelNG::SetOnChange(frameNode, std::move(onChange));
482 }
483 } // namespace NodeModifier
484 } // namespace OHOS::Ace::NG
485