1 /* 2 * Copyright (c) 2021-2022 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_CHECKABLE_RENDER_RADIO_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CHECKABLE_RENDER_RADIO_H 18 19 #include <functional> 20 21 #include "core/animation/animator.h" 22 #include "core/animation/keyframe_animation.h" 23 #include "core/components/checkable/checkable_component.h" 24 #include "core/components/checkable/render_checkable.h" 25 26 namespace OHOS::Ace { 27 28 class RenderRadio : public RenderCheckable { 29 DECLARE_ACE_TYPE(RenderRadio, RenderCheckable); 30 31 public: 32 RenderRadio() = default; 33 ~RenderRadio() override = default; 34 35 static RefPtr<RenderNode> Create(); 36 void Update(const RefPtr<Component>& component) override; 37 void PerformLayout() override; 38 bool UpdateGroupValue(const std::string& groupValue); 39 GetRadioComponent()40 RefPtr<RadioComponent<std::string>> GetRadioComponent() const 41 { 42 return component_; 43 } 44 45 std::string ProvideRestoreInfo() override; 46 47 protected: 48 double innerCircleRadius_ = 0.0; 49 double outCircleRadius_ = 0.0; 50 double radioInnerSizeRatio_ = 0.0; 51 std::string radioValue_; 52 std::string groupValue_; 53 std::function<void(std::string)> groupValueChangedListener_; 54 55 void UpdateAnimation(bool isOn); 56 void OffAnimationEnd(); 57 void OnAnimationStart(); 58 void HandleClick() override; 59 void UpdateAccessibilityAttr() const; 60 61 RefPtr<Animator> onController_; 62 RefPtr<Animator> offController_; 63 64 double totalScale_ = 1.0; 65 double pointScale_ = 1.0; 66 bool isClicked_ = false; 67 RefPtr<RadioComponent<std::string>> component_; 68 69 private: 70 void ApplyRestoreInfo(); 71 }; 72 73 } // namespace OHOS::Ace 74 75 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CHECKABLE_RENDER_RADIO_H 76