1 /*
2  * Copyright (c) 2021 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 "frameworks/bridge/js_frontend/engine/jsi/jsi_stepper_bridge.h"
17 
18 namespace OHOS::Ace::Framework {
19 
GetAttrLabel(shared_ptr<JsRuntime> runtime,const shared_ptr<JsValue> & valObject,StepperLabels & stepperLabel)20 void JsiStepperBridge::GetAttrLabel(
21     shared_ptr<JsRuntime> runtime, const shared_ptr<JsValue>& valObject, StepperLabels& stepperLabel)
22 {
23     if (!runtime) {
24         LOGE("runtime is null");
25         return;
26     }
27     if (!valObject->IsObject(runtime)) {
28         LOGE("none found attrs");
29         return;
30     }
31     shared_ptr<JsValue> propertyNames;
32     int32_t len = 0;
33     valObject->GetPropertyNames(runtime, propertyNames, len);
34     for (auto i = 0; i < len; i++) {
35         shared_ptr<JsValue> key = propertyNames->GetElement(runtime, i);
36         if (!key) {
37             LOGW("key is null. Ignoring!");
38             continue;
39         }
40         std::string keyStr = key->ToString(runtime);
41         shared_ptr<JsValue> item = valObject->GetProperty(runtime, key);
42         if (!item) {
43             LOGW("item value is null. Ignoring!");
44             continue;
45         }
46         if (item->IsString(runtime) || item->IsNumber(runtime)) {
47             std::string valStr = item->ToString(runtime);
48             if (keyStr == DOM_STEPPER_LEFT_LABEL) {
49                 stepperLabel.leftLabel = valStr;
50             } else if (keyStr == DOM_STEPPER_RIGHT_LABEL) {
51                 stepperLabel.rightLabel = valStr;
52             } else if (keyStr == DOM_STEPPER_INITIAL_STATUS) {
53                 stepperLabel.initialStatus = valStr;
54             }
55         }
56     }
57 }
58 
59 } // namespace OHOS::Ace::Framework
60