1 /*
2  * Copyright (c) 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 "bridge/cj_frontend/interfaces/cj_ffi/cj_radio_ffi.h"
17 
18 #include <optional>
19 #include <string>
20 
21 #include "cj_lambda.h"
22 #include "bridge/cj_frontend/interfaces/cj_ffi/utils.h"
23 #include "bridge/declarative_frontend/view_stack_processor.h"
24 #include "core/components_ng/pattern/radio/radio_model_ng.h"
25 
26 using namespace OHOS::Ace;
27 
28 extern "C" {
FfiOHOSAceFrameworkRadioCreate(const char * group,const char * value)29 void FfiOHOSAceFrameworkRadioCreate(const char* group, const char* value)
30 {
31     std::optional<int32_t> indicator;
32     RadioModel::GetInstance()->Create(std::optional<std::string>(value), std::optional<std::string>(group), indicator);
33 }
FfiOHOSAceFrameworkRadioChecked(bool value)34 void FfiOHOSAceFrameworkRadioChecked(bool value)
35 {
36     RadioModel::GetInstance()->SetChecked(value);
37 }
FfiOHOSAceFrameworkRadioOnChange(void (* callback)(bool isChecked))38 void FfiOHOSAceFrameworkRadioOnChange(void (*callback)(bool isChecked))
39 {
40     RadioModel::GetInstance()->SetOnChange(CJLambda::Create(callback));
41 }
42 
FfiRadioSetResponseRegion(CJResponseRegion value)43 void FfiRadioSetResponseRegion(CJResponseRegion value)
44 {
45     std::vector<DimensionRect> result;
46     ParseCJResponseRegion(value, result);
47     RadioModel::GetInstance()->SetResponseRegion(result);
48 }
49 
FfiRadioSetResponseRegionArray(VectorStringPtr vecContent)50 void FfiRadioSetResponseRegionArray(VectorStringPtr vecContent)
51 {
52     std::vector<DimensionRect> result;
53     ParseVectorStringPtr(vecContent, result);
54     RadioModel::GetInstance()->SetResponseRegion(result);
55 }
56 }
57