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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_VALUE_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_VALUE_COMPONENT_H 18 19 #include "core/components/picker/picker_option_component.h" 20 #include "core/components/picker/picker_value_element.h" 21 #include "core/pipeline/base/sole_child_component.h" 22 23 namespace OHOS::Ace { 24 25 class PickerValueComponent : public SoleChildComponent { 26 DECLARE_ACE_TYPE(PickerValueComponent, SoleChildComponent); 27 28 public: PickerValueComponent(const PickerValueCallback & clickCallback)29 explicit PickerValueComponent(const PickerValueCallback& clickCallback) 30 { 31 clickCallback_ = clickCallback; 32 option_ = AceType::MakeRefPtr<PickerOptionComponent>(); 33 option_->SetSelected(false); 34 option_->SetAutoLayout(true); 35 SetChild(option_); 36 } 37 38 ~PickerValueComponent() override = default; 39 CreateRenderNode()40 RefPtr<RenderNode> CreateRenderNode() override 41 { 42 return AceType::MakeRefPtr<RenderPickerValue>(clickCallback_); 43 } CreateElement()44 RefPtr<Element> CreateElement() override 45 { 46 return AceType::MakeRefPtr<PickerValueElement>(); 47 } 48 GetText()49 const std::string& GetText() const 50 { 51 return option_->GetText(); 52 } SetText(const std::string & value)53 void SetText(const std::string& value) 54 { 55 option_->SetText(value); 56 } 57 SetTheme(const RefPtr<PickerTheme> & value)58 void SetTheme(const RefPtr<PickerTheme>& value) 59 { 60 if (!value) { 61 LOGE("input value is null."); 62 return; 63 } 64 65 value->SetOptionStyle(true, false, value->GetOptionStyle(false, false)); 66 value->SetOptionDecoration(false, AceType::MakeRefPtr<Decoration>()); 67 option_->SetTheme(value); 68 option_->SetTextDirection(GetTextDirection()); 69 } 70 71 private: 72 RefPtr<PickerOptionComponent> option_; 73 PickerValueCallback clickCallback_; 74 }; 75 76 } // namespace OHOS::Ace 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_VALUE_COMPONENT_H 79